mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-14 00:09:55 +02:00
show ai gateway resource details in launcher
This commit is contained in:
@@ -4053,7 +4053,18 @@
|
|||||||
"resourceLauncherTcp": "TCP",
|
"resourceLauncherTcp": "TCP",
|
||||||
"resourceLauncherUdp": "UDP",
|
"resourceLauncherUdp": "UDP",
|
||||||
"resourceLauncherUnlabeled": "Unlabeled",
|
"resourceLauncherUnlabeled": "Unlabeled",
|
||||||
|
"resourceLauncherAiGateway": "AI Gateway",
|
||||||
"resourceLauncherNoSite": "No Site",
|
"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",
|
"resourceLauncherNoResourcesInGroup": "No resources in this group",
|
||||||
"resourceLauncherEmptyStateTitle": "No Resources Available",
|
"resourceLauncherEmptyStateTitle": "No Resources Available",
|
||||||
"resourceLauncherEmptyStateDescription": "You don't have access to any resources yet. Contact your administrator to request access.",
|
"resourceLauncherEmptyStateDescription": "You don't have access to any resources yet. Contact your administrator to request access.",
|
||||||
|
|||||||
@@ -518,6 +518,152 @@ export async function listSiteResourceAiProviders(siteResourceId: number) {
|
|||||||
.where(eq(siteResourceAiProviders.siteResourceId, siteResourceId));
|
.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
|
* Model list APIs require an inference resource with at least one select-mode
|
||||||
* attached provider.
|
* attached provider.
|
||||||
|
|||||||
@@ -590,6 +590,20 @@ authenticated.get(
|
|||||||
launcher.listLauncherResources
|
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(
|
authenticated.get(
|
||||||
"/org/:orgId/launcher/sites",
|
"/org/:orgId/launcher/sites",
|
||||||
verifyOrgAccess,
|
verifyOrgAccess,
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ function formatTcpUdpResourceAccess(
|
|||||||
export function formatPublicResourceAccess(
|
export function formatPublicResourceAccess(
|
||||||
resource: PublicResourceAccessInput
|
resource: PublicResourceAccessInput
|
||||||
): LauncherAccessFields {
|
): LauncherAccessFields {
|
||||||
const browserModes = ["http", "ssh", "rdp", "vnc"];
|
const browserModes = ["http", "ssh", "rdp", "vnc", "inference"];
|
||||||
if (!browserModes.includes(resource.mode)) {
|
if (!browserModes.includes(resource.mode)) {
|
||||||
return formatTcpUdpResourceAccess(
|
return formatTcpUdpResourceAccess(
|
||||||
resource.exitNodeEndpoint,
|
resource.exitNodeEndpoint,
|
||||||
@@ -125,15 +125,10 @@ export function formatPublicResourceAccess(
|
|||||||
export function formatSiteResourceAccess(
|
export function formatSiteResourceAccess(
|
||||||
resource: SiteResourceAccessInput
|
resource: SiteResourceAccessInput
|
||||||
): LauncherAccessFields {
|
): LauncherAccessFields {
|
||||||
if (resource.alias) {
|
if (
|
||||||
return {
|
(resource.mode === "http" || resource.mode === "inference") &&
|
||||||
accessDisplay: resource.alias,
|
resource.fullDomain
|
||||||
accessCopyValue: resource.alias,
|
) {
|
||||||
accessUrl: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resource.mode === "http" && resource.fullDomain) {
|
|
||||||
const url = `${resource.ssl ? "https" : "http"}://${resource.fullDomain}`;
|
const url = `${resource.ssl ? "https" : "http"}://${resource.fullDomain}`;
|
||||||
return {
|
return {
|
||||||
accessDisplay: url,
|
accessDisplay: url,
|
||||||
@@ -142,6 +137,14 @@ export function formatSiteResourceAccess(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resource.alias) {
|
||||||
|
return {
|
||||||
|
accessDisplay: resource.alias,
|
||||||
|
accessCopyValue: resource.alias,
|
||||||
|
accessUrl: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const destination = formatSiteResourceDestinationDisplay({
|
const destination = formatSiteResourceDestinationDisplay({
|
||||||
mode: resource.mode as SiteResourceDestinationInput["mode"],
|
mode: resource.mode as SiteResourceDestinationInput["mode"],
|
||||||
destination: resource.destination,
|
destination: resource.destination,
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ export { listLauncherResources } from "./listLauncherResources";
|
|||||||
export { listLauncherSites } from "./listLauncherSites";
|
export { listLauncherSites } from "./listLauncherSites";
|
||||||
export { listLauncherLabels } from "./listLauncherLabels";
|
export { listLauncherLabels } from "./listLauncherLabels";
|
||||||
export { listLauncherViews } from "./listLauncherViews";
|
export { listLauncherViews } from "./listLauncherViews";
|
||||||
|
export {
|
||||||
|
listLauncherPublicAiModels,
|
||||||
|
listLauncherSiteAiModels
|
||||||
|
} from "./listLauncherAiModels";
|
||||||
|
export type { ListLauncherAiModelsResponse } from "./listLauncherAiModels";
|
||||||
export { createLauncherView } from "./createLauncherView";
|
export { createLauncherView } from "./createLauncherView";
|
||||||
export { updateLauncherView } from "./updateLauncherView";
|
export { updateLauncherView } from "./updateLauncherView";
|
||||||
export { deleteLauncherView } from "./deleteLauncherView";
|
export { deleteLauncherView } from "./deleteLauncherView";
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import {
|
|||||||
inArray,
|
inArray,
|
||||||
isNull,
|
isNull,
|
||||||
like,
|
like,
|
||||||
|
ne,
|
||||||
or,
|
or,
|
||||||
sql,
|
sql,
|
||||||
type SQL
|
type SQL
|
||||||
@@ -40,6 +41,7 @@ import {
|
|||||||
formatSiteResourceAccess
|
formatSiteResourceAccess
|
||||||
} from "./formatLauncherAccess";
|
} from "./formatLauncherAccess";
|
||||||
import {
|
import {
|
||||||
|
LAUNCHER_AI_GATEWAY_GROUP_KEY,
|
||||||
LAUNCHER_FLAT_GROUP_KEY,
|
LAUNCHER_FLAT_GROUP_KEY,
|
||||||
LAUNCHER_NO_SITE_GROUP_KEY,
|
LAUNCHER_NO_SITE_GROUP_KEY,
|
||||||
LAUNCHER_UNLABELED_GROUP_KEY,
|
LAUNCHER_UNLABELED_GROUP_KEY,
|
||||||
@@ -652,6 +654,7 @@ async function listSiteGroups(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let aiGatewayCount = 0;
|
||||||
let noSiteCount = 0;
|
let noSiteCount = 0;
|
||||||
|
|
||||||
if (accessible.resourceIds.length > 0 && siteFilterIds.length === 0) {
|
if (accessible.resourceIds.length > 0 && siteFilterIds.length === 0) {
|
||||||
@@ -665,27 +668,49 @@ async function listSiteGroups(
|
|||||||
noSitePublicConditions.push(searchPublic);
|
noSitePublicConditions.push(searchPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
let noSitePublicQuery = db
|
const buildNoSitePublicQuery = () => {
|
||||||
.select({
|
let queryBuilder = db
|
||||||
itemCount: countDistinct(resources.resourceId)
|
.select({
|
||||||
})
|
itemCount: countDistinct(resources.resourceId)
|
||||||
.from(resources)
|
})
|
||||||
.leftJoin(targets, eq(targets.resourceId, 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) {
|
if (labelFilterIds.length > 0) {
|
||||||
noSitePublicQuery = noSitePublicQuery.innerJoin(
|
|
||||||
resourceLabels,
|
|
||||||
eq(resourceLabels.resourceId, resources.resourceId)
|
|
||||||
);
|
|
||||||
noSitePublicConditions.push(
|
noSitePublicConditions.push(
|
||||||
inArray(resourceLabels.labelId, labelFilterIds)
|
inArray(resourceLabels.labelId, labelFilterIds)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [noSitePublicRow] = await noSitePublicQuery.where(
|
const [aiGatewayPublicRow] = await buildNoSitePublicQuery().where(
|
||||||
and(...noSitePublicConditions, isNull(targets.targetId))
|
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);
|
noSiteCount += Number(noSitePublicRow?.itemCount ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,38 +725,57 @@ async function listSiteGroups(
|
|||||||
noSiteSiteConditions.push(searchSite);
|
noSiteSiteConditions.push(searchSite);
|
||||||
}
|
}
|
||||||
|
|
||||||
let noSiteSiteQuery = db
|
const buildNoSiteSiteQuery = () => {
|
||||||
.select({
|
let queryBuilder = db
|
||||||
itemCount: countDistinct(siteResources.siteResourceId)
|
.select({
|
||||||
})
|
itemCount: countDistinct(siteResources.siteResourceId)
|
||||||
.from(siteResources)
|
})
|
||||||
.leftJoin(
|
.from(siteResources)
|
||||||
siteNetworks,
|
.leftJoin(
|
||||||
eq(siteResources.networkId, siteNetworks.networkId)
|
siteNetworks,
|
||||||
)
|
eq(siteResources.networkId, siteNetworks.networkId)
|
||||||
.leftJoin(sites, eq(siteNetworks.siteId, sites.siteId));
|
)
|
||||||
|
.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) {
|
if (labelFilterIds.length > 0) {
|
||||||
noSiteSiteQuery = noSiteSiteQuery.innerJoin(
|
|
||||||
siteResourceLabels,
|
|
||||||
eq(
|
|
||||||
siteResourceLabels.siteResourceId,
|
|
||||||
siteResources.siteResourceId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
noSiteSiteConditions.push(
|
noSiteSiteConditions.push(
|
||||||
inArray(siteResourceLabels.labelId, labelFilterIds)
|
inArray(siteResourceLabels.labelId, labelFilterIds)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [noSiteSiteRow] = await noSiteSiteQuery.where(
|
const [aiGatewaySiteRow] = await buildNoSiteSiteQuery().where(
|
||||||
and(...noSiteSiteConditions, isNull(sites.siteId))
|
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);
|
noSiteCount += Number(noSiteSiteRow?.itemCount ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let groups: LauncherGroup[] = Array.from(siteCountMap.values()).map(
|
const siteGroups: LauncherGroup[] = Array.from(siteCountMap.values()).map(
|
||||||
(row) => ({
|
(row) => ({
|
||||||
groupKey: String(row.siteId),
|
groupKey: String(row.siteId),
|
||||||
name: row.name,
|
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) {
|
if (noSiteCount > 0 && siteFilterIds.length === 0) {
|
||||||
groups.push({
|
pinnedGroups.push({
|
||||||
groupKey: LAUNCHER_NO_SITE_GROUP_KEY,
|
groupKey: LAUNCHER_NO_SITE_GROUP_KEY,
|
||||||
name: "No Site",
|
name: "No Site",
|
||||||
groupType: "site",
|
groupType: "site",
|
||||||
@@ -751,12 +813,7 @@ async function listSiteGroups(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.sort((a, b) => {
|
const groups = [...pinnedGroups, ...siteGroups];
|
||||||
const cmp = a.name.localeCompare(b.name, undefined, {
|
|
||||||
sensitivity: "base"
|
|
||||||
});
|
|
||||||
return query.order === "desc" ? -cmp : cmp;
|
|
||||||
});
|
|
||||||
|
|
||||||
const total = groups.length;
|
const total = groups.length;
|
||||||
return {
|
return {
|
||||||
@@ -1189,8 +1246,11 @@ function filterResourcesBySite(
|
|||||||
items: LauncherResource[],
|
items: LauncherResource[],
|
||||||
groupKey: string
|
groupKey: string
|
||||||
): LauncherResource[] {
|
): LauncherResource[] {
|
||||||
|
if (groupKey === LAUNCHER_AI_GATEWAY_GROUP_KEY) {
|
||||||
|
return items.filter((item) => item.mode === "inference");
|
||||||
|
}
|
||||||
if (groupKey === LAUNCHER_NO_SITE_GROUP_KEY) {
|
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);
|
const siteId = Number.parseInt(groupKey, 10);
|
||||||
if (!Number.isFinite(siteId)) {
|
if (!Number.isFinite(siteId)) {
|
||||||
@@ -1327,7 +1387,8 @@ async function listLauncherResourcesForUserUncached(
|
|||||||
|
|
||||||
const parsedSiteId =
|
const parsedSiteId =
|
||||||
query.groupBy === "site" &&
|
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.parseInt(query.groupKey, 10)
|
||||||
: Number.NaN;
|
: Number.NaN;
|
||||||
const siteIdFilter = Number.isFinite(parsedSiteId)
|
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"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|||||||
|
|
||||||
export const LAUNCHER_UNLABELED_GROUP_KEY = "unlabeled";
|
export const LAUNCHER_UNLABELED_GROUP_KEY = "unlabeled";
|
||||||
export const LAUNCHER_NO_SITE_GROUP_KEY = "no-site";
|
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 LAUNCHER_FLAT_GROUP_KEY = "__all__";
|
||||||
|
|
||||||
export const launcherViewConfigSchema = z.object({
|
export const launcherViewConfigSchema = z.object({
|
||||||
|
|||||||
@@ -368,56 +368,65 @@ export default function CreatePrivateResourcePage() {
|
|||||||
/>
|
/>
|
||||||
</SettingsFormCell>
|
</SettingsFormCell>
|
||||||
|
|
||||||
{mode === "http" ||
|
{(mode === "http" ||
|
||||||
(mode === "inference" && (
|
mode === "inference") && (
|
||||||
<SettingsFormCell span="full">
|
<SettingsFormCell span="full">
|
||||||
<FormItem>
|
<FormField
|
||||||
<DomainPicker
|
control={form.control}
|
||||||
orgId={orgId}
|
name="httpConfigDomainId"
|
||||||
cols={2}
|
render={() => (
|
||||||
hideFreeDomain
|
<FormItem>
|
||||||
onDomainChange={(
|
<DomainPicker
|
||||||
res
|
orgId={orgId}
|
||||||
) => {
|
cols={2}
|
||||||
if (!res) {
|
hideFreeDomain
|
||||||
|
onDomainChange={(
|
||||||
|
res
|
||||||
|
) => {
|
||||||
|
if (!res) {
|
||||||
|
form.setValue(
|
||||||
|
"httpConfigSubdomain",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
form.setValue(
|
||||||
|
"httpConfigDomainId",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
form.setValue(
|
||||||
|
"httpConfigFullDomain",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigSubdomain",
|
"httpConfigSubdomain",
|
||||||
null
|
res.subdomain ??
|
||||||
|
null
|
||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigDomainId",
|
"httpConfigDomainId",
|
||||||
null
|
res.domainId,
|
||||||
|
{
|
||||||
|
shouldValidate: true
|
||||||
|
}
|
||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigFullDomain",
|
"httpConfigFullDomain",
|
||||||
null
|
res.fullDomain
|
||||||
);
|
);
|
||||||
return;
|
}}
|
||||||
}
|
/>
|
||||||
form.setValue(
|
<FormMessage />
|
||||||
"httpConfigSubdomain",
|
<FormDescription>
|
||||||
res.subdomain ??
|
{t(
|
||||||
null
|
"resourceDomainDescription"
|
||||||
);
|
)}
|
||||||
form.setValue(
|
</FormDescription>
|
||||||
"httpConfigDomainId",
|
</FormItem>
|
||||||
res.domainId
|
)}
|
||||||
);
|
/>
|
||||||
form.setValue(
|
</SettingsFormCell>
|
||||||
"httpConfigFullDomain",
|
)}
|
||||||
res.fullDomain
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<FormMessage />
|
|
||||||
<FormDescription>
|
|
||||||
{t(
|
|
||||||
"resourceDomainDescription"
|
|
||||||
)}
|
|
||||||
</FormDescription>
|
|
||||||
</FormItem>
|
|
||||||
</SettingsFormCell>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{(mode === "host" ||
|
{(mode === "host" ||
|
||||||
(mode === "ssh" && !isNativeSsh)) && (
|
(mode === "ssh" && !isNativeSsh)) && (
|
||||||
|
|||||||
@@ -124,13 +124,17 @@ export function PrivateResourceInfoSections({
|
|||||||
siteResource.fullDomain &&
|
siteResource.fullDomain &&
|
||||||
build != "oss"
|
build != "oss"
|
||||||
);
|
);
|
||||||
|
const showPortRestrictions =
|
||||||
|
isPanel &&
|
||||||
|
siteResource.mode !== "http" &&
|
||||||
|
siteResource.mode !== "inference";
|
||||||
|
|
||||||
const numSections =
|
const numSections =
|
||||||
2 +
|
2 +
|
||||||
(showDestination ? 1 : 0) +
|
(showDestination ? 1 : 0) +
|
||||||
(showAlias ? 1 : 0) +
|
(showAlias ? 1 : 0) +
|
||||||
(showCertificate ? 1 : 0) +
|
(showCertificate ? 1 : 0) +
|
||||||
(isPanel ? 1 : 0);
|
(showPortRestrictions ? 1 : 0);
|
||||||
|
|
||||||
const sections = (
|
const sections = (
|
||||||
<InfoSections cols={numSections} layout={isPanel ? "panel" : "default"}>
|
<InfoSections cols={numSections} layout={isPanel ? "panel" : "default"}>
|
||||||
@@ -194,7 +198,7 @@ export function PrivateResourceInfoSections({
|
|||||||
</InfoSection>
|
</InfoSection>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{isPanel ? (
|
{showPortRestrictions ? (
|
||||||
<InfoSection>
|
<InfoSection>
|
||||||
<InfoSectionTitle>{t("portRestrictions")}</InfoSectionTitle>
|
<InfoSectionTitle>{t("portRestrictions")}</InfoSectionTitle>
|
||||||
<InfoSectionContent>
|
<InfoSectionContent>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import type {
|
|||||||
LauncherViewConfig
|
LauncherViewConfig
|
||||||
} from "@server/routers/launcher/types";
|
} from "@server/routers/launcher/types";
|
||||||
import {
|
import {
|
||||||
|
LAUNCHER_AI_GATEWAY_GROUP_KEY,
|
||||||
LAUNCHER_NO_SITE_GROUP_KEY,
|
LAUNCHER_NO_SITE_GROUP_KEY,
|
||||||
LAUNCHER_UNLABELED_GROUP_KEY
|
LAUNCHER_UNLABELED_GROUP_KEY
|
||||||
} from "@server/routers/launcher/types";
|
} from "@server/routers/launcher/types";
|
||||||
@@ -148,9 +149,11 @@ export function LauncherGroupSection({
|
|||||||
const groupTitle =
|
const groupTitle =
|
||||||
group.groupKey === LAUNCHER_UNLABELED_GROUP_KEY
|
group.groupKey === LAUNCHER_UNLABELED_GROUP_KEY
|
||||||
? t("resourceLauncherUnlabeled")
|
? t("resourceLauncherUnlabeled")
|
||||||
: group.groupKey === LAUNCHER_NO_SITE_GROUP_KEY
|
: group.groupKey === LAUNCHER_AI_GATEWAY_GROUP_KEY
|
||||||
? t("resourceLauncherNoSite")
|
? t("resourceLauncherAiGateway")
|
||||||
: group.name;
|
: group.groupKey === LAUNCHER_NO_SITE_GROUP_KEY
|
||||||
|
? t("resourceLauncherNoSite")
|
||||||
|
: group.name;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Collapsible
|
<Collapsible
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
import { CollapsibleTrigger } from "@app/components/ui/collapsible";
|
import { CollapsibleTrigger } from "@app/components/ui/collapsible";
|
||||||
import type { LauncherGroup } from "@server/routers/launcher/types";
|
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";
|
import { ChevronDown, ChevronLeft } from "lucide-react";
|
||||||
|
|
||||||
type LauncherGroupTriggerProps = {
|
type LauncherGroupTriggerProps = {
|
||||||
@@ -21,6 +25,13 @@ function LauncherGroupStatusDot({ group }: { group: LauncherGroup }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (group.groupType === "site") {
|
if (group.groupType === "site") {
|
||||||
|
if (
|
||||||
|
group.groupKey === LAUNCHER_AI_GATEWAY_GROUP_KEY ||
|
||||||
|
group.groupKey === LAUNCHER_NO_SITE_GROUP_KEY
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(group.siteType === "newt" || group.siteType === "wireguard") &&
|
(group.siteType === "newt" || group.siteType === "wireguard") &&
|
||||||
typeof group.siteOnline === "boolean"
|
typeof group.siteOnline === "boolean"
|
||||||
@@ -47,11 +58,11 @@ export function LauncherGroupTrigger({
|
|||||||
title,
|
title,
|
||||||
isOpen
|
isOpen
|
||||||
}: LauncherGroupTriggerProps) {
|
}: LauncherGroupTriggerProps) {
|
||||||
|
const statusDot = <LauncherGroupStatusDot group={group} />;
|
||||||
|
|
||||||
return (
|
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">
|
<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" ? (
|
{statusDot}
|
||||||
<LauncherGroupStatusDot group={group} />
|
|
||||||
) : null}
|
|
||||||
<span className="flex min-w-0 items-center gap-2.5 text-sm font-semibold text-foreground">
|
<span className="flex min-w-0 items-center gap-2.5 text-sm font-semibold text-foreground">
|
||||||
<span className="truncate">
|
<span className="truncate">
|
||||||
{title} ({group.itemCount})
|
{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
|
InfoSectionTitle
|
||||||
} from "@app/components/InfoSection";
|
} from "@app/components/InfoSection";
|
||||||
import { PrivateResourceInfoSections } from "@app/components/PrivateResourceInfoBox";
|
import { PrivateResourceInfoSections } from "@app/components/PrivateResourceInfoBox";
|
||||||
|
import { LauncherInferenceApiKeysSection } from "@app/components/resource-launcher/LauncherInferenceApiKeysSection";
|
||||||
|
import { LauncherInferenceModelsSection } from "@app/components/resource-launcher/LauncherInferenceModelsSection";
|
||||||
import {
|
import {
|
||||||
SettingsSection,
|
SettingsSection,
|
||||||
SettingsSectionBody,
|
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 }) {
|
function AuthMethodStatusDisplay({ enabled }: { enabled: boolean }) {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
@@ -227,20 +230,24 @@ function PublicResourceAuthMethods({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function PublicResourceDetails({
|
function PublicResourceDetails({
|
||||||
|
orgId,
|
||||||
launcherResource,
|
launcherResource,
|
||||||
resource,
|
resource,
|
||||||
authInfo
|
authInfo
|
||||||
}: {
|
}: {
|
||||||
|
orgId: string;
|
||||||
launcherResource: LauncherResource;
|
launcherResource: LauncherResource;
|
||||||
resource: GetResourceResponse;
|
resource: GetResourceResponse;
|
||||||
authInfo: GetResourceAuthInfoResponse;
|
authInfo: GetResourceAuthInfoResponse;
|
||||||
}) {
|
}) {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const supportsAuth = PUBLIC_AUTH_BROWSER_MODES.includes(
|
const mode = resource.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 authState = derivePublicAuthState(resource.mode, authInfo);
|
||||||
const infoSectionCount = supportsAuth ? 4 : 3;
|
const infoSectionCount = 2 + (showAuthBadge ? 1 : 0) + (showHealth ? 1 : 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
@@ -275,7 +282,7 @@ function PublicResourceDetails({
|
|||||||
/>
|
/>
|
||||||
</InfoSectionContent>
|
</InfoSectionContent>
|
||||||
</InfoSection>
|
</InfoSection>
|
||||||
{supportsAuth ? (
|
{showAuthBadge ? (
|
||||||
<InfoSection>
|
<InfoSection>
|
||||||
<InfoSectionTitle>
|
<InfoSectionTitle>
|
||||||
{t("authentication")}
|
{t("authentication")}
|
||||||
@@ -295,30 +302,54 @@ function PublicResourceDetails({
|
|||||||
</InfoSectionContent>
|
</InfoSectionContent>
|
||||||
</InfoSection>
|
</InfoSection>
|
||||||
) : null}
|
) : null}
|
||||||
<InfoSection>
|
{showHealth ? (
|
||||||
<InfoSectionTitle>{t("health")}</InfoSectionTitle>
|
<InfoSection>
|
||||||
<InfoSectionContent>
|
<InfoSectionTitle>
|
||||||
<HealthStatusDisplay health={resource.health} />
|
{t("health")}
|
||||||
</InfoSectionContent>
|
</InfoSectionTitle>
|
||||||
</InfoSection>
|
<InfoSectionContent>
|
||||||
|
<HealthStatusDisplay
|
||||||
|
health={resource.health}
|
||||||
|
/>
|
||||||
|
</InfoSectionContent>
|
||||||
|
</InfoSection>
|
||||||
|
) : null}
|
||||||
</InfoSections>
|
</InfoSections>
|
||||||
</SettingsSectionBody>
|
</SettingsSectionBody>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
{supportsAuth ? (
|
{showAuthMethods ? (
|
||||||
<PublicResourceAuthMethods authInfo={authInfo} />
|
<PublicResourceAuthMethods authInfo={authInfo} />
|
||||||
) : null}
|
) : null}
|
||||||
|
{isInference ? (
|
||||||
|
<>
|
||||||
|
<LauncherInferenceModelsSection
|
||||||
|
orgId={orgId}
|
||||||
|
params={{
|
||||||
|
resourceType: "public",
|
||||||
|
resourceId: resource.resourceId
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<LauncherInferenceApiKeysSection
|
||||||
|
orgId={orgId}
|
||||||
|
resourceGuid={resource.resourceGuid}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function PrivateResourceDetails({
|
function PrivateResourceDetails({
|
||||||
|
orgId,
|
||||||
launcherResource,
|
launcherResource,
|
||||||
resource
|
resource
|
||||||
}: {
|
}: {
|
||||||
|
orgId: string;
|
||||||
launcherResource: LauncherResource;
|
launcherResource: LauncherResource;
|
||||||
resource: GetSiteResourceResponse;
|
resource: GetSiteResourceResponse;
|
||||||
}) {
|
}) {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
const isInference = resource.mode === "inference";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
@@ -365,6 +396,15 @@ function PrivateResourceDetails({
|
|||||||
/>
|
/>
|
||||||
</SettingsSectionBody>
|
</SettingsSectionBody>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
{isInference ? (
|
||||||
|
<LauncherInferenceModelsSection
|
||||||
|
orgId={orgId}
|
||||||
|
params={{
|
||||||
|
resourceType: "site",
|
||||||
|
siteResourceId: resource.siteResourceId
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -405,6 +445,7 @@ function LauncherResourcePanelBody({
|
|||||||
if (detail.resourceType === "public") {
|
if (detail.resourceType === "public") {
|
||||||
return (
|
return (
|
||||||
<PublicResourceDetails
|
<PublicResourceDetails
|
||||||
|
orgId={orgId}
|
||||||
launcherResource={resource}
|
launcherResource={resource}
|
||||||
resource={detail.data}
|
resource={detail.data}
|
||||||
authInfo={detail.authInfo}
|
authInfo={detail.authInfo}
|
||||||
@@ -414,6 +455,7 @@ function LauncherResourcePanelBody({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<PrivateResourceDetails
|
<PrivateResourceDetails
|
||||||
|
orgId={orgId}
|
||||||
launcherResource={resource}
|
launcherResource={resource}
|
||||||
resource={detail.data}
|
resource={detail.data}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export type LauncherAccessFields = {
|
|||||||
export function formatPublicResourceAccess(
|
export function formatPublicResourceAccess(
|
||||||
resource: PublicResourceAccessInput
|
resource: PublicResourceAccessInput
|
||||||
): LauncherAccessFields {
|
): LauncherAccessFields {
|
||||||
const browserModes = ["http", "ssh", "rdp", "vnc"];
|
const browserModes = ["http", "ssh", "rdp", "vnc", "inference"];
|
||||||
if (!browserModes.includes(resource.mode)) {
|
if (!browserModes.includes(resource.mode)) {
|
||||||
const port = resource.proxyPort?.toString() ?? "";
|
const port = resource.proxyPort?.toString() ?? "";
|
||||||
return {
|
return {
|
||||||
@@ -66,16 +66,8 @@ export function formatPublicResourceAccess(
|
|||||||
export function formatSiteResourceAccess(
|
export function formatSiteResourceAccess(
|
||||||
resource: SiteResourceAccessInput
|
resource: SiteResourceAccessInput
|
||||||
): LauncherAccessFields {
|
): LauncherAccessFields {
|
||||||
if (resource.alias) {
|
|
||||||
return {
|
|
||||||
accessDisplay: resource.alias,
|
|
||||||
accessCopyValue: resource.alias,
|
|
||||||
accessUrl: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(resource.mode === "http" || resource.mode == "inference") &&
|
(resource.mode === "http" || resource.mode === "inference") &&
|
||||||
resource.fullDomain
|
resource.fullDomain
|
||||||
) {
|
) {
|
||||||
const url = `${resource.ssl ? "https" : "http"}://${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({
|
const destination = formatSiteResourceDestinationDisplay({
|
||||||
mode: resource.mode as SiteResourceDestinationInput["mode"],
|
mode: resource.mode as SiteResourceDestinationInput["mode"],
|
||||||
destination: resource.destination,
|
destination: resource.destination,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { GetSiteResourceResponse } from "@server/routers/siteResource/getSi
|
|||||||
|
|
||||||
export type PublicAuthState = "protected" | "not_protected" | "none";
|
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(
|
export function derivePublicAuthState(
|
||||||
mode: string | null,
|
mode: string | null,
|
||||||
@@ -37,6 +37,10 @@ export function formatPublicResourceType(
|
|||||||
return resource.ssl ? "HTTPS" : "HTTP";
|
return resource.ssl ? "HTTPS" : "HTTP";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resource.mode === "inference") {
|
||||||
|
return "Inference";
|
||||||
|
}
|
||||||
|
|
||||||
const mode = (resource.mode || "").toLowerCase();
|
const mode = (resource.mode || "").toLowerCase();
|
||||||
if (mode === "tcp") {
|
if (mode === "tcp") {
|
||||||
return "TCP";
|
return "TCP";
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import type {
|
|||||||
ListLauncherSitesResponse,
|
ListLauncherSitesResponse,
|
||||||
ListLauncherViewsResponse
|
ListLauncherViewsResponse
|
||||||
} from "@server/routers/launcher/types";
|
} 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 { GetResourcePolicyResponse } from "@server/routers/policy";
|
||||||
import type {
|
import type {
|
||||||
GetResourcePoliciesResponse,
|
GetResourcePoliciesResponse,
|
||||||
@@ -1776,5 +1778,69 @@ export const launcherQueries = {
|
|||||||
data: res.data.data
|
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;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user