KV client for reading and rendering prompt templates from Cloudflare KV.

Optimized for edge/serverless environments, this client provides fast access to prompt templates stored in a KV namespace. Includes built-in Mustache template rendering for dynamic prompt generation.

const kv = new Teleprompter.KV(env);
const prompts = await kv.list();
const rendered = await kv.render('welcome-email', { name: 'Ada' });

Constructors

Methods

Constructors

  • Creates a new KV client instance.

    Parameters

    • env: ENV

      Environment bindings containing the PROMPTS KV namespace

    Returns KV

Methods

  • Retrieves a specific prompt by its ID from KV.

    Parameters

    • id: string

      The unique identifier of the prompt

    Returns Promise<null | Prompt>

    Promise resolving to the prompt, or null if not found

  • Lists all prompts stored in the KV namespace.

    Returns Promise<Prompt[]>

    Promise resolving to an array of all prompts (null values are filtered out)

  • Retrieves and renders a prompt template with the provided context.

    Uses Mustache for template rendering, supporting variables, conditionals, and loops in your prompt templates.

    Parameters

    • id: string

      The unique identifier of the prompt template

    • ctx: any

      The context object for template variable substitution

    Returns Promise<string>

    Promise resolving to the rendered prompt string

    Error if the prompt is not found

    const output = await kv.render('welcome-email', {
    name: 'Ada',
    company: 'Acme Corp'
    });
    // Result: "Welcome, Ada! Thank you for joining Acme Corp."