@riotprompt/riotprompt 0.0.3 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"override.js","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDirs: z.array(z.string()).default(['./overrides']),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const response: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = {\n prepends: [],\n appends: []\n };\n\n // Process directories in order (closest to furthest)\n for (let i = 0; i < options.configDirs.length; i++) {\n const configDir = options.configDirs[i];\n const baseFile = path.join(configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n // Check for prepend files (-pre.md)\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s (layer %d)', preFile, i + 1);\n const parser = Parser.create({ logger });\n const prependSection = await parser.parseFile<T>(preFile, currentSectionOptions);\n response.prepends.push(prependSection);\n }\n\n // Check for append files (-post.md)\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s (layer %d)', postFile, i + 1);\n const parser = Parser.create({ logger });\n const appendSection = await parser.parseFile<T>(postFile, currentSectionOptions);\n response.appends.push(appendSection);\n }\n\n // Check for complete override files - use the first (closest) one found\n if (!response.override && await storage.exists(baseFile)) {\n logger.silly('Found base file %s (layer %d)', baseFile, i + 1);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { override: overrideContent, prepends, appends }: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n // Apply prepends in order (closest layer first)\n for (const prepend of prepends) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n // Apply appends in reverse order (furthest layers first, then closest)\n for (const append of appends.reverse()) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDirs","array","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","response","prepends","appends","i","length","configDir","baseFile","path","join","preFile","replace","postFile","exists","silly","parser","Parser","prependSection","parseFile","push","appendSection","warn","error","Error","customize","overrideContent","finalSection","prepend","append","reverse","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYP,EAAEQ,KAAK,CAACR,EAAES,MAAM,EAAA,CAAA,CAAIJ,OAAO,CAAC;AAAC,QAAA;AAAc,KAAA,CAAA;AACvDK,IAAAA,SAAAA,EAAWV,CAAAA,CAAEW,OAAO,EAAA,CAAGN,OAAO,CAAC,KAAA,CAAA;AAC/BO,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBT,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAYO,MAAMS,MAAAA,GAAS,CAACC,eAAAA,GAAgC,EAAE,GAAA;IACr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,KAAK,MAAMC,MAAAA,IAAUzB,OAAAA,CAAQ0B,OAAO,EAAA,CAAI;YACpCzD,MAAAA,CAAO0C,KAAK,CAAC,8CAAA,EAAgDc,MAAAA,CAAAA;YAC7DF,YAAAA,GAAeA,YAAAA,CAAaE,MAAM,CAACA,MAAAA,CAAAA;AACvC;QAEA,MAAME,WAAAA,GAAYC,QAAgB,CAAC;AAAE3D,YAAAA;AAAO,SAAA,CAAA;QAC5CA,MAAAA,CAAO0C,KAAK,CAAC,6BAAA,EAA+B1C,MAAAA,CAAO4D,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACP,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,KAAA;IAEA,OAAO;AACH7B,QAAAA,QAAAA;AACA2B,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"override.js","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDirs: z.array(z.string()).default(['./overrides']),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const response: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = {\n prepends: [],\n appends: []\n };\n\n // Process directories in order (closest to furthest)\n for (let i = 0; i < options.configDirs.length; i++) {\n const configDir = options.configDirs[i];\n const baseFile = path.join(configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n // Check for prepend files (-pre.md)\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s (layer %d)', preFile, i + 1);\n const parser = Parser.create({ logger });\n const prependSection = await parser.parseFile<T>(preFile, currentSectionOptions);\n response.prepends.push(prependSection);\n }\n\n // Check for append files (-post.md)\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s (layer %d)', postFile, i + 1);\n const parser = Parser.create({ logger });\n const appendSection = await parser.parseFile<T>(postFile, currentSectionOptions);\n response.appends.push(appendSection);\n }\n\n // Check for complete override files - use the first (closest) one found\n if (!response.override && await storage.exists(baseFile)) {\n logger.silly('Found base file %s (layer %d)', baseFile, i + 1);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { override: overrideContent, prepends, appends }: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n // Apply prepends in order (closest layer first)\n for (const prepend of prepends) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n // Apply appends in reverse order (furthest layers first, then closest)\n for (const append of appends.reverse()) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDirs","array","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","response","prepends","appends","i","length","configDir","baseFile","path","join","preFile","replace","postFile","exists","silly","parser","Parser","prependSection","parseFile","push","appendSection","warn","error","Error","customize","overrideContent","finalSection","prepend","append","reverse","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CA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AS,EAAE;gBACnBR,MAAAA,CAAOiD,IAAI,CAAC,gDAAA,EAAkDI,eAAAA,CAAAA;gBAC9DC,YAAAA,GAAeD,eAAAA;YACnB,CAAA,MAAO;AACHrD,gBAAAA,MAAAA,CAAOkD,KAAK,CAAC,sEAAA,CAAA;AACb,gBAAA,MAAM,IAAIC,KAAAA,CAAM,+IAAA,CAAA;AACpB,YAAA;AACJ,QAAA;;QAGA,KAAK,MAAMI,WAAWzB,QAAAA,CAAU;YAC5B9B,MAAAA,CAAO0C,KAAK,CAAC,+CAAA,EAAiDa,OAAAA,CAAAA;YAC9DD,YAAAA,GAAeA,YAAAA,CAAaC,OAAO,CAACA,OAAAA,CAAAA;AACxC,QAAA;;AAGA,QAAA,KAAK,MAAMC,MAAAA,IAAUzB,OAAAA,CAAQ0B,OAAO,EAAA,CAAI;YACpCzD,MAAAA,CAAO0C,KAAK,CAAC,8CAAA,EAAgDc,MAAAA,CAAAA;YAC7DF,YAAAA,GAAeA,YAAAA,CAAaE,MAAM,CAACA,MAAAA,CAAAA;AACvC,QAAA;QAEA,MAAME,WAAAA,GAAYC,QAAgB,CAAC;AAAE3D,YAAAA;AAAO,SAAA,CAAA;QAC5CA,MAAAA,CAAO0C,KAAK,CAAC,6BAAA,EAA+B1C,MAAAA,CAAO4D,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACP,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACH7B,QAAAA,QAAAA;AACA2B,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -1,3 +1,3 @@
1
1
  import { Section, SectionOptions } from '../items/section';
2
2
  import { Weighted } from '../items/weighted';
3
- export declare const parseMarkdown: <T extends Weighted>(input: string | Buffer, options?: Partial<SectionOptions>) => Section<T>;
3
+ export declare const parseMarkdown: <T extends Weighted>(input: string | Buffer, options?: Partial<SectionOptions>) => Promise<Section<T>>;
@@ -1,8 +1,9 @@
1
- import { marked } from 'marked';
2
1
  import { SectionOptionsSchema, create } from '../items/section.js';
3
2
  import { WeightedOptionsSchema, create as create$1 } from '../items/weighted.js';
4
3
 
5
- const parseMarkdown = (input, options = {})=>{
4
+ const parseMarkdown = async (input, options = {})=>{
5
+ // Dynamic import for marked (ES module)
6
+ const { marked } = await import('marked');
6
7
  let markdownContent;
7
8
  if (typeof input === 'string') {
8
9
  markdownContent = input;
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","sources":["../../src/parse/markdown.ts"],"sourcesContent":["import { marked } from 'marked';\nimport { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseMarkdown = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let markdownContent;\n if (typeof input === 'string') {\n markdownContent = input;\n } else {\n markdownContent = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Use marked.lexer to get tokens without full parsing/rendering\n const tokens = marked.lexer(markdownContent);\n\n // Create the main section (with a Title from the options)\n const mainSection = createSection<T>(sectionOptions);\n\n // Track sections at each depth level\n const sectionStack: Section<T>[] = [mainSection];\n\n // Set if we've seen the first token\n let isFirstToken = true;\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n for (const token of tokens) {\n switch (token.type) {\n case 'heading': {\n const depth = token.depth;\n\n // If this is the first token and it's a heading, use it as the main section title\n if (isFirstToken) {\n mainSection.title = token.text;\n isFirstToken = false;\n break;\n }\n\n isFirstToken = false;\n\n // Create a new section with this heading\n const newSection = createSection<T>({ ...sectionOptions, title: token.text });\n\n // Ensure the section stack has the right size based on this heading's depth\n // (e.g., a depth-2 heading should be added to the depth-1 section)\n // We need to ensure the stack length is exactly depth, not just less than or equal to depth\n while (sectionStack.length > depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Make sure we're at the right level for this heading\n // If we stay at the same heading level (e.g., two h2s in sequence),\n // we need to pop once more to get to the parent level\n if (sectionStack.length === depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Add new section to its parent\n const parentSection = sectionStack[sectionStack.length - 1];\n parentSection.add(newSection, itemOptions);\n\n // Push this section onto the stack\n sectionStack.push(newSection);\n break;\n }\n\n case 'paragraph': {\n isFirstToken = false;\n const instruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(instruction, itemOptions);\n break;\n }\n\n case 'list': {\n isFirstToken = false;\n // Convert list items to instructions\n const listInstructionContent = token.items.map((item: any) => `- ${item.text}`).join('\\n');\n const listInstruction: T = createWeighted<T>(listInstructionContent, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(listInstruction, itemOptions);\n break;\n }\n\n case 'code': {\n isFirstToken = false;\n // Represent code blocks as instructions\n const codeInstruction: T = createWeighted<T>(`\\`\\`\\`${token.lang || ''}\\n${token.text}\\n\\`\\`\\``, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(codeInstruction, itemOptions);\n break;\n }\n\n case 'space':\n // Usually ignore space tokens between block elements\n break;\n\n default: {\n isFirstToken = false;\n // Treat other block tokens' text as instructions for robustness\n if ('text' in token && token.text) {\n const fallbackInstruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(fallbackInstruction, itemOptions);\n }\n break;\n }\n }\n }\n return mainSection;\n}\n"],"names":["parseMarkdown","input","options","markdownContent","toString","sectionOptions","SectionOptionsSchema","parse","tokens","marked","lexer","mainSection","createSection","sectionStack","isFirstToken","itemOptions","WeightedOptionsSchema","weight","itemWeight","token","type","depth","title","text","newSection","length","pop","parentSection","add","push","instruction","createWeighted","currentSection","listInstructionContent","items","map","item","join","listInstruction","codeInstruction","lang","fallbackInstruction"],"mappings":";;;;MAIaA,aAAAA,GAAgB,CACzBC,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MAAMyB,kBAAqBR,QAAAA,CAAkB,CAAC,MAAM,EAAEZ,MAAMqB,IAAI,IAAI,EAAA,CAAG,EAAE,EAAErB,KAAAA,CAAMI,IAAI,CAAC,QAAQ,CAAC,EAAER,WAAAA,CAAAA;AACjG,oBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAAA,CAAaY,MAAM,GAAG,CAAA,CAAE;oBAC5DO,cAAAA,CAAeJ,GAAG,CAACW,eAAAA,EAAiBxB,WAAAA,CAAAA;AACpC,oBAAA;AACJ;YAEA,KAAK,OAAA;AAED,gBAAA;AAEJ,YAAA;AAAS,gBAAA;oBACLD,YAAAA,GAAe,KAAA;;AAEf,oBAAA,IAAI,MAAA,IAAUK,KAAAA,IAASA,KAAAA,CAAMI,IAAI,EAAE;AAC/B,wBAAA,MAAMkB,mBAAAA,GAAyBV,QAAAA,CAAkBZ,KAAAA,CAAMI,IAAI,EAAER,WAAAA,CAAAA;AAC7D,wBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAAA,CAAaY,MAAM,GAAG,CAAA,CAAE;wBAC5DO,cAAAA,CAAeJ,GAAG,CAACa,mBAAAA,EAAqB1B,WAAAA,CAAAA;AAC5C;AACA,oBAAA;AACJ;AACJ;AACJ;IACA,OAAOJ,WAAAA;AACX;;;;"}
1
+ {"version":3,"file":"markdown.js","sources":["../../src/parse/markdown.ts"],"sourcesContent":["import { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseMarkdown = async <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Promise<Section<T>> => {\n\n // Dynamic import for marked (ES module)\n const { marked } = await import('marked');\n\n let markdownContent;\n if (typeof input === 'string') {\n markdownContent = input;\n } else {\n markdownContent = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Use marked.lexer to get tokens without full parsing/rendering\n const tokens = marked.lexer(markdownContent);\n\n // Create the main section (with a Title from the options)\n const mainSection = createSection<T>(sectionOptions);\n\n // Track sections at each depth level\n const sectionStack: Section<T>[] = [mainSection];\n\n // Set if we've seen the first token\n let isFirstToken = true;\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n for (const token of tokens) {\n switch (token.type) {\n case 'heading': {\n const depth = token.depth;\n\n // If this is the first token and it's a heading, use it as the main section title\n if (isFirstToken) {\n mainSection.title = token.text;\n isFirstToken = false;\n break;\n }\n\n isFirstToken = false;\n\n // Create a new section with this heading\n const newSection = createSection<T>({ ...sectionOptions, title: token.text });\n\n // Ensure the section stack has the right size based on this heading's depth\n // (e.g., a depth-2 heading should be added to the depth-1 section)\n // We need to ensure the stack length is exactly depth, not just less than or equal to depth\n while (sectionStack.length > depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Make sure we're at the right level for this heading\n // If we stay at the same heading level (e.g., two h2s in sequence),\n // we need to pop once more to get to the parent level\n if (sectionStack.length === depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Add new section to its parent\n const parentSection = sectionStack[sectionStack.length - 1];\n parentSection.add(newSection, itemOptions);\n\n // Push this section onto the stack\n sectionStack.push(newSection);\n break;\n }\n\n case 'paragraph': {\n isFirstToken = false;\n const instruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(instruction, itemOptions);\n break;\n }\n\n case 'list': {\n isFirstToken = false;\n // Convert list items to instructions\n const listInstructionContent = token.items.map((item: any) => `- ${item.text}`).join('\\n');\n const listInstruction: T = createWeighted<T>(listInstructionContent, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(listInstruction, itemOptions);\n break;\n }\n\n case 'code': {\n isFirstToken = false;\n // Represent code blocks as instructions\n const codeInstruction: T = createWeighted<T>(`\\`\\`\\`${token.lang || ''}\\n${token.text}\\n\\`\\`\\``, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(codeInstruction, itemOptions);\n break;\n }\n\n case 'space':\n // Usually ignore space tokens between block elements\n break;\n\n default: {\n isFirstToken = false;\n // Treat other block tokens' text as instructions for robustness\n if ('text' in token && token.text) {\n const fallbackInstruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(fallbackInstruction, itemOptions);\n }\n break;\n }\n }\n }\n return mainSection;\n}\n"],"names":["parseMarkdown","input","options","marked","markdownContent","toString","sectionOptions","SectionOptionsSchema","parse","tokens","lexer","mainSection","createSection","sectionStack","isFirstToken","itemOptions","WeightedOptionsSchema","weight","itemWeight","token","type","depth","title","text","newSection","length","pop","parentSection","add","push","instruction","createWeighted","currentSection","listInstructionContent","items","map","item","join","listInstruction","codeInstruction","lang","fallbackInstruction"],"mappings":";;;MAGaA,aAAAA,GAAgB,OACzBC,KAAAA,EACAC,OAAAA,GAAmC,EAAE,GAAA;;AAIrC,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAM,OAAO,QAAA,CAAA;IAEhC,IAAIC,eAAAA;IACJ,IAAI,OAAOH,UAAU,QAAA,EAAU;QAC3BG,eAAAA,GAAkBH,KAAAA;IACtB,CAAA,MAAO;AACHG,QAAAA,eAAAA,GAAkBH,MAAMI,QAAQ,EAAA;AACpC,IAAA;IAEA,MAAMC,cAAAA,GAAiBC,oBAAAA,CAAqBC,KAAK,CAACN,OAAAA,CAAAA;;IAGlD,MAAMO,MAAAA,GAASN,MAAAA,CAAOO,KAAK,CAACN,eAAAA,CAAAA;;AAG5B,IAAA,MAAMO,cAAcC,MAAAA,CAAiBN,cAAAA,CAAAA;;AAGrC,IAAA,MAAMO,YAAAA,GAA6B;AAACF,QAAAA;AAAY,KAAA;;AAGhD,IAAA,IAAIG,YAAAA,GAAe,IAAA;;IAGnB,MAAMC,WAAAA,GAAcC,qBAAAA,CAAsBR,KAAK,CAAC;AAC5C,QAAA,GA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AAAA,CAAkBZ,KAAAA,CAAMI,IAAI,EAAER,WAAAA,CAAAA;AAC7D,wBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAAA,CAAaY,MAAM,GAAG,CAAA,CAAE;wBAC5DO,cAAAA,CAAeJ,GAAG,CAACa,mBAAAA,EAAqB1B,WAAAA,CAAAA;AAC5C,oBAAA;AACA,oBAAA;AACJ,gBAAA;AACJ;AACJ,IAAA;IACA,OAAOJ,WAAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","sources":["../../src/parse/text.ts"],"sourcesContent":["import { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseText = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let text;\n if (typeof input === 'string') {\n text = input;\n } else {\n text = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n // Split the text on newlines\n const lines = text.split(/\\r?\\n/).filter(line => line.trim().length > 0);\n\n // Create the main section with the supplied title\n const mainSection = createSection<T>(sectionOptions);\n\n for (const line of lines) {\n const instruction: T = createWeighted<T>(line, itemOptions);\n mainSection.add(instruction, itemOptions);\n }\n\n return mainSection;\n}\n"],"names":["parseText","input","options","text","toString","sectionOptions","SectionOptionsSchema","parse","itemOptions","WeightedOptionsSchema","weight","itemWeight","lines","split","filter","line","trim","length","mainSection","createSection","instruction","createWeighted","add"],"mappings":";;;MAGaA,SAAAA,GAAY,CACrBC,KAAAA,EACAC,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,IAAAA;IACJ,IAAI,OAAOF,UAAU,QAAA,EAAU;QAC3BE,IAAAA,GAAOF,KAAAA;KACX,MAAO;AACHE,QAAAA,IAAAA,GAAOF,MAAMG,QAAQ,EAAA;AACzB;IAEA,MAAMC,cAAAA,GAAiBC,oBAAAA,CAAqBC,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,WAAAA,GAAcC,qBAAAA,CAAsBF,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBK,QAAAA,MAAAA,EAAQL,eAAeM;AAC3B,KAAA,CAAA;;AAGA,IAAA,MAAMC,KAAAA,GAAQT,IAAAA,CAAKU,KAAK,CAAC,OAAA,CAAA,CAASC,MAAM,CAACC,CAAAA,IAAAA,GAAQA,IAAAA,CAAKC,IAAI,EAAA,CAAGC,MAAM,GAAG,CAAA,CAAA;;AAGtE,IAAA,MAAMC,cAAcC,MAAAA,CAAiBd,cAAAA,CAAAA;IAErC,KAAK,MAAMU,QAAQH,KAAAA,CAAO;QACtB,MAAMQ,WAAAA,GAAiBC,SAAkBN,IAAAA,EAAMP,WAAAA,CAAAA;QAC/CU,WAAAA,CAAYI,GAAG,CAACF,WAAAA,EAAaZ,WAAAA,CAAAA;AACjC;IAEA,OAAOU,WAAAA;AACX;;;;"}
1
+ {"version":3,"file":"text.js","sources":["../../src/parse/text.ts"],"sourcesContent":["import { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseText = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let text;\n if (typeof input === 'string') {\n text = input;\n } else {\n text = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n // Split the text on newlines\n const lines = text.split(/\\r?\\n/).filter(line => line.trim().length > 0);\n\n // Create the main section with the supplied title\n const mainSection = createSection<T>(sectionOptions);\n\n for (const line of lines) {\n const instruction: T = createWeighted<T>(line, itemOptions);\n mainSection.add(instruction, itemOptions);\n }\n\n return mainSection;\n}\n"],"names":["parseText","input","options","text","toString","sectionOptions","SectionOptionsSchema","parse","itemOptions","WeightedOptionsSchema","weight","itemWeight","lines","split","filter","line","trim","length","mainSection","createSection","instruction","createWeighted","add"],"mappings":";;;MAGaA,SAAAA,GAAY,CACrBC,KAAAA,EACAC,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,IAAAA;IACJ,IAAI,OAAOF,UAAU,QAAA,EAAU;QAC3BE,IAAAA,GAAOF,KAAAA;IACX,CAAA,MAAO;AACHE,QAAAA,IAAAA,GAAOF,MAAMG,QAAQ,EAAA;AACzB,IAAA;IAEA,MAAMC,cAAAA,GAAiBC,oBAAAA,CAAqBC,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,WAAAA,GAAcC,qBAAAA,CAAsBF,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBK,QAAAA,MAAAA,EAAQL,eAAeM;AAC3B,KAAA,CAAA;;AAGA,IAAA,MAAMC,KAAAA,GAAQT,IAAAA,CAAKU,KAAK,CAAC,OAAA,CAAA,CAASC,MAAM,CAACC,CAAAA,IAAAA,GAAQA,IAAAA,CAAKC,IAAI,EAAA,CAAGC,MAAM,GAAG,CAAA,CAAA;;AAGtE,IAAA,MAAMC,cAAcC,MAAAA,CAAiBd,cAAAA,CAAAA;IAErC,KAAK,MAAMU,QAAQH,KAAAA,CAAO;QACtB,MAAMQ,WAAAA,GAAiBC,SAAkBN,IAAAA,EAAMP,WAAAA,CAAAA;QAC/CU,WAAAA,CAAYI,GAAG,CAACF,WAAAA,EAAaZ,WAAAA,CAAAA;AACjC,IAAA;IAEA,OAAOU,WAAAA;AACX;;;;"}
package/dist/parser.d.ts CHANGED
@@ -14,7 +14,7 @@ declare const OptionsSchema: z.ZodObject<{
14
14
  export type Options = z.infer<typeof OptionsSchema>;
15
15
  export type OptionsParam = Partial<Options>;
16
16
  export interface Instance {
17
- parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Section<T>;
17
+ parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Promise<Section<T>>;
18
18
  parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;
19
19
  }
20
20
  export declare const create: (parserOptions?: OptionsParam) => Instance;
package/dist/parser.js CHANGED
@@ -33,7 +33,7 @@ const create = (parserOptions)=>{
33
33
  const content = await fs.readFile(filePath, 'utf-8');
34
34
  // Only use the filename as title if no title was explicitly provided
35
35
  const fileName = path.basename(filePath, path.extname(filePath));
36
- return parse(content, {
36
+ return await parse(content, {
37
37
  ...currentOptions,
38
38
  title: (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.title) || fileName
39
39
  });
@@ -53,11 +53,11 @@ const create = (parserOptions)=>{
53
53
  *
54
54
  * @param content The content to parse
55
55
  * @returns A Section containing all content in a hierarchical structure
56
- */ const parse = (content, options = {})=>{
56
+ */ const parse = async (content, options = {})=>{
57
57
  const currentOptions = loadOptions(options);
58
58
  let mainSection;
59
59
  if (isMarkdown(content)) {
60
- mainSection = parseMarkdown(content, currentOptions);
60
+ mainSection = await parseMarkdown(content, currentOptions);
61
61
  } else if (isText(content)) {
62
62
  mainSection = parseText(content, currentOptions);
63
63
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sources":["../src/parser.ts"],"sourcesContent":["import * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { Section, SectionOptions, SectionOptionsSchema } from './items/section';\nimport { Weighted } from './items/weighted';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { parseMarkdown } from './parse/markdown';\nimport { parseText } from './parse/text';\nimport { isMarkdown } from './util/markdown';\nimport { isText } from './util/text';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Section<T>;\n parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;\n}\n\nexport const create = (parserOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(parserOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Parser');\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const parseFile = async <T extends Weighted>(\n filePath: string,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n // Only use the filename as title if no title was explicitly provided\n const fileName = path.basename(filePath, path.extname(filePath));\n return parse(content, {\n ...currentOptions,\n title: currentOptions?.title || fileName\n });\n } catch (error) {\n // Log the error or handle it appropriately\n logger.error(`Error reading or parsing file with marked at ${filePath}:`, error);\n throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Reads Markdown content and parses it into a single Section.\n * \n * - If the content starts with a heading, that becomes the title of the returned Section\n * - If no heading at the start, creates a Section with no title\n * - Headers within the content create nested sections based on their depth\n * - All content is organized in a hierarchical structure based on heading levels\n *\n * @param content The content to parse\n * @returns A Section containing all content in a hierarchical structure\n */\n const parse = <T extends Weighted>(\n content: string | Buffer,\n options: Partial<SectionOptions> = {}\n ): Section<T> => {\n const currentOptions = loadOptions(options);\n\n let mainSection: Section<T>;\n if (isMarkdown(content)) {\n mainSection = parseMarkdown<T>(content, currentOptions);\n } else if (isText(content)) {\n mainSection = parseText<T>(content, currentOptions);\n } else {\n throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);\n }\n return mainSection;\n }\n\n return {\n parse,\n parseFile\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","parameters","ParametersSchema","create","parserOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","parseFile","filePath","content","fs","readFile","fileName","path","basename","extname","title","error","Error","message","String","mainSection","isMarkdown","parseMarkdown","isText","parseText"],"mappings":";;;;;;;;;;;AAYA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBJ,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAWO,MAAMI,SAAS,CAACC,aAAAA,GAAAA;AACnB,IAAA,MAAMC,OAAAA,GAA6BZ,aAAAA,CAAca,KAAK,CAACF,iBAAiB,EAAC,CAAA;IACzE,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAML,MAAAA,GAASW,UAAAA,CAAWF,OAAAA,CAAQT,MAAM,EAAE,QAAA,CAAA;AAE1C,IAAA,MAAMY,WAAAA,GAAc,CAACC,cAAAA,GAA0C,EAAE,GAAA;QAC7D,MAAMC,cAAAA,GAAiBC,oBAAAA,CAAqBL,KAAK,CAACG,cAAAA,CAAAA;QAClD,OAAO;AACH,YAAA,GAAGC,cAAc;YACjBT,UAAAA,EAAY;AACR,gBAAA,GAAGA,UAAU;AACb,gBAAA,GAAGS,eAAeT;AACtB;AACJ,SAAA;AACJ,KAAA;AAEA,IAAA,MAAMW,SAAAA,GAAY,OACdC,QAAAA,EACAR,OAAAA,GAAmC,EAAE,GAAA;AAErC,QAAA,MAAMK,iBAAiBF,WAAAA,CAAYH,OAAAA,CAAAA;QACnC,IAAI;AACA,YAAA,MAAMS,OAAAA,GAAU,MAAMC,EAAAA,CAAGC,QAAQ,CAACH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WAAAA;AACX,KAAA;IAEA,OAAO;AACHpB,QAAAA,KAAAA;AACAM,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"parser.js","sources":["../src/parser.ts"],"sourcesContent":["import * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { Section, SectionOptions, SectionOptionsSchema } from './items/section';\nimport { Weighted } from './items/weighted';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { parseMarkdown } from './parse/markdown';\nimport { parseText } from './parse/text';\nimport { isMarkdown } from './util/markdown';\nimport { isText } from './util/text';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Promise<Section<T>>;\n parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;\n}\n\nexport const create = (parserOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(parserOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Parser');\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const parseFile = async <T extends Weighted>(\n filePath: string,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n // Only use the filename as title if no title was explicitly provided\n const fileName = path.basename(filePath, path.extname(filePath));\n return await parse(content, {\n ...currentOptions,\n title: currentOptions?.title || fileName\n });\n } catch (error) {\n // Log the error or handle it appropriately\n logger.error(`Error reading or parsing file with marked at ${filePath}:`, error);\n throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Reads Markdown content and parses it into a single Section.\n * \n * - If the content starts with a heading, that becomes the title of the returned Section\n * - If no heading at the start, creates a Section with no title\n * - Headers within the content create nested sections based on their depth\n * - All content is organized in a hierarchical structure based on heading levels\n *\n * @param content The content to parse\n * @returns A Section containing all content in a hierarchical structure\n */\n const parse = async <T extends Weighted>(\n content: string | Buffer,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n\n let mainSection: Section<T>;\n if (isMarkdown(content)) {\n mainSection = await parseMarkdown<T>(content, currentOptions);\n } else if (isText(content)) {\n mainSection = parseText<T>(content, currentOptions);\n } else {\n throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);\n }\n return mainSection;\n }\n\n return {\n parse,\n parseFile\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","parameters","ParametersSchema","create","parserOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","parseFile","filePath","content","fs","readFile","fileName","path","basename","extname","title","error","Error","message","String","mainSection","isMarkdown","parseMarkdown","isText","parseText"],"mappings":";;;;;;;;;;;AAYA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBJ,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAWO,MAAMI,SAAS,CAACC,aAAAA,GAAAA;AACnB,IAAA,MAAMC,OAAAA,GAA6BZ,aAAAA,CAAca,KAAK,CAACF,iBAAiB,EAAC,CAAA;IACzE,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IA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CAAME,OAAO,GAAGC,OAAOH,KAAAA,CAAAA,CAAAA,CAAQ,CAAA;AAC9H,QAAA;AACJ,IAAA,CAAA;AAEA;;;;;;;;;;AAUC,QACD,MAAMhB,KAAAA,GAAQ,OACVQ,OAAAA,EACAT,OAAAA,GAAmC,EAAE,GAAA;AAErC,QAAA,MAAMK,iBAAiBF,WAAAA,CAAYH,OAAAA,CAAAA;QAEnC,IAAIqB,WAAAA;AACJ,QAAA,IAAIC,WAAWb,OAAAA,CAAAA,EAAU;YACrBY,WAAAA,GAAc,MAAME,cAAiBd,OAAAA,EAASJ,cAAAA,CAAAA;QAClD,CAAA,MAAO,IAAImB,OAAOf,OAAAA,CAAAA,EAAU;AACxBY,YAAAA,WAAAA,GAAcI,UAAahB,OAAAA,EAASJ,cAAAA,CAAAA;QACxC,CAAA,MAAO;AACH,YAAA,MAAM,IAAIa,KAAAA,CAAM,CAAC,2FAA2F,CAAC,CAAA;AACjH,QAAA;QACA,OAAOG,WAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACHpB,QAAAA,KAAAA;AACAM,QAAAA;AACJ,KAAA;AACJ;;;;"}
package/dist/recipes.d.ts CHANGED
@@ -192,7 +192,7 @@ declare const RecipeConfigSchema: z.ZodObject<{
192
192
  title?: string | undefined;
193
193
  }>]>, "many">>>;
194
194
  extends: z.ZodOptional<z.ZodString>;
195
- template: z.ZodOptional<z.ZodEnum<["commit", "release", "documentation", "review", "custom"]>>;
195
+ template: z.ZodOptional<z.ZodString>;
196
196
  }, "strip", z.ZodTypeAny, {
197
197
  parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
198
198
  instructions: (string | {
@@ -252,7 +252,7 @@ declare const RecipeConfigSchema: z.ZodObject<{
252
252
  } | undefined;
253
253
  logger?: any;
254
254
  extends?: string | undefined;
255
- template?: "custom" | "commit" | "release" | "documentation" | "review" | undefined;
255
+ template?: string | undefined;
256
256
  }, {
257
257
  basePath: string;
258
258
  parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
@@ -312,7 +312,7 @@ declare const RecipeConfigSchema: z.ZodObject<{
312
312
  title?: string | undefined;
313
313
  })[] | undefined;
314
314
  extends?: string | undefined;
315
- template?: "custom" | "commit" | "release" | "documentation" | "review" | undefined;
315
+ template?: string | undefined;
316
316
  }>;
317
317
  type RecipeConfig = z.infer<typeof RecipeConfigSchema>;
318
318
  type ContentItem = z.infer<typeof ContentItemSchema>;
@@ -323,83 +323,45 @@ export interface TemplateConfig {
323
323
  context?: ContentItem[];
324
324
  }
325
325
  /**
326
- * Configure custom template paths (perfect for KodrDriv constants!)
326
+ * Register custom templates with the recipes system
327
327
  *
328
328
  * @example
329
329
  * ```typescript
330
- * // Configure using your KodrDriv constants
331
- * configureTemplates({
332
- * commit: {
333
- * persona: { path: DEFAULT_PERSONA_YOU_FILE },
334
- * instructions: [{ path: DEFAULT_INSTRUCTIONS_COMMIT_FILE }]
330
+ * // Register your own templates
331
+ * registerTemplates({
332
+ * myWorkflow: {
333
+ * persona: { path: "personas/my-persona.md" },
334
+ * instructions: [{ path: "instructions/my-instructions.md" }]
335
335
  * },
336
- * release: {
337
- * persona: { path: DEFAULT_PERSONA_RELEASER_FILE },
338
- * instructions: [{ path: DEFAULT_INSTRUCTIONS_RELEASE_FILE }]
336
+ * anotherTemplate: {
337
+ * persona: { content: "You are a helpful assistant" },
338
+ * instructions: [{ content: "Follow these steps..." }]
339
339
  * }
340
340
  * });
341
341
  * ```
342
342
  */
343
- export declare const configureTemplates: (customTemplates: Record<string, TemplateConfig>) => void;
343
+ export declare const registerTemplates: (templates: Record<string, TemplateConfig>) => void;
344
344
  /**
345
- * Get current template configuration
345
+ * Get currently registered templates
346
346
  */
347
347
  export declare const getTemplates: () => Record<string, TemplateConfig>;
348
+ /**
349
+ * Clear all registered templates
350
+ */
351
+ export declare const clearTemplates: () => void;
348
352
  export declare const cook: (config: Partial<RecipeConfig> & {
349
353
  basePath: string;
350
354
  }) => Promise<Prompt>;
351
- export declare const commit: (config: Partial<RecipeConfig> & {
352
- basePath: string;
353
- }) => Promise<Prompt>;
354
- export declare const release: (config: Partial<RecipeConfig> & {
355
- basePath: string;
356
- }) => Promise<Prompt>;
357
- export declare const documentation: (config: Partial<RecipeConfig> & {
358
- basePath: string;
359
- }) => Promise<Prompt>;
360
- export declare const review: (config: Partial<RecipeConfig> & {
361
- basePath: string;
362
- }) => Promise<Prompt>;
363
- export declare const quick: {
364
- /**
365
- * Create a commit prompt with minimal configuration
366
- */
367
- commit: (diffContent: string, options: {
368
- basePath: string;
369
- overridePaths?: string[];
370
- overrides?: boolean;
371
- userDirection?: string;
372
- context?: string;
373
- directories?: string[];
374
- }) => Promise<Prompt>;
375
- /**
376
- * Create a release prompt with minimal configuration
377
- */
378
- release: (logContent: string, diffContent: string, options: {
379
- basePath: string;
380
- overridePaths?: string[];
381
- overrides?: boolean;
382
- releaseFocus?: string;
383
- context?: string;
384
- directories?: string[];
385
- }) => Promise<Prompt>;
386
- };
387
355
  export declare const recipe: (basePath: string) => {
388
- template: (name: "commit" | "release" | "documentation" | "review") => {
389
- with: (config: Partial<RecipeConfig>) => Promise<Prompt>;
390
- };
391
- persona: (persona: ContentItem) => {
392
- instructions: (...instructions: ContentItem[]) => {
393
- content: (...content: ContentItem[]) => {
394
- context: (...context: ContentItem[]) => {
395
- cook: () => Promise<Prompt>;
396
- };
397
- cook: () => Promise<Prompt>;
398
- };
399
- cook: () => Promise<Prompt>;
400
- };
401
- cook: () => Promise<Prompt>;
402
- };
403
- cook: (config: Partial<RecipeConfig>) => Promise<Prompt>;
356
+ template: (name: string) => /*elided*/ any;
357
+ with: (partialConfig: Partial<RecipeConfig>) => /*elided*/ any;
358
+ persona: (persona: ContentItem) => /*elided*/ any;
359
+ instructions: (...instructions: ContentItem[]) => /*elided*/ any;
360
+ content: (...content: ContentItem[]) => /*elided*/ any;
361
+ context: (...context: ContentItem[]) => /*elided*/ any;
362
+ parameters: (parameters: any) => /*elided*/ any;
363
+ overrides: (enabled: boolean) => /*elided*/ any;
364
+ overridePaths: (paths: string[]) => /*elided*/ any;
365
+ cook: () => Promise<Prompt>;
404
366
  };
405
367
  export type { RecipeConfig, ContentItem };