Spaces:
Runtime error
Runtime error
File size: 2,250 Bytes
cd8bd0a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | /**
* Centralized display name helpers for provider and account/connection labels.
*
* Prevents raw internal IDs (connection UUIDs, dynamic provider IDs) from
* leaking into user-facing dashboards (Health, Analytics, Sessions, Rate-limits,
* Quota, Compatible Provider pages, etc.).
*
* Priority order:
* β Account: name β displayName β email β short readble label
* β Provider: node.name β node.prefix β alias β readable ID
*
* @module lib/display/names
*/
export interface ConnectionLike {
id?: string | null;
name?: string | null;
displayName?: string | null;
email?: string | null;
}
export interface ProviderNodeLike {
name?: string | null;
prefix?: string | null;
}
/**
* Friendly display name for an account/connection.
*
* Priority: name β displayName β email β "Account #<6-char ID>"
*/
export function getAccountDisplayName(conn: ConnectionLike): string {
if (!conn) return "Unknown Account";
const name =
(typeof conn.name === "string" && conn.name.trim()) ||
(typeof conn.displayName === "string" && conn.displayName.trim()) ||
(typeof conn.email === "string" && conn.email.trim());
if (name) return name;
if (typeof conn.id === "string" && conn.id) {
return `Account #${conn.id.slice(0, 6)}`;
}
return "Unknown Account";
}
/**
* Friendly display name for a provider node/ID.
*
* Priority: node.name β node.prefix β de-UUIDed providerId
*
* Dynamic compatible provider IDs like
* "openai-compatible-chat-02669115-2545-4896-b003-cb4dac09d441"
* are rendered as "Compatible (openai)".
*/
export function getProviderDisplayName(
providerId: string | null | undefined,
providerNode?: ProviderNodeLike | null
): string {
if (providerNode?.name?.trim()) return providerNode.name.trim();
if (providerNode?.prefix?.trim()) return providerNode.prefix.trim();
if (!providerId) return "Unknown Provider";
// Simplify dynamic compatible provider IDs
const match = providerId.match(
/^(openai|anthropic)-compatible-(?:chat|responses)-[0-9a-f-]{10,}$/i
);
if (match) return `Compatible (${match[1]})`;
if (/^anthropic-compatible-cc-[0-9a-f-]{10,}$/i.test(providerId)) {
return "CC Compatible";
}
return providerId;
}
|