Implementation:Ucbepic Docetl ApiUtils
| Knowledge Sources | |
|---|---|
| Domains | Frontend, React_UI |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete tool for server-side utility functions that generate pipeline YAML configurations and handle encryption in the DocETL frontend.
Description
This module provides utility functions used by various API routes. It includes an Encryptor class for simple character-code-based encryption with LZ-string compression, a generatePipelineConfig function that assembles YAML pipeline configurations from operations and settings, and helpers like getNamespaceDir, safeParseJSON, and sanitizeForYaml for data processing and serialization safety.
Usage
Imported by API routes (e.g., run pipeline, write pipeline) to transform frontend operation state into the YAML configuration format expected by the DocETL Python backend.
Code Reference
Source Location
- Repository: Ucbepic_Docetl
- File: website/src/app/api/utils.ts
- Lines: 1-404
Signature
export function getNamespaceDir(homeDir: string, namespace: string): string
export function generatePipelineConfig(
namespace: string,
default_model: string,
data: { path: string },
operations: Operation[],
operation_id: string,
name: string,
homeDir: string,
sample_size: number | null,
optimize?: boolean,
clear_intermediate?: boolean,
system_prompt?: { datasetDescription: string | null; persona: string | null },
apiKeys?: APIKey[],
optimizerModel?: string,
extraPipelineSettings?: Record<string, unknown> | null
): string
Import
import { generatePipelineConfig, getNamespaceDir } from "@/app/api/utils";
I/O Contract
Inputs (Props)
| Name | Type | Required | Description |
|---|---|---|---|
| namespace | string | Yes | User namespace identifier |
| default_model | string | Yes | Default LLM model name |
| data | { path: string } | Yes | Dataset file path |
| operations | Operation[] | Yes | Array of pipeline operations |
| operation_id | string | Yes | Current operation ID |
| name | string | Yes | Pipeline name |
| homeDir | string | Yes | Home directory for namespace storage |
| sample_size | number or null | Yes | Sample size for pipeline execution |
Outputs
| Name | Type | Description |
|---|---|---|
| config | string | YAML-formatted pipeline configuration string |
Usage Examples
const yamlConfig = generatePipelineConfig(
"my-namespace",
"gpt-4o-mini",
{ path: "/data/input.json" },
operations,
"op-123",
"my-pipeline",
"/home/user",
100
);