prompts/parsePromptDependencyTags.ts

langfuse · packages/shared/src/features/prompts/parsePromptDependencyTags.ts · typescript · MIT
ai, tag:knn-classified

Module exposing: parsePromptDependencyTags, PromptDependencyRegex, ParsedPromptDependencySchema

// Source: https://github.com/langfuse/langfuse | License: MIT | Copyright 2023-2026 ClickHouse, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import { z } from "zod";

export const PromptDependencyRegex = /@@@langfusePrompt:(.*?)@@@/g;

export const ParsedPromptDependencySchema = z.union([
  z.object({
    name: z.string(),
    type: z.literal("version"),
    version: z.coerce.number(),
  }),
  z.object({ name: z.string(), type: z.literal("label"), label: z.string() }),
]);

export type ParsedPromptDependencyTag = z.infer<
  typeof ParsedPromptDependencySchema
>;

export function parsePromptDependencyTags(
  content: string | object,
): ParsedPromptDependencyTag[] {
  const matchedTags = JSON.stringify(content).match(PromptDependencyRegex);

  const validTags: Parse

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key