add manual virtual api key create ui

This commit is contained in:
miloschwartz
2026-08-10 21:44:22 -04:00
parent 4c1f7f6243
commit 6d45486bb5
16 changed files with 1974 additions and 18 deletions
+12 -2
View File
@@ -62,10 +62,18 @@ export async function assertManualKeyResourcesInOrg(params: {
}): Promise<{ ok: true } | { ok: false; message: string }> {
const { allResources, resourceIds, orgId } = params;
if (allResources || resourceIds.length === 0) {
if (allResources) {
return { ok: true };
}
if (resourceIds.length === 0) {
return {
ok: false,
message:
"Select at least one public inference resource, or enable all public inference resources"
};
}
const uniqueIds = [...new Set(resourceIds)];
const rows = await db
.select({ resourceId: resources.resourceId })
@@ -73,6 +81,7 @@ export async function assertManualKeyResourcesInOrg(params: {
.where(
and(
eq(resources.orgId, orgId),
eq(resources.mode, "inference"),
inArray(resources.resourceId, uniqueIds)
)
);
@@ -80,7 +89,8 @@ export async function assertManualKeyResourcesInOrg(params: {
if (rows.length !== uniqueIds.length) {
return {
ok: false,
message: "One or more resources are invalid for this organization"
message:
"One or more resources are invalid public inference resources for this organization"
};
}
+11 -2
View File
@@ -124,12 +124,21 @@ const listResourcesSchema = z.strictObject({
"Filter resources based on health status of their targets. `healthy` means all targets are healthy. `degraded` means at least one target is unhealthy, but not all are unhealthy. `offline` means all targets are unhealthy. `unknown` means all targets have unknown health status."
}),
protocol: z
.enum(["http", "https", "tcp", "udp", "ssh", "rdp", "vnc"])
.enum(["http", "https", "tcp", "udp", "ssh", "rdp", "vnc", "inference"])
.optional()
.catch(undefined)
.openapi({
type: "string",
enum: ["http", "https", "tcp", "udp", "ssh", "rdp", "vnc"],
enum: [
"http",
"https",
"tcp",
"udp",
"ssh",
"rdp",
"vnc",
"inference"
],
description:
"Filter resources by protocol. `http` and `https` match HTTP resources without and with SSL respectively."
}),
+17 -8
View File
@@ -4,14 +4,23 @@ export const virtualApiKeyResourceIdsSchema = z
.array(z.coerce.number().int().positive())
.optional();
export const createVirtualApiKeyBodySchema = z.strictObject({
name: z.string().nonempty(),
description: z.string().optional().nullable(),
userId: z.string().optional().nullable(),
allResources: z.boolean().optional().default(false),
resourceIds: virtualApiKeyResourceIdsSchema,
validForSeconds: z.int().positive().optional()
});
export const createVirtualApiKeyBodySchema = z
.strictObject({
name: z.string().nonempty(),
description: z.string().optional().nullable(),
userId: z.string().optional().nullable(),
allResources: z.boolean().optional().default(false),
resourceIds: virtualApiKeyResourceIdsSchema,
validForSeconds: z.int().positive().optional()
})
.refine(
(data) => data.allResources || (data.resourceIds?.length ?? 0) > 0,
{
message:
"Select at least one public inference resource, or enable all public inference resources",
path: ["resourceIds"]
}
);
export const updateVirtualApiKeyBodySchema = z.strictObject({
name: z.string().nonempty().optional(),