{"version":3,"sources":["../../src/system-prompts/builder.ts"],"sourcesContent":["/**\n * System Prompt Plugin Builder utilities\n *\n * Provides helper functions for creating and validating system prompt plugins.\n *\n * @module @quilltap/plugin-utils/system-prompts\n */\n\nimport type {\n  SystemPromptData,\n  SystemPromptMetadata,\n  SystemPromptPlugin,\n} from '@quilltap/plugin-types';\n\n// ============================================================================\n// BUILDER OPTIONS\n// ============================================================================\n\n/**\n * Options for creating a system prompt plugin\n */\nexport interface CreateSystemPromptPluginOptions {\n  /** Plugin metadata */\n  metadata: SystemPromptMetadata;\n\n  /**\n   * One or more system prompts.\n   * Each prompt must have a unique name within the plugin.\n   */\n  prompts: SystemPromptData[];\n\n  /**\n   * Optional initialization function.\n   * Called when the plugin is loaded.\n   */\n  initialize?: () => void | Promise<void>;\n}\n\n// ============================================================================\n// BUILDER FUNCTIONS\n// ============================================================================\n\n/**\n * Creates a system prompt plugin.\n *\n * @param options - Plugin configuration options\n * @returns A valid SystemPromptPlugin instance\n *\n * @example\n * ```typescript\n * import { createSystemPromptPlugin } from '@quilltap/plugin-utils';\n *\n * export const plugin = createSystemPromptPlugin({\n *   metadata: {\n *     pluginId: 'my-prompts',\n *     displayName: 'My Prompt Collection',\n *     description: 'Custom system prompts for various models',\n *   },\n *   prompts: [\n *     {\n *       name: 'CLAUDE_CREATIVE',\n *       content: '# Creative Writing Prompt\\n\\nYou are {{char}}...',\n *       modelHint: 'CLAUDE',\n *       category: 'CREATIVE',\n *     },\n *   ],\n * });\n * ```\n */\nexport function createSystemPromptPlugin(\n  options: CreateSystemPromptPluginOptions\n): SystemPromptPlugin {\n  const { metadata, prompts, initialize } = options;\n\n  // Validate prompts\n  if (prompts.length === 0) {\n    throw new Error('At least one system prompt is required');\n  }\n\n  // Check for duplicate names\n  const names = new Set<string>();\n  for (const prompt of prompts) {\n    if (!prompt.name || prompt.name.trim() === '') {\n      throw new Error('Prompt name is required');\n    }\n    if (!prompt.content || prompt.content.trim() === '') {\n      throw new Error(`Prompt \"${prompt.name}\" requires content`);\n    }\n    if (!prompt.modelHint || prompt.modelHint.trim() === '') {\n      throw new Error(`Prompt \"${prompt.name}\" requires a modelHint`);\n    }\n    if (!prompt.category || prompt.category.trim() === '') {\n      throw new Error(`Prompt \"${prompt.name}\" requires a category`);\n    }\n    if (names.has(prompt.name)) {\n      throw new Error(`Duplicate prompt name: \"${prompt.name}\"`);\n    }\n    names.add(prompt.name);\n  }\n\n  // Create the plugin\n  const plugin: SystemPromptPlugin = {\n    metadata,\n    prompts,\n  };\n\n  // Add initialize function if provided\n  if (initialize) {\n    plugin.initialize = async () => {\n      await initialize();\n    };\n  }\n\n  return plugin;\n}\n\n// ============================================================================\n// VALIDATION UTILITIES\n// ============================================================================\n\n/**\n * Validates a complete system prompt plugin\n *\n * @param plugin - The plugin to validate\n * @returns True if valid, throws Error if invalid\n */\nexport function validateSystemPromptPlugin(plugin: SystemPromptPlugin): boolean {\n  // Validate metadata\n  if (!plugin.metadata) {\n    throw new Error('Plugin metadata is required');\n  }\n\n  if (!plugin.metadata.pluginId || plugin.metadata.pluginId.trim() === '') {\n    throw new Error('Plugin metadata.pluginId is required');\n  }\n\n  if (!/^[a-z0-9-]+$/.test(plugin.metadata.pluginId)) {\n    throw new Error('Plugin pluginId must be lowercase alphanumeric with hyphens only');\n  }\n\n  if (!plugin.metadata.displayName || plugin.metadata.displayName.trim() === '') {\n    throw new Error('Plugin metadata.displayName is required');\n  }\n\n  // Validate prompts\n  if (!plugin.prompts || !Array.isArray(plugin.prompts) || plugin.prompts.length === 0) {\n    throw new Error('Plugin must have at least one prompt');\n  }\n\n  const names = new Set<string>();\n  for (const prompt of plugin.prompts) {\n    if (!prompt.name || prompt.name.trim() === '') {\n      throw new Error('Prompt name is required');\n    }\n    if (!prompt.content || prompt.content.trim() === '') {\n      throw new Error(`Prompt \"${prompt.name}\" requires content`);\n    }\n    if (!prompt.modelHint || prompt.modelHint.trim() === '') {\n      throw new Error(`Prompt \"${prompt.name}\" requires a modelHint`);\n    }\n    if (!prompt.category || prompt.category.trim() === '') {\n      throw new Error(`Prompt \"${prompt.name}\" requires a category`);\n    }\n    if (names.has(prompt.name)) {\n      throw new Error(`Duplicate prompt name: \"${prompt.name}\"`);\n    }\n    names.add(prompt.name);\n  }\n\n  return true;\n}\n"],"mappings":";AAqEO,SAAS,yBACd,SACoB;AACpB,QAAM,EAAE,UAAU,SAAS,WAAW,IAAI;AAG1C,MAAI,QAAQ,WAAW,GAAG;AACxB,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AAGA,QAAM,QAAQ,oBAAI,IAAY;AAC9B,aAAW,UAAU,SAAS;AAC5B,QAAI,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,MAAM,IAAI;AAC7C,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AACA,QAAI,CAAC,OAAO,WAAW,OAAO,QAAQ,KAAK,MAAM,IAAI;AACnD,YAAM,IAAI,MAAM,WAAW,OAAO,IAAI,oBAAoB;AAAA,IAC5D;AACA,QAAI,CAAC,OAAO,aAAa,OAAO,UAAU,KAAK,MAAM,IAAI;AACvD,YAAM,IAAI,MAAM,WAAW,OAAO,IAAI,wBAAwB;AAAA,IAChE;AACA,QAAI,CAAC,OAAO,YAAY,OAAO,SAAS,KAAK,MAAM,IAAI;AACrD,YAAM,IAAI,MAAM,WAAW,OAAO,IAAI,uBAAuB;AAAA,IAC/D;AACA,QAAI,MAAM,IAAI,OAAO,IAAI,GAAG;AAC1B,YAAM,IAAI,MAAM,2BAA2B,OAAO,IAAI,GAAG;AAAA,IAC3D;AACA,UAAM,IAAI,OAAO,IAAI;AAAA,EACvB;AAGA,QAAM,SAA6B;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAGA,MAAI,YAAY;AACd,WAAO,aAAa,YAAY;AAC9B,YAAM,WAAW;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAYO,SAAS,2BAA2B,QAAqC;AAE9E,MAAI,CAAC,OAAO,UAAU;AACpB,UA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