154 lines
5.4 KiB
TypeScript
154 lines
5.4 KiB
TypeScript
/**
|
|
* URL helper functions that ensure proper encoding of identifiers.
|
|
* Always use these instead of string interpolation to handle names with special characters.
|
|
*/
|
|
|
|
import type { ResolvedObject } from "~/types/tensorzero";
|
|
|
|
// ============================================================================
|
|
// Observability - Functions
|
|
// ============================================================================
|
|
|
|
export function toFunctionUrl(
|
|
functionName: string,
|
|
snapshotHash?: string,
|
|
): string {
|
|
const base = `/observability/functions/${encodeURIComponent(functionName)}`;
|
|
return appendSnapshotHash(base, snapshotHash);
|
|
}
|
|
|
|
export function toVariantUrl(
|
|
functionName: string,
|
|
variantName: string,
|
|
snapshotHash?: string,
|
|
): string {
|
|
const base = `/observability/functions/${encodeURIComponent(functionName)}/variants/${encodeURIComponent(variantName)}`;
|
|
return appendSnapshotHash(base, snapshotHash);
|
|
}
|
|
|
|
// ============================================================================
|
|
// Observability - Inferences
|
|
// ============================================================================
|
|
|
|
export function toInferenceUrl(inferenceId: string): string {
|
|
return `/observability/inferences/${encodeURIComponent(inferenceId)}`;
|
|
}
|
|
|
|
export function toInferenceApiUrl(inferenceId: string): string {
|
|
return `/api/inference/${encodeURIComponent(inferenceId)}`;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Observability - Episodes
|
|
// ============================================================================
|
|
|
|
export function toEpisodeUrl(episodeId: string): string {
|
|
return `/observability/episodes/${encodeURIComponent(episodeId)}`;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Datasets
|
|
// ============================================================================
|
|
|
|
export function toDatasetUrl(datasetName: string): string {
|
|
return `/datasets/${encodeURIComponent(datasetName)}`;
|
|
}
|
|
|
|
export function toDatapointUrl(
|
|
datasetName: string,
|
|
datapointId: string,
|
|
): string {
|
|
return `/datasets/${encodeURIComponent(datasetName)}/datapoint/${encodeURIComponent(datapointId)}`;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Evaluations
|
|
// ============================================================================
|
|
|
|
export function toEvaluationRunsUrl(runIds: string | string[]): string {
|
|
const ids = Array.isArray(runIds) ? runIds.join(",") : runIds;
|
|
return `/evaluations/runs?evaluation_run_ids=${encodeURIComponent(ids)}`;
|
|
}
|
|
|
|
export function toEvaluationDatapointUrl(
|
|
datapointId: string,
|
|
queryParams: { evaluation_run_ids: string },
|
|
): string {
|
|
return `/evaluations/results/${encodeURIComponent(datapointId)}?evaluation_run_ids=${encodeURIComponent(queryParams.evaluation_run_ids)}`;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Workflow Evaluations
|
|
// ============================================================================
|
|
|
|
export function toWorkflowEvaluationRunUrl(runId: string): string {
|
|
return `/workflow-evaluations/runs/${encodeURIComponent(runId)}`;
|
|
}
|
|
|
|
export function toWorkflowEvaluationProjectUrl(projectName: string): string {
|
|
return `/workflow-evaluations/projects/${encodeURIComponent(projectName)}`;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Optimization
|
|
// ============================================================================
|
|
|
|
export function toSupervisedFineTuningJobUrl(jobId: string): string {
|
|
return `/optimization/supervised-fine-tuning/${encodeURIComponent(jobId)}`;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Resolved Object URLs
|
|
// ============================================================================
|
|
|
|
export function toResolvedObjectUrl(
|
|
uuid: string,
|
|
obj: ResolvedObject,
|
|
): string | null {
|
|
switch (obj.type) {
|
|
case "inference":
|
|
return toInferenceUrl(uuid);
|
|
case "episode":
|
|
return toEpisodeUrl(uuid);
|
|
case "chat_datapoint":
|
|
case "json_datapoint":
|
|
return toDatapointUrl(obj.dataset_name, uuid);
|
|
case "model_inference":
|
|
case "boolean_feedback":
|
|
case "float_feedback":
|
|
case "comment_feedback":
|
|
case "demonstration_feedback":
|
|
return null;
|
|
default: {
|
|
const _exhaustiveCheck: never = obj;
|
|
return _exhaustiveCheck;
|
|
}
|
|
}
|
|
}
|
|
|
|
// ============================================================================
|
|
// Helpers
|
|
// ============================================================================
|
|
|
|
function appendSnapshotHash(url: string, snapshotHash?: string): string {
|
|
if (!snapshotHash) return url;
|
|
const separator = url.includes("?") ? "&" : "?";
|
|
return `${url}${separator}snapshot_hash=${encodeURIComponent(snapshotHash)}`;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Internal API Routes
|
|
// ============================================================================
|
|
|
|
export function toResolveUuidApi(uuid: string): string {
|
|
return `/api/tensorzero/resolve_uuid/${encodeURIComponent(uuid)}`;
|
|
}
|
|
|
|
export function toInferencePreviewApi(inferenceId: string): string {
|
|
return `/api/tensorzero/inference_preview/${encodeURIComponent(inferenceId)}`;
|
|
}
|
|
|
|
export function toEpisodePreviewApi(episodeId: string): string {
|
|
return `/api/tensorzero/episode_preview/${encodeURIComponent(episodeId)}`;
|
|
}
|