Nirmos
SDK reference

Prompt types

Public prompts types and declarations exported from @nirmos/sdk.

Import these names from @nirmos/sdk. Optional fields may be absent; nullable fields may be null. Dates in management DTOs remain strings. These declarations do not imply provider support or runtime implementation. Use TypeScript support for indexed DTOs.

The declaration shorthand ExtensibleString<T> means T | (string & {}): known values keep autocomplete while other strings remain assignable. This helper itself is not a root export.

ChatPromptContent

export interface ChatPromptContent {
    type: "chat";
    messages: readonly ChatMessage[];
}

Prompt

export interface Prompt {
    id: string;
    name: string;
    slug: string;
    description?: string;
    status: PromptStatus;
    version: PromptVersion;
    content: PromptContent;
    variables: readonly PromptVariable[];
    metadata: Readonly<Record<string, JsonValue>>;
    tags: readonly string[];
    folder?: string;
    createdAt?: string;
    updatedAt?: string;
    requestMetadata: RequestMetadata;
}

PromptCacheConfig

export interface PromptCacheConfig {
    /** Cache active prompt retrievals in memory. Defaults to true. */
    enabled?: boolean;
    /** Freshness window. Defaults to 60 seconds. */
    ttlMs?: number;
    /** Maximum cached prompt variants per client. Defaults to 100. */
    maxEntries?: number;
}

PromptCacheMode

export type PromptCacheMode = "default" | "reload" | "no-store";

PromptContent

export type PromptContent = TextPromptContent | ChatPromptContent;

PromptCreateParams

export interface PromptCreateParams {
    name: string;
    slug?: string;
    description?: string;
    content: PromptContent;
    variables?: readonly PromptVariable[];
    metadata?: Readonly<Record<string, JsonValue>>;
    tags?: readonly string[];
    folder?: string;
    commitMessage?: string;
    activate?: boolean;
}

PromptIdentifier

export type PromptIdentifier = string;

PromptRenderOptions

export interface PromptRenderOptions {
    allowUnresolved?: boolean;
}

PromptRenderReference

export interface PromptRenderReference {
    id: PromptIdentifier;
    version?: number | "active" | "latest";
    cache?: PromptCacheMode;
}

PromptRetrieveOptions

export interface PromptRetrieveOptions extends RequestOptions {
    version?: number | "active" | "latest";
    cache?: PromptCacheMode;
}

PromptStatus

export type PromptStatus = ExtensibleString<"draft" | "active" | "archived" | "published">;

PromptUpdateParams

export interface PromptUpdateParams {
    name?: string;
    slug?: string;
    description?: string | null;
    metadata?: Readonly<Record<string, JsonValue>>;
    tags?: readonly string[];
    folder?: string | null;
    status?: PromptStatus;
}

PromptVariable

export interface PromptVariable {
    name: string;
    type: PromptVariableType;
    required?: boolean;
    description?: string;
    default?: JsonValue;
    values?: readonly string[];
    min?: number;
    max?: number;
    minLength?: number;
    maxLength?: number;
    itemType?: PromptVariableType;
}

PromptVariableType

export type PromptVariableType = "string" | "number" | "boolean" | "enum" | "array";

PromptVariableValue

export type PromptVariableValue = JsonValue | undefined;

PromptVariableValues

export type PromptVariableValues = Readonly<Record<string, PromptVariableValue>>;

PromptVersion

export interface PromptVersion {
    id: string;
    number: number;
    status: PromptStatus;
    active: boolean;
    content: PromptContent;
    variables: readonly PromptVariable[];
    metadata: Readonly<Record<string, JsonValue>>;
    commitMessage?: string;
    createdAt?: string;
    updatedAt?: string;
}

PromptVersionCreateParams

export interface PromptVersionCreateParams {
    content: PromptContent;
    variables?: readonly PromptVariable[];
    metadata?: Readonly<Record<string, JsonValue>>;
    commitMessage?: string;
    activate?: boolean;
}

PromptVersionListOptions

export interface PromptVersionListOptions extends RequestOptions {
    limit?: number;
    cursor?: string;
}

PromptVersionPage

export type PromptVersionPage = Page<PromptVersion>;

RenderedPrompt

export interface RenderedPrompt {
    promptId: string;
    promptVersion: number;
    messages: readonly ChatMessage[];
    variables: PromptVariableValues;
}

TextPromptContent

export interface TextPromptContent {
    type: "text";
    text: string;
    role?: Exclude<ChatRole, "tool">;
}

extractPromptVariableNames

export function extractPromptVariableNames(...values: Array<string | null | undefined>): string[] {
    return [
        ...new Set(values.flatMap((value) => [...(value ?? "").matchAll(PROMPT_VARIABLE_PATTERN)].map((match) => match[1]!))),
    ];
}

interpolatePromptVariables

export function interpolatePromptVariables(text: string, values: Record<string, unknown>): string {
    return text.replace(PROMPT_VARIABLE_PATTERN, (token, name: string) => {
        const value = promptVariableValue(values, name);
        return value === undefined
            ? token
            : typeof value === "string"
                ? value
                : JSON.stringify(value);
    });
}

promptVariableValue

export function promptVariableValue(values: Record<string, unknown>, name: string): unknown {
    if (Object.hasOwn(values, name))
        return values[name];
    let current: unknown = values;
    for (const key of name.split(".")) {
        if (["__proto__", "prototype", "constructor"].includes(key) ||
            !current ||
            typeof current !== "object" ||
            !Object.hasOwn(current, key))
            return undefined;
        current = (current as Record<string, unknown>)[key];
    }
    return current;
}

validatePromptTemplate

export function validatePromptTemplate(text: string): string[] {
    const remaining = text.replace(PROMPT_VARIABLE_PATTERN, "");
    return /\{\{|\{%/.test(remaining)
        ? [
            "Unsupported variable syntax. Use {{name}}, {{ spaced }}, or {{user.name}}. Expressions, filters and template blocks cannot run as managed prompt variables.",
        ]
        : [];
}

validatePromptVariableValues

export function validatePromptVariableValues(definitions: readonly VariableDefinition[], values: Record<string, unknown>): Record<string, string> {
    const errors: Record<string, string> = {};
    for (const definition of definitions) {
        const supplied = promptVariableValue(values, definition.name);
        const value = supplied === undefined ? definition.default : supplied;
        let error = "";
        if (value === undefined || value === "") {
            if (definition.required)
                error = "A value is required.";
        }
        else {
            const type = definition.type;
            if (type === "number" &&
                (typeof value !== "number" || !Number.isFinite(value)))
                error = "Enter a valid number.";
            if (type === "boolean" && typeof value !== "boolean")
                error = "Choose true or false.";
            if (type === "string" && typeof value !== "string")
                error = "Enter text.";
            if (type === "enum" &&
                !(definition.enum ?? definition.values)?.includes(String(value)))
                error = "Choose one of the allowed values.";
            if (type === "array" && !Array.isArray(value))
                error = "Enter a valid array.";
            if (typeof value === "number" &&
                ((definition.min !== undefined && value < definition.min) ||
                    (definition.max !== undefined && value > definition.max)))
                error = `Enter a number between ${definition.min ?? "−∞"} and ${definition.max ?? "∞"}.`;
            const minLength = definition.minLength ?? definition.min_length;
            const maxLength = definition.maxLength ?? definition.max_length;
            if (typeof value === "string" &&
                ((minLength !== undefined && value.length < minLength) ||
                    (maxLength !== undefined && value.length > maxLength)))
                error = `Use ${minLength ?? 0} to ${maxLength ?? "any number of"} characters.`;
            const itemType = definition.itemType ?? definition.item_type;
            if (Array.isArray(value) &&
                itemType &&
                value.some((item) => itemType === "array"
                    ? !Array.isArray(item)
                    : itemType !== "enum" && typeof item !== itemType))
                error = `Every item must be ${itemType}.`;
        }
        if (error)
            errors[definition.name] = error;
    }
    return errors;
}

validatePromptSettings

export function validatePromptSettings(settings: {
    temperature: unknown;
    topP: unknown;
    maxTokens: unknown;
}): Record<string, string> {
    const errors: Record<string, string> = {};
    for (const [field, label, min, max] of [
        ["temperature", "Temperature", 0, 2],
        ["topP", "Top P", 0, 1],
        ["maxTokens", "Max tokens", 1, 200000],
    ] as const) {
        const raw = settings[field];
        const value = Number(raw);
        if (raw === "" ||
            raw === null ||
            raw === undefined ||
            !Number.isFinite(value) ||
            value < min ||
            value > max ||
            (field === "maxTokens" && !Number.isInteger(value)))
            errors[field] =
                `${label} must be ${field === "maxTokens" ? "a whole number" : "a number"} between ${min} and ${max}.`;
    }
    return errors;
}

On this page