{"version":3,"file":"instruction.mjs","names":[],"sources":["../../../../../../../ai/src/system-prompt/instruction.ts"],"sourcesContent":["import type { Placeholders } from \"../contracts/placeholders.type\";\nimport type { InstructionContract } from \"../contracts/system-prompt.contract\";\nimport { renderPlaceholders } from \"./render-placeholders\";\n\n/**\n * Concrete `InstructionContract` — a reusable directive block.\n *\n * **Role.** A single addressable prompt block representing one rule the\n * agent must follow (`\"Always respond in {{language|English}}.\"`). Exists\n * as its own type so the same instruction can be shared across many\n * prompts and agents, each render supplying its own placeholder map.\n *\n * **Responsibility.**\n * - Owns: the `type: \"instruction\"` discriminator, the raw template text,\n *   and the placeholder-rendering step.\n * - Does NOT own: ordering relative to other instructions, joining with a\n *   persona, or any surrounding prompt composition — those concerns live\n *   in `SystemPrompt`.\n *\n * Users construct via the `ai.instruction()` factory — `new Instruction()`\n * is not the public API (see §4.2 of code-style.md).\n *\n * @example\n * const replyInLanguage = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt()\n *   .persona(\"You are Alex.\")\n *   .instruction(replyInLanguage)\n *   .instruction(\"Always include code examples.\");\n */\nexport class Instruction implements InstructionContract {\n  public readonly type = \"instruction\" as const;\n\n  public constructor(public readonly text: string) {\n    //\n  }\n\n  /**\n   * Substitute `{{mustache}}` placeholders in the instruction text against\n   * the supplied map. Delegates to the shared `renderPlaceholders` helper\n   * so persona / instruction / system-prompt rendering stays identical.\n   */\n  public resolve(placeholders?: Placeholders): string {\n    return renderPlaceholders(this.text, placeholders);\n  }\n}\n\n/**\n * Create an `Instruction` from raw template text.\n *\n * @example\n * const replyIn = instruction(\"Respond in {{language|English}}.\");\n * const cite = instruction(\"Always cite sources inline.\");\n */\nexport function instruction(text: string): Instruction {\n  return new Instruction(text);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,cAAb,MAAwD;CAGtD,AAAO,YAAY,AAAgB,MAAc;EAAd;cAFZ;CAIvB;;;;;;CAOA,AAAO,QAAQ,cAAqC;EAClD,OAAO,mBAAmB,KAAK,MAAM,YAAY;CACnD;AACF;;;;;;;;AASA,SAAgB,YAAY,MAA2B;CACrD,OAAO,IAAI,YAAY,IAAI;AAC7B"}