@riotprompt/riotprompt 0.0.1 → 0.0.3

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.
Files changed (93) hide show
  1. package/README.md +54 -470
  2. package/dist/builder.d.ts +3 -3
  3. package/dist/builder.js +7 -2
  4. package/dist/builder.js.map +1 -1
  5. package/dist/chat.js.map +1 -1
  6. package/dist/constants.js.map +1 -1
  7. package/dist/formatter.js.map +1 -1
  8. package/dist/items/content.js.map +1 -1
  9. package/dist/items/context.js.map +1 -1
  10. package/dist/items/instruction.js.map +1 -1
  11. package/dist/items/parameters.js.map +1 -1
  12. package/dist/items/section.js.map +1 -1
  13. package/dist/items/trait.js.map +1 -1
  14. package/dist/items/weighted.js.map +1 -1
  15. package/dist/loader.js +1 -0
  16. package/dist/loader.js.map +1 -1
  17. package/dist/logger.js +4 -2
  18. package/dist/logger.js.map +1 -1
  19. package/dist/override.d.ts +5 -5
  20. package/dist/override.js +47 -30
  21. package/dist/override.js.map +1 -1
  22. package/dist/parse/markdown.js.map +1 -1
  23. package/dist/parse/text.js.map +1 -1
  24. package/dist/parser.js.map +1 -1
  25. package/dist/prompt.js.map +1 -1
  26. package/dist/recipes.d.ts +405 -0
  27. package/dist/recipes.js +424 -0
  28. package/dist/recipes.js.map +1 -0
  29. package/dist/riotprompt.cjs +586 -132
  30. package/dist/riotprompt.cjs.map +1 -1
  31. package/dist/riotprompt.d.ts +3 -0
  32. package/dist/riotprompt.js +3 -0
  33. package/dist/riotprompt.js.map +1 -1
  34. package/dist/util/general.js.map +1 -1
  35. package/dist/util/markdown.js.map +1 -1
  36. package/dist/util/storage.js.map +1 -1
  37. package/dist/util/text.js.map +1 -1
  38. package/package.json +35 -28
  39. package/.gitcarve/config.yaml +0 -10
  40. package/.gitcarve/context/content.md +0 -11
  41. package/.markdown-doctest-setup.mjs +0 -23
  42. package/.nvmrc +0 -1
  43. package/dist/builder.cjs +0 -152
  44. package/dist/builder.cjs.map +0 -1
  45. package/dist/chat.cjs +0 -26
  46. package/dist/chat.cjs.map +0 -1
  47. package/dist/constants.cjs +0 -34
  48. package/dist/constants.cjs.map +0 -1
  49. package/dist/formatter.cjs +0 -139
  50. package/dist/formatter.cjs.map +0 -1
  51. package/dist/items/content.cjs +0 -14
  52. package/dist/items/content.cjs.map +0 -1
  53. package/dist/items/context.cjs +0 -13
  54. package/dist/items/context.cjs.map +0 -1
  55. package/dist/items/instruction.cjs +0 -13
  56. package/dist/items/instruction.cjs.map +0 -1
  57. package/dist/items/parameters.cjs +0 -53
  58. package/dist/items/parameters.cjs.map +0 -1
  59. package/dist/items/section.cjs +0 -120
  60. package/dist/items/section.cjs.map +0 -1
  61. package/dist/items/trait.cjs +0 -13
  62. package/dist/items/trait.cjs.map +0 -1
  63. package/dist/items/weighted.cjs +0 -27
  64. package/dist/items/weighted.cjs.map +0 -1
  65. package/dist/loader.cjs +0 -167
  66. package/dist/loader.cjs.map +0 -1
  67. package/dist/logger.cjs +0 -51
  68. package/dist/logger.cjs.map +0 -1
  69. package/dist/override.cjs +0 -109
  70. package/dist/override.cjs.map +0 -1
  71. package/dist/parse/markdown.cjs +0 -114
  72. package/dist/parse/markdown.cjs.map +0 -1
  73. package/dist/parse/text.cjs +0 -33
  74. package/dist/parse/text.cjs.map +0 -1
  75. package/dist/parser.cjs +0 -99
  76. package/dist/parser.cjs.map +0 -1
  77. package/dist/prompt.cjs +0 -15
  78. package/dist/prompt.cjs.map +0 -1
  79. package/dist/util/general.cjs +0 -52
  80. package/dist/util/general.cjs.map +0 -1
  81. package/dist/util/markdown.cjs +0 -115
  82. package/dist/util/markdown.cjs.map +0 -1
  83. package/dist/util/storage.cjs +0 -155
  84. package/dist/util/storage.cjs.map +0 -1
  85. package/dist/util/text.cjs +0 -42
  86. package/dist/util/text.cjs.map +0 -1
  87. package/docs/loader.md +0 -237
  88. package/docs/override.md +0 -323
  89. package/docs/parser.md +0 -130
  90. package/eslint.config.mjs +0 -82
  91. package/nodemon.json +0 -14
  92. package/vite.config.ts +0 -114
  93. package/vitest.config.ts +0 -25
@@ -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 configDir: 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>, prepend?: Section<T>, append?: 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>, prepend?: Section<T>, append?: Section<T> }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const baseFile = path.join(options.configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n const response: { override?: Section<T>, prepend?: Section<T>, append?: Section<T> } = {};\n\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s', preFile);\n const parser = Parser.create({ logger });\n response.prepend = await parser.parseFile<T>(preFile, currentSectionOptions);\n }\n\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s', postFile);\n const parser = Parser.create({ logger });\n response.append = await parser.parseFile<T>(postFile, currentSectionOptions);\n }\n\n if (await storage.exists(baseFile)) {\n logger.silly('Found base file %s', baseFile);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration');\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 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 { overrideContent, prepend, append }: { overrideContent?: Section<T>, prepend?: Section<T>, append?: 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 if (prepend) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n if (append) {\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","configDir","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","baseFile","path","join","preFile","replace","postFile","response","exists","silly","parser","Parser","prepend","parseFile","append","warn","error","Error","customize","overrideContent","finalSection","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,SAAAA,EAAWP,CAAEQ,CAAAA,MAAM,EAAGH,CAAAA,OAAO,CAAC,aAAA,CAAA;AAC9BI,IAAAA,SAAAA,EAAWT,CAAEU,CAAAA,OAAO,EAAGL,CAAAA,OAAO,CAAC,KAAA,CAAA;AAC/BM,IAAAA,UAAAA,EAAYC,gBAAiBR,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAYaQ,MAAAA,MAAAA,GAAS,CAACC,eAAAA,GAAgC,EAAE,GAAA;IACrD,MAAMC,OAAAA,GAA6BhB,aAAciB,CAAAA,KAAK,CAACF,eAAAA,CAAAA;IAEvD,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAMT,SAASe,UAAWF,CAAAA,OAAAA,KAAAA,IAAAA,IAAAA,OAAAA,KAAAA,MAAAA,GAAAA,MAAAA,GAAAA,OAAAA,CAASb,MAAM,EAAE,UAAA,CAAA;IAC3C,MAAMgB,OAAAA,GAAUC,QAAc,CAAC;AAAEC,QAAAA,GAAAA,EAAKlB,OAAOmB;AAAM,KAAA,CAAA;AAEnD,IAAA,MAAMC,WAAc,GAAA,CAACC,cAA0C,GAAA,EAAE,GAAA;QAC7D,MAAMC,cAAAA,GAAiBC,oBAAqBT,CAAAA,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J;AAEA,QAAA,IAAIL,OAAS,EAAA;YACTvC,MAAOoC,CAAAA,KAAK,CAAC,+CAAiDG,EAAAA,OAAAA,CAAAA;YAC9DQ,YAAeA,GAAAA,YAAAA,CAAaR,OAAO,CAACA,OAAAA,CAAAA;AACxC;AAEA,QAAA,IAAIE,MAAQ,EAAA;YACRzC,MAAOoC,CAAAA,KAAK,CAAC,8CAAgDK,EAAAA,MAAAA,CAAAA;YAC7DM,YAAeA,GAAAA,YAAAA,CAAaN,MAAM,CAACA,MAAAA,CAAAA;AACvC;QAEA,MAAMO,WAAAA,GAAYC,QAAgB,CAAC;AAAEjD,YAAAA;AAAO,SAAA,CAAA;QAC5CA,MAAOoC,CAAAA,KAAK,CAAC,6BAA+BpC,EAAAA,MAAAA,CAAOkD,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACJ,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,KAAA;IAEA,OAAO;AACHvB,QAAAA,QAAAA;AACAqB,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,MAAM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B,YAAAA,GAA2B3B,OAAAA;AAE/B,QAAA,IAAI0B,eAAAA,EAAiB;YACjB,IAAIvC,OAAAA,CAAQN,SAAS,EAAE;gBACnBR,MAAAA,CAAOiD,IAAI,CAAC,gDAAA,EAAkDI,eAAAA,CAAAA;gBAC9DC,YAAAA,GAAeD,eAAAA;aACnB,MAAO;AACHrD,gBAAAA,MAAAA,CAAOkD,KAAK,CAAC,sEAAA,CAAA;AACb,gBAAA,MAAM,IAAIC,KAAAA,CAAM,+IAAA,CAAA;AACpB;AACJ;;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;;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;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 +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,aAAgB,GAAA,CACzBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,eAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,eAAkBF,GAAAA,KAAAA;KACf,MAAA;AACHE,QAAAA,eAAAA,GAAkBF,MAAMG,QAAQ,EAAA;AACpC;IAEA,MAAMC,cAAAA,GAAiBC,oBAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,MAAAA,GAASC,MAAOC,CAAAA,KAAK,CAACP,eAAAA,CAAAA;;AAG5B,IAAA,MAAMQ,cAAcC,MAAiBP,CAAAA,cAAAA,CAAAA;;AAGrC,IAAA,MAAMQ,YAA6B,GAAA;AAACF,QAAAA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AAMI,CAAAA,IAAI,EAAE;AAC/B,wBAAA,MAAMkB,mBAAyBV,GAAAA,QAAAA,CAAkBZ,KAAMI,CAAAA,IAAI,EAAER,WAAAA,CAAAA;AAC7D,wBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAaY,CAAAA,MAAM,GAAG,CAAE,CAAA;wBAC5DO,cAAeJ,CAAAA,GAAG,CAACa,mBAAqB1B,EAAAA,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 { 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","listInstruct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BAAA;AACJ;YAEA,KAAK,MAAA;AAAQ,gBAAA;oBACTD,YAAAA,GAAe,KAAA;;AAEf,oBAAA,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 +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,SAAY,GAAA,CACrBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,IAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,IAAOF,GAAAA,KAAAA;KACJ,MAAA;AACHE,QAAAA,IAAAA,GAAOF,MAAMG,QAAQ,EAAA;AACzB;IAEA,MAAMC,cAAAA,GAAiBC,oBAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,WAAAA,GAAcC,qBAAsBF,CAAAA,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBK,QAAAA,MAAAA,EAAQL,eAAeM;AAC3B,KAAA,CAAA;;AAGA,IAAA,MAAMC,KAAQT,GAAAA,IAAAA,CAAKU,KAAK,CAAC,OAASC,CAAAA,CAAAA,MAAM,CAACC,CAAAA,IAAQA,GAAAA,IAAAA,CAAKC,IAAI,EAAA,CAAGC,MAAM,GAAG,CAAA,CAAA;;AAGtE,IAAA,MAAMC,cAAcC,MAAiBd,CAAAA,cAAAA,CAAAA;IAErC,KAAK,MAAMU,QAAQH,KAAO,CAAA;QACtB,MAAMQ,WAAAA,GAAiBC,SAAkBN,IAAMP,EAAAA,WAAAA,CAAAA;QAC/CU,WAAYI,CAAAA,GAAG,CAACF,WAAaZ,EAAAA,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;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 +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,CAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,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AA;AACJ,SAAA,CAAE,OAAOK,KAAO,EAAA;;YAEZ1B,MAAO0B,CAAAA,KAAK,CAAC,CAAC,6CAA6C,EAAET,QAAS,CAAA,CAAC,CAAC,EAAES,KAAAA,CAAAA;AAC1E,YAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,kCAAkC,EAAEV,QAAS,CAAA,EAAE,EAAES,KAAAA,YAAiBC,KAAQD,GAAAA,KAAAA,CAAME,OAAO,GAAGC,OAAOH,KAAQ,CAAA,CAAA,CAAA,CAAA;AAC9H;AACJ,KAAA;AAEA;;;;;;;;;;AAUC,QACD,MAAMhB,KAAQ,GAAA,CACVQ,OACAT,EAAAA,OAAAA,GAAmC,EAAE,GAAA;AAErC,QAAA,MAAMK,iBAAiBF,WAAYH,CAAAA,OAAAA,CAAAA;QAEnC,IAAIqB,WAAAA;AACJ,QAAA,IAAIC,WAAWb,OAAU,CAAA,EAAA;AACrBY,YAAAA,WAAAA,GAAcE,cAAiBd,OAASJ,EAAAA,cAAAA,CAAAA;SACrC,MAAA,IAAImB,OAAOf,OAAU,CAAA,EAAA;AACxBY,YAAAA,WAAAA,GAAcI,UAAahB,OAASJ,EAAAA,cAAAA,CAAAA;SACjC,MAAA;AACH,YAAA,MAAM,IAAIa,KAAAA,CAAM,CAAC,2FAA2F,CAAC,CAAA;AACjH;QACA,OAAOG,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) => 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,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Y,YAAAA,WAAAA,GAAcI,UAAahB,OAAAA,EAASJ,cAAAA,CAAAA;SACxC,MAAO;AACH,YAAA,MAAM,IAAIa,KAAAA,CAAM,CAAC,2FAA2F,CAAC,CAAA;AACjH;QACA,OAAOG,WAAAA;AACX,KAAA;IAEA,OAAO;AACHpB,QAAAA,KAAAA;AACAM,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sources":["../src/prompt.ts"],"sourcesContent":["import { Content } from \"./items/content\";\nimport { Context } from \"./items/context\";\nimport { Instruction } from \"./items/instruction\";\nimport { Section } from \"./items/section\";\n\nexport interface Prompt {\n persona?: Section<Instruction>;\n instructions: Section<Instruction>;\n contents?: Section<Content>;\n contexts?: Section<Context>;\n}\n\nexport const create = ({\n persona,\n instructions,\n contents,\n contexts,\n}: {\n persona?: Section<Instruction>,\n instructions: Section<Instruction>,\n contents?: Section<Content>,\n contexts?: Section<Context>\n}): Prompt => {\n\n return {\n persona,\n instructions,\n contents,\n contexts,\n }\n}"],"names":["create","persona","instructions","contents","contexts"],"mappings":"AAYO,MAAMA,MAAS,GAAA,CAAC,EACnBC,OAAO,EACPC,YAAY,EACZC,QAAQ,EACRC,QAAQ,EAMX,GAAA;IAEG,OAAO;AACHH,QAAAA,OAAAA;AACAC,QAAAA,YAAAA;AACAC,QAAAA,QAAAA;AACAC,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"prompt.js","sources":["../src/prompt.ts"],"sourcesContent":["import { Content } from \"./items/content\";\nimport { Context } from \"./items/context\";\nimport { Instruction } from \"./items/instruction\";\nimport { Section } from \"./items/section\";\n\nexport interface Prompt {\n persona?: Section<Instruction>;\n instructions: Section<Instruction>;\n contents?: Section<Content>;\n contexts?: Section<Context>;\n}\n\nexport const create = ({\n persona,\n instructions,\n contents,\n contexts,\n}: {\n persona?: Section<Instruction>,\n instructions: Section<Instruction>,\n contents?: Section<Content>,\n contexts?: Section<Context>\n}): Prompt => {\n\n return {\n persona,\n instructions,\n contents,\n contexts,\n }\n}"],"names":["create","persona","instructions","contents","contexts"],"mappings":"AAYO,MAAMA,MAAAA,GAAS,CAAC,EACnBC,OAAO,EACPC,YAAY,EACZC,QAAQ,EACRC,QAAQ,EAMX,GAAA;IAEG,OAAO;AACHH,QAAAA,OAAAA;AACAC,QAAAA,YAAAA;AACAC,QAAAA,QAAAA;AACAC,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,405 @@
1
+ import { z } from 'zod';
2
+ import { Prompt } from './riotprompt';
3
+ declare const ContentItemSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
4
+ content: z.ZodString;
5
+ title: z.ZodOptional<z.ZodString>;
6
+ weight: z.ZodOptional<z.ZodNumber>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ content: string;
9
+ weight?: number | undefined;
10
+ title?: string | undefined;
11
+ }, {
12
+ content: string;
13
+ weight?: number | undefined;
14
+ title?: string | undefined;
15
+ }>, z.ZodObject<{
16
+ path: z.ZodString;
17
+ title: z.ZodOptional<z.ZodString>;
18
+ weight: z.ZodOptional<z.ZodNumber>;
19
+ }, "strip", z.ZodTypeAny, {
20
+ path: string;
21
+ weight?: number | undefined;
22
+ title?: string | undefined;
23
+ }, {
24
+ path: string;
25
+ weight?: number | undefined;
26
+ title?: string | undefined;
27
+ }>, z.ZodObject<{
28
+ directories: z.ZodArray<z.ZodString, "many">;
29
+ title: z.ZodOptional<z.ZodString>;
30
+ weight: z.ZodOptional<z.ZodNumber>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ directories: string[];
33
+ weight?: number | undefined;
34
+ title?: string | undefined;
35
+ }, {
36
+ directories: string[];
37
+ weight?: number | undefined;
38
+ title?: string | undefined;
39
+ }>]>;
40
+ declare const RecipeConfigSchema: z.ZodObject<{
41
+ basePath: z.ZodString;
42
+ logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
43
+ overridePaths: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
44
+ overrides: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
45
+ parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">]>>>>;
46
+ persona: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
47
+ content: z.ZodString;
48
+ title: z.ZodOptional<z.ZodString>;
49
+ weight: z.ZodOptional<z.ZodNumber>;
50
+ }, "strip", z.ZodTypeAny, {
51
+ content: string;
52
+ weight?: number | undefined;
53
+ title?: string | undefined;
54
+ }, {
55
+ content: string;
56
+ weight?: number | undefined;
57
+ title?: string | undefined;
58
+ }>, z.ZodObject<{
59
+ path: z.ZodString;
60
+ title: z.ZodOptional<z.ZodString>;
61
+ weight: z.ZodOptional<z.ZodNumber>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ path: string;
64
+ weight?: number | undefined;
65
+ title?: string | undefined;
66
+ }, {
67
+ path: string;
68
+ weight?: number | undefined;
69
+ title?: string | undefined;
70
+ }>, z.ZodObject<{
71
+ directories: z.ZodArray<z.ZodString, "many">;
72
+ title: z.ZodOptional<z.ZodString>;
73
+ weight: z.ZodOptional<z.ZodNumber>;
74
+ }, "strip", z.ZodTypeAny, {
75
+ directories: string[];
76
+ weight?: number | undefined;
77
+ title?: string | undefined;
78
+ }, {
79
+ directories: string[];
80
+ weight?: number | undefined;
81
+ title?: string | undefined;
82
+ }>]>>;
83
+ instructions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
84
+ content: z.ZodString;
85
+ title: z.ZodOptional<z.ZodString>;
86
+ weight: z.ZodOptional<z.ZodNumber>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ content: string;
89
+ weight?: number | undefined;
90
+ title?: string | undefined;
91
+ }, {
92
+ content: string;
93
+ weight?: number | undefined;
94
+ title?: string | undefined;
95
+ }>, z.ZodObject<{
96
+ path: z.ZodString;
97
+ title: z.ZodOptional<z.ZodString>;
98
+ weight: z.ZodOptional<z.ZodNumber>;
99
+ }, "strip", z.ZodTypeAny, {
100
+ path: string;
101
+ weight?: number | undefined;
102
+ title?: string | undefined;
103
+ }, {
104
+ path: string;
105
+ weight?: number | undefined;
106
+ title?: string | undefined;
107
+ }>, z.ZodObject<{
108
+ directories: z.ZodArray<z.ZodString, "many">;
109
+ title: z.ZodOptional<z.ZodString>;
110
+ weight: z.ZodOptional<z.ZodNumber>;
111
+ }, "strip", z.ZodTypeAny, {
112
+ directories: string[];
113
+ weight?: number | undefined;
114
+ title?: string | undefined;
115
+ }, {
116
+ directories: string[];
117
+ weight?: number | undefined;
118
+ title?: string | undefined;
119
+ }>]>, "many">>>;
120
+ content: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
121
+ content: z.ZodString;
122
+ title: z.ZodOptional<z.ZodString>;
123
+ weight: z.ZodOptional<z.ZodNumber>;
124
+ }, "strip", z.ZodTypeAny, {
125
+ content: string;
126
+ weight?: number | undefined;
127
+ title?: string | undefined;
128
+ }, {
129
+ content: string;
130
+ weight?: number | undefined;
131
+ title?: string | undefined;
132
+ }>, z.ZodObject<{
133
+ path: z.ZodString;
134
+ title: z.ZodOptional<z.ZodString>;
135
+ weight: z.ZodOptional<z.ZodNumber>;
136
+ }, "strip", z.ZodTypeAny, {
137
+ path: string;
138
+ weight?: number | undefined;
139
+ title?: string | undefined;
140
+ }, {
141
+ path: string;
142
+ weight?: number | undefined;
143
+ title?: string | undefined;
144
+ }>, z.ZodObject<{
145
+ directories: z.ZodArray<z.ZodString, "many">;
146
+ title: z.ZodOptional<z.ZodString>;
147
+ weight: z.ZodOptional<z.ZodNumber>;
148
+ }, "strip", z.ZodTypeAny, {
149
+ directories: string[];
150
+ weight?: number | undefined;
151
+ title?: string | undefined;
152
+ }, {
153
+ directories: string[];
154
+ weight?: number | undefined;
155
+ title?: string | undefined;
156
+ }>]>, "many">>>;
157
+ context: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
158
+ content: z.ZodString;
159
+ title: z.ZodOptional<z.ZodString>;
160
+ weight: z.ZodOptional<z.ZodNumber>;
161
+ }, "strip", z.ZodTypeAny, {
162
+ content: string;
163
+ weight?: number | undefined;
164
+ title?: string | undefined;
165
+ }, {
166
+ content: string;
167
+ weight?: number | undefined;
168
+ title?: string | undefined;
169
+ }>, z.ZodObject<{
170
+ path: z.ZodString;
171
+ title: z.ZodOptional<z.ZodString>;
172
+ weight: z.ZodOptional<z.ZodNumber>;
173
+ }, "strip", z.ZodTypeAny, {
174
+ path: string;
175
+ weight?: number | undefined;
176
+ title?: string | undefined;
177
+ }, {
178
+ path: string;
179
+ weight?: number | undefined;
180
+ title?: string | undefined;
181
+ }>, z.ZodObject<{
182
+ directories: z.ZodArray<z.ZodString, "many">;
183
+ title: z.ZodOptional<z.ZodString>;
184
+ weight: z.ZodOptional<z.ZodNumber>;
185
+ }, "strip", z.ZodTypeAny, {
186
+ directories: string[];
187
+ weight?: number | undefined;
188
+ title?: string | undefined;
189
+ }, {
190
+ directories: string[];
191
+ weight?: number | undefined;
192
+ title?: string | undefined;
193
+ }>]>, "many">>>;
194
+ extends: z.ZodOptional<z.ZodString>;
195
+ template: z.ZodOptional<z.ZodEnum<["commit", "release", "documentation", "review", "custom"]>>;
196
+ }, "strip", z.ZodTypeAny, {
197
+ parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
198
+ instructions: (string | {
199
+ content: string;
200
+ weight?: number | undefined;
201
+ title?: string | undefined;
202
+ } | {
203
+ path: string;
204
+ weight?: number | undefined;
205
+ title?: string | undefined;
206
+ } | {
207
+ directories: string[];
208
+ weight?: number | undefined;
209
+ title?: string | undefined;
210
+ })[];
211
+ overrides: boolean;
212
+ basePath: string;
213
+ overridePaths: string[];
214
+ content: (string | {
215
+ content: string;
216
+ weight?: number | undefined;
217
+ title?: string | undefined;
218
+ } | {
219
+ path: string;
220
+ weight?: number | undefined;
221
+ title?: string | undefined;
222
+ } | {
223
+ directories: string[];
224
+ weight?: number | undefined;
225
+ title?: string | undefined;
226
+ })[];
227
+ context: (string | {
228
+ content: string;
229
+ weight?: number | undefined;
230
+ title?: string | undefined;
231
+ } | {
232
+ path: string;
233
+ weight?: number | undefined;
234
+ title?: string | undefined;
235
+ } | {
236
+ directories: string[];
237
+ weight?: number | undefined;
238
+ title?: string | undefined;
239
+ })[];
240
+ persona?: string | {
241
+ content: string;
242
+ weight?: number | undefined;
243
+ title?: string | undefined;
244
+ } | {
245
+ path: string;
246
+ weight?: number | undefined;
247
+ title?: string | undefined;
248
+ } | {
249
+ directories: string[];
250
+ weight?: number | undefined;
251
+ title?: string | undefined;
252
+ } | undefined;
253
+ logger?: any;
254
+ extends?: string | undefined;
255
+ template?: "custom" | "commit" | "release" | "documentation" | "review" | undefined;
256
+ }, {
257
+ basePath: string;
258
+ parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
259
+ persona?: string | {
260
+ content: string;
261
+ weight?: number | undefined;
262
+ title?: string | undefined;
263
+ } | {
264
+ path: string;
265
+ weight?: number | undefined;
266
+ title?: string | undefined;
267
+ } | {
268
+ directories: string[];
269
+ weight?: number | undefined;
270
+ title?: string | undefined;
271
+ } | undefined;
272
+ instructions?: (string | {
273
+ content: string;
274
+ weight?: number | undefined;
275
+ title?: string | undefined;
276
+ } | {
277
+ path: string;
278
+ weight?: number | undefined;
279
+ title?: string | undefined;
280
+ } | {
281
+ directories: string[];
282
+ weight?: number | undefined;
283
+ title?: string | undefined;
284
+ })[] | undefined;
285
+ logger?: any;
286
+ overrides?: boolean | undefined;
287
+ overridePaths?: string[] | undefined;
288
+ content?: (string | {
289
+ content: string;
290
+ weight?: number | undefined;
291
+ title?: string | undefined;
292
+ } | {
293
+ path: string;
294
+ weight?: number | undefined;
295
+ title?: string | undefined;
296
+ } | {
297
+ directories: string[];
298
+ weight?: number | undefined;
299
+ title?: string | undefined;
300
+ })[] | undefined;
301
+ context?: (string | {
302
+ content: string;
303
+ weight?: number | undefined;
304
+ title?: string | undefined;
305
+ } | {
306
+ path: string;
307
+ weight?: number | undefined;
308
+ title?: string | undefined;
309
+ } | {
310
+ directories: string[];
311
+ weight?: number | undefined;
312
+ title?: string | undefined;
313
+ })[] | undefined;
314
+ extends?: string | undefined;
315
+ template?: "custom" | "commit" | "release" | "documentation" | "review" | undefined;
316
+ }>;
317
+ type RecipeConfig = z.infer<typeof RecipeConfigSchema>;
318
+ type ContentItem = z.infer<typeof ContentItemSchema>;
319
+ export interface TemplateConfig {
320
+ persona?: ContentItem;
321
+ instructions?: ContentItem[];
322
+ content?: ContentItem[];
323
+ context?: ContentItem[];
324
+ }
325
+ /**
326
+ * Configure custom template paths (perfect for KodrDriv constants!)
327
+ *
328
+ * @example
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 }]
335
+ * },
336
+ * release: {
337
+ * persona: { path: DEFAULT_PERSONA_RELEASER_FILE },
338
+ * instructions: [{ path: DEFAULT_INSTRUCTIONS_RELEASE_FILE }]
339
+ * }
340
+ * });
341
+ * ```
342
+ */
343
+ export declare const configureTemplates: (customTemplates: Record<string, TemplateConfig>) => void;
344
+ /**
345
+ * Get current template configuration
346
+ */
347
+ export declare const getTemplates: () => Record<string, TemplateConfig>;
348
+ export declare const cook: (config: Partial<RecipeConfig> & {
349
+ basePath: string;
350
+ }) => 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
+ 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>;
404
+ };
405
+ export type { RecipeConfig, ContentItem };