@riotprompt/riotprompt 0.0.2 → 0.0.4

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 (53) hide show
  1. package/.cursor/rules/focus-on-prompt.mdc +5 -0
  2. package/README.md +65 -492
  3. package/dist/builder.d.ts +3 -3
  4. package/dist/builder.js +9 -4
  5. package/dist/builder.js.map +1 -1
  6. package/dist/chat.js.map +1 -1
  7. package/dist/constants.js.map +1 -1
  8. package/dist/formatter.js.map +1 -1
  9. package/dist/items/content.js.map +1 -1
  10. package/dist/items/context.js.map +1 -1
  11. package/dist/items/instruction.js.map +1 -1
  12. package/dist/items/parameters.js.map +1 -1
  13. package/dist/items/section.js.map +1 -1
  14. package/dist/items/trait.js.map +1 -1
  15. package/dist/items/weighted.js.map +1 -1
  16. package/dist/loader.js +1 -0
  17. package/dist/loader.js.map +1 -1
  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.d.ts +1 -1
  23. package/dist/parse/markdown.js +3 -2
  24. package/dist/parse/markdown.js.map +1 -1
  25. package/dist/parse/text.js.map +1 -1
  26. package/dist/parser.d.ts +1 -1
  27. package/dist/parser.js +3 -3
  28. package/dist/parser.js.map +1 -1
  29. package/dist/prompt.js.map +1 -1
  30. package/dist/recipes.d.ts +373 -0
  31. package/dist/recipes.js +279 -0
  32. package/dist/recipes.js.map +1 -0
  33. package/dist/riotprompt.cjs +340 -40
  34. package/dist/riotprompt.cjs.map +1 -1
  35. package/dist/riotprompt.d.ts +3 -0
  36. package/dist/riotprompt.js +3 -0
  37. package/dist/riotprompt.js.map +1 -1
  38. package/dist/util/general.js.map +1 -1
  39. package/dist/util/markdown.js.map +1 -1
  40. package/dist/util/storage.js.map +1 -1
  41. package/dist/util/text.js.map +1 -1
  42. package/package.json +29 -24
  43. package/.gitcarve/config.yaml +0 -10
  44. package/.gitcarve/context/content.md +0 -11
  45. package/.markdown-doctest-setup.mjs +0 -23
  46. package/.nvmrc +0 -1
  47. package/docs/loader.md +0 -237
  48. package/docs/override.md +0 -323
  49. package/docs/parser.md +0 -130
  50. package/eslint.config.mjs +0 -82
  51. package/nodemon.json +0 -14
  52. package/vite.config.ts +0 -114
  53. package/vitest.config.ts +0 -25
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","sources":["../src/builder.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 { Content, Context, createPrompt, createSection, Instruction, Loader, Override, Parser, Prompt, Section, Weighted } from \"./riotprompt\";\n\nconst OptionSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n basePath: z.string(),\n overridePath: z.string().optional().default(\"./\"),\n overrides: z.boolean().optional().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionSchema>;\n\nexport type OptionsParam = Required<Pick<Options, 'basePath'>> & Partial<Omit<Options, 'basePath'>>;\n\nexport interface Instance {\n addPersonaPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContextPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addInstructionPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContentPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContent(content: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContext(context: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n loadContext(contextDirectories: string[], sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n loadContent(contentDirectories: string[], sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n build(): Promise<Prompt>;\n}\n\nexport const create = (builderOptions: OptionsParam): Instance => {\n const options: Required<Options> = OptionSchema.parse(builderOptions) as Required<Options>;\n\n const logger = wrapLogger(options.logger, 'Builder');\n const parser = Parser.create({ logger });\n const override = Override.create({\n logger, configDir: options.overridePath || \"./\",\n overrides: options.overrides || false\n });\n const loader = Loader.create({ logger });\n\n const personaSection: Section<Instruction> = createSection({ title: \"Persona\" });\n const contextSection: Section<Context> = createSection({ title: \"Context\" });\n const instructionSection: Section<Instruction> = createSection({ title: \"Instruction\" });\n const contentSection: Section<Content> = createSection({ title: \"Content\" });\n const parameters = options.parameters;\n\n\n const instance: Partial<Instance> = {}\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 loadDirectories = async <T extends Weighted>(\n directories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const currentOptions = loadOptions(sectionOptions);\n logger.debug(\"Loading directories\", directories);\n const sections: Section<T>[] = await loader.load<T>(directories, currentOptions);\n return sections;\n }\n\n const loadContext = async (\n contextDirectories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n logger.debug('Loading context', contextDirectories);\n const context: Section<Context>[] = await loadDirectories<Context>(contextDirectories, currentOptions);\n contextSection.add(context);\n return instance as Instance;\n }\n instance.loadContext = loadContext;\n\n const loadContent = async (\n contentDirectories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n const content: Section<Content>[] = await loadDirectories<Content>(contentDirectories, currentOptions);\n contentSection.add(content);\n return instance as Instance;\n }\n instance.loadContent = loadContent;\n\n const loadPath = async <T extends Weighted>(\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(sectionOptions);\n const defaultPath = path.join(options.basePath as string, contentPath);\n const section: Section<T> = await parser.parseFile<T>(defaultPath, currentOptions);\n const overrideSection = await override.customize<T>(contentPath, section, currentOptions);\n return overrideSection;\n }\n\n const addPersonaPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n const persona: Section<Instruction> = await loadPath<Instruction>(contentPath, currentOptions);\n personaSection.add(persona);\n return instance as Instance;\n }\n instance.addPersonaPath = addPersonaPath;\n\n const addContextPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding context path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const context: Section<Context> = await loadPath<Context>(contentPath, currentOptions);\n contextSection.add(context);\n return instance as Instance;\n }\n instance.addContextPath = addContextPath;\n\n const addInstructionPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding instruction path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const instruction: Section<Instruction> = await loadPath<Instruction>(contentPath, currentOptions);\n instructionSection.add(instruction);\n return instance as Instance;\n }\n instance.addInstructionPath = addInstructionPath;\n\n const addContentPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding content path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const content: Section<Content> = await loadPath<Content>(contentPath, currentOptions);\n contentSection.add(content);\n return instance as Instance;\n }\n instance.addContentPath = addContentPath;\n\n const addContent = async (\n content: string | Buffer,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding content\", typeof content);\n const currentOptions = loadOptions(sectionOptions);\n const parsedContentSection: Section<Content> = parser.parse<Content>(content, currentOptions);\n contentSection.add(parsedContentSection);\n return instance as Instance;\n }\n instance.addContent = addContent;\n\n const addContext = async (\n context: string | Buffer,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding context\", typeof context);\n const currentOptions = loadOptions(sectionOptions);\n const parsedContextSection: Section<Context> = parser.parse<Context>(context, currentOptions);\n contextSection.add(parsedContextSection);\n return instance as Instance;\n }\n instance.addContext = addContext;\n\n const build = async () => {\n logger.debug(\"Building prompt\", {});\n const prompt = createPrompt({ persona: personaSection, contexts: contextSection, instructions: instructionSection, contents: contentSection });\n return prompt;\n }\n instance.build = build;\n\n return instance as Instance;\n}\n"],"names":["OptionSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","basePath","string","overridePath","overrides","boolean","parameters","ParametersSchema","create","builderOptions","options","parse","wrapLogger","parser","Parser","override","Override","configDir","loader","Loader","personaSection","createSection","title","contextSection","instructionSection","contentSection","instance","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","loadDirectories","directories","debug","sections","load","loadContext","contextDirectories","context","add","loadContent","contentDirectories","content","loadPath","contentPath","defaultPath","path","join","section","parseFile","overrideSection","customize","addPersonaPath","persona","addContextPath","addInstructionPath","instruction","addContentPath","addContent","parsedContentSection","addContext","parsedContextSection","build","prompt","createPrompt","contexts","instructions","contents"],"mappings":";;;;;;;;;;;;AAOA,MAAMA,YAAAA,GAAeC,CAAEC,CAAAA,MAAM,CAAC;AAC1BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,QAAAA,EAAUP,EAAEQ,MAAM,EAAA;AAClBC,IAAAA,YAAAA,EAAcT,EAAEQ,MAAM,EAAA,CAAGJ,QAAQ,EAAA,CAAGC,OAAO,CAAC,IAAA,CAAA;AAC5CK,IAAAA,SAAAA,EAAWV,EAAEW,OAAO,EAAA,CAAGP,QAAQ,EAAA,CAAGC,OAAO,CAAC,KAAA,CAAA;AAC1CO,IAAAA,UAAAA,EAAYC,gBAAiBT,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;A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ACftB,OACAV,EAAAA,cAAAA,GAA0C,EAAE,GAAA;QAE5ChC,MAAOqC,CAAAA,KAAK,CAAC,gBAAA,EAAkB,OAAOK,OAAAA,CAAAA;AACtC,QAAA,MAAMT,iBAAiBF,WAAYC,CAAAA,cAAAA,CAAAA;AACnC,QAAA,MAAMiC,oBAAyChD,GAAAA,QAAAA,CAAOF,KAAK,CAAU2B,OAAST,EAAAA,cAAAA,CAAAA;AAC9EN,QAAAA,cAAAA,CAAegB,GAAG,CAACsB,oBAAAA,CAAAA;QACnB,OAAOnC,QAAAA;AACX,KAAA;AACAA,IAAAA,QAAAA,CAASkC,UAAU,GAAGA,UAAAA;AAEtB,IAAA,MAAME,KAAQ,GAAA,UAAA;QACVlE,MAAOqC,CAAAA,KAAK,CAAC,iBAAA,EAAmB,EAAC,CAAA;AACjC,QAAA,MAAM8B,SAASC,QAAa,CAAA;YAAEX,OAASjC,EAAAA,cAAAA;YAAgB6C,QAAU1C,EAAAA,cAAAA;YAAgB2C,YAAc1C,EAAAA,kBAAAA;YAAoB2C,QAAU1C,EAAAA;AAAe,SAAA,CAAA;QAC5I,OAAOsC,MAAAA;AACX,KAAA;AACArC,IAAAA,QAAAA,CAASoC,KAAK,GAAGA,KAAAA;IAEjB,OAAOpC,QAAAA;AACX;;;;"}
1
+ {"version":3,"file":"builder.js","sources":["../src/builder.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 { Content, Context, createPrompt, createSection, Instruction, Loader, Override, Parser, Prompt, Section, Weighted } from \"./riotprompt\";\n\nconst OptionSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n basePath: z.string(),\n overridePaths: z.array(z.string()).optional().default([\"./\"]),\n overrides: z.boolean().optional().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionSchema>;\n\nexport type OptionsParam = Required<Pick<Options, 'basePath'>> & Partial<Omit<Options, 'basePath'>>;\n\nexport interface Instance {\n addPersonaPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContextPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addInstructionPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContentPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContent(content: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContext(context: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n loadContext(contextDirectories: string[], sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n loadContent(contentDirectories: string[], sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n build(): Promise<Prompt>;\n}\n\nexport const create = (builderOptions: OptionsParam): Instance => {\n const options: Required<Options> = OptionSchema.parse(builderOptions) as Required<Options>;\n\n const logger = wrapLogger(options.logger, 'Builder');\n const parser = Parser.create({ logger });\n const override = Override.create({\n logger, configDirs: options.overridePaths || [\"./\"],\n overrides: options.overrides || false\n });\n const loader = Loader.create({ logger });\n\n const personaSection: Section<Instruction> = createSection({ title: \"Persona\" });\n const contextSection: Section<Context> = createSection({ title: \"Context\" });\n const instructionSection: Section<Instruction> = createSection({ title: \"Instruction\" });\n const contentSection: Section<Content> = createSection({ title: \"Content\" });\n const parameters = options.parameters;\n\n\n const instance: Partial<Instance> = {}\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 loadDirectories = async <T extends Weighted>(\n directories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const currentOptions = loadOptions(sectionOptions);\n logger.debug(\"Loading directories\", directories);\n const sections: Section<T>[] = await loader.load<T>(directories, currentOptions);\n return sections;\n }\n\n const loadContext = async (\n contextDirectories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n logger.debug('Loading context', contextDirectories);\n const context: Section<Context>[] = await loadDirectories<Context>(contextDirectories, currentOptions);\n contextSection.add(context);\n return instance as Instance;\n }\n instance.loadContext = loadContext;\n\n const loadContent = async (\n contentDirectories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n const content: Section<Content>[] = await loadDirectories<Content>(contentDirectories, currentOptions);\n contentSection.add(content);\n return instance as Instance;\n }\n instance.loadContent = loadContent;\n\n const loadPath = async <T extends Weighted>(\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(sectionOptions);\n const defaultPath = path.join(options.basePath as string, contentPath);\n const section: Section<T> = await parser.parseFile<T>(defaultPath, currentOptions);\n const overrideSection = await override.customize<T>(contentPath, section, currentOptions);\n return overrideSection;\n }\n\n const addPersonaPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n const persona: Section<Instruction> = await loadPath<Instruction>(contentPath, currentOptions);\n personaSection.add(persona);\n return instance as Instance;\n }\n instance.addPersonaPath = addPersonaPath;\n\n const addContextPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding context path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const context: Section<Context> = await loadPath<Context>(contentPath, currentOptions);\n contextSection.add(context);\n return instance as Instance;\n }\n instance.addContextPath = addContextPath;\n\n const addInstructionPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding instruction path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const instruction: Section<Instruction> = await loadPath<Instruction>(contentPath, currentOptions);\n instructionSection.add(instruction);\n return instance as Instance;\n }\n instance.addInstructionPath = addInstructionPath;\n\n const addContentPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding content path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const content: Section<Content> = await loadPath<Content>(contentPath, currentOptions);\n contentSection.add(content);\n return instance as Instance;\n }\n instance.addContentPath = addContentPath;\n\n const addContent = async (\n content: string | Buffer,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding content\", typeof content);\n const currentOptions = loadOptions(sectionOptions);\n const parsedContentSection: Section<Content> = await parser.parse<Content>(content, currentOptions);\n contentSection.add(parsedContentSection);\n return instance as Instance;\n }\n instance.addContent = addContent;\n\n const addContext = async (\n context: string | Buffer,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding context\", typeof context);\n const currentOptions = loadOptions(sectionOptions);\n const parsedContextSection: Section<Context> = await parser.parse<Context>(context, currentOptions);\n contextSection.add(parsedContextSection);\n return instance as Instance;\n }\n instance.addContext = addContext;\n\n const build = async () => {\n logger.debug(\"Building prompt\", {});\n const prompt = createPrompt({ persona: personaSection, contexts: contextSection, instructions: instructionSection, contents: contentSection });\n return prompt;\n }\n instance.build = build;\n\n return instance as Instance;\n}\n"],"names":["OptionSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","basePath","string","overridePaths","array","overrides","boolean","parameters","ParametersSchema","create","builderOptions","options","parse","wrapLogger","parser","Parser","override","Override","configDirs","loader","Loader","personaSection","createSection","title","contextSection","instructionSection","contentSection","instance","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","loadDirectories","directories","debug","sections","load","loadContext","contextDirectories","context","add","loadContent","contentDirectories","content","loadPath","contentPath","defaultPath","path","join","section","parseFile","overrideSection","customize","addPersonaPath","persona","addContextPath","addInstructionPath","instruction","addContentPath","addContent","parsedContentSection","addContext","parsedContextSection","build","prompt","createPrompt","contexts","instructions","contents"],"mappings":";;;;;;;;;;;;;AAOA,MAAMA,YAAAA,GAAeC,CAAAA,CAAEC,MAAM,CAAC;AAC1BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,QAAAA,EAAUP,EAAEQ,MAAM,EAAA;IAClBC,aAAAA,EAAeT,CAAAA,CAAEU,KAAK,CAACV,CAAAA,CAAEQ,MAAM,EAAA,CAAA,CAAIJ,QAAQ,EAAA,CAAGC,OAAO,CAAC;AAAC,QAAA;AAAK,KAAA,CAAA;AAC5DM,IAAAA,SAAAA,EAAWX,EAAEY,OAAO,EAAA,CAAGR,QAAQ,EAAA,CAAGC,OAAO,CAAC,KAAA,CAAA;AAC1CQ,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBV,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAkBO,MAAMU,SAAS,CAACC,cAAAA,GAAAA;IACnB,MAAMC,OAAAA,GAA6BlB,YAAAA,CAAamB,KAAK,CAACF,cAAAA,CAAAA;AAEtD,IAAA,MAAMd,MAAAA,GAASiB,UAAAA,CAAWF,OAAAA,CAAQf,MAAM,EAAE,SAAA,CAAA;IAC1C,MAAMkB,QAAAA,GAASC,QAAa,CAAC;AAAEnB,QAAAA;AAAO,KAAA,CAAA;IACtC,MAAMoB,UAAAA,GAAWC,QAAe,CAAC;AAC7BrB,QAAAA,MAAAA;QAAQsB,UAAAA,EAAYP,OAAAA,CAAQR,aAAa,IAAI;AAAC,YAAA;AAAK,SAAA;QACnDE,SAAAA,EAAWM,OAAAA,CAAQN,SAAS,IAAI;AACpC,KAAA,CAAA;IACA,MAAMc,QAAAA,GAASC,QAAa,CAAC;AAAExB,QAAAA;AAAO,KAAA,CAAA;AAEtC,IAAA,MAAMyB,iBAA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AK,CAAC,iBAAA,EAAmB,EAAC,CAAA;AACjC,QAAA,MAAM8B,SAASC,QAAAA,CAAa;YAAEX,OAAAA,EAASjC,cAAAA;YAAgB6C,QAAAA,EAAU1C,cAAAA;YAAgB2C,YAAAA,EAAc1C,kBAAAA;YAAoB2C,QAAAA,EAAU1C;AAAe,SAAA,CAAA;QAC5I,OAAOsC,MAAAA;AACX,IAAA,CAAA;AACArC,IAAAA,QAAAA,CAASoC,KAAK,GAAGA,KAAAA;IAEjB,OAAOpC,QAAAA;AACX;;;;"}
package/dist/chat.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"chat.js","sources":["../src/chat.ts"],"sourcesContent":["import { DEFAULT_PERSONA_ROLE } from \"./constants\";\n\nexport type Role = \"user\" | \"assistant\" | \"system\" | \"developer\";\n\nexport type Model = \"gpt-4o\" | \"gpt-4o-mini\" | \"o1-preview\" | \"o1-mini\" | \"o1\" | \"o3-mini\" | \"o1-pro\";\n\nexport interface Message {\n role: Role;\n content: string | string[];\n name?: string;\n}\n\nexport interface Request {\n messages: Message[];\n model: Model;\n\n addMessage(message: Message): void;\n}\n\nexport const getPersonaRole = (model: Model): Role => {\n if (model === \"gpt-4o\" || model === \"gpt-4o-mini\") {\n return \"system\";\n }\n return DEFAULT_PERSONA_ROLE;\n}\n\nexport const createRequest = (model: Model): Request => {\n const messages: Message[] = [];\n\n return {\n model,\n messages,\n addMessage: (message: Message) => {\n messages.push(message);\n }\n }\n}\n"],"names":["getPersonaRole","model","DEFAULT_PERSONA_ROLE","createRequest","messages","addMessage","message","push"],"mappings":";;AAmBO,MAAMA,iBAAiB,CAACC,KAAAA,GAAAA;IAC3B,IAAIA,KAAAA,KAAU,QAAYA,IAAAA,KAAAA,KAAU,aAAe,EAAA;QAC/C,OAAO,QAAA;AACX;IACA,OAAOC,oBAAAA;AACX;AAEO,MAAMC,gBAAgB,CAACF,KAAAA,GAAAA;AAC1B,IAAA,MAAMG,WAAsB,EAAE;IAE9B,OAAO;AACHH,QAAAA,KAAAA;AACAG,QAAAA,QAAAA;AACAC,QAAAA,UAAAA,EAAY,CAACC,OAAAA,GAAAA;AACTF,YAAAA,QAAAA,CAASG,IAAI,CAACD,OAAAA,CAAAA;AAClB;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"chat.js","sources":["../src/chat.ts"],"sourcesContent":["import { DEFAULT_PERSONA_ROLE } from \"./constants\";\n\nexport type Role = \"user\" | \"assistant\" | \"system\" | \"developer\";\n\nexport type Model = \"gpt-4o\" | \"gpt-4o-mini\" | \"o1-preview\" | \"o1-mini\" | \"o1\" | \"o3-mini\" | \"o1-pro\";\n\nexport interface Message {\n role: Role;\n content: string | string[];\n name?: string;\n}\n\nexport interface Request {\n messages: Message[];\n model: Model;\n\n addMessage(message: Message): void;\n}\n\nexport const getPersonaRole = (model: Model): Role => {\n if (model === \"gpt-4o\" || model === \"gpt-4o-mini\") {\n return \"system\";\n }\n return DEFAULT_PERSONA_ROLE;\n}\n\nexport const createRequest = (model: Model): Request => {\n const messages: Message[] = [];\n\n return {\n model,\n messages,\n addMessage: (message: Message) => {\n messages.push(message);\n }\n }\n}\n"],"names":["getPersonaRole","model","DEFAULT_PERSONA_ROLE","createRequest","messages","addMessage","message","push"],"mappings":";;AAmBO,MAAMA,iBAAiB,CAACC,KAAAA,GAAAA;IAC3B,IAAIA,KAAAA,KAAU,QAAA,IAAYA,KAAAA,KAAU,aAAA,EAAe;QAC/C,OAAO,QAAA;AACX,IAAA;IACA,OAAOC,oBAAAA;AACX;AAEO,MAAMC,gBAAgB,CAACF,KAAAA,GAAAA;AAC1B,IAAA,MAAMG,WAAsB,EAAE;IAE9B,OAAO;AACHH,QAAAA,KAAAA;AACAG,QAAAA,QAAAA;AACAC,QAAAA,UAAAA,EAAY,CAACC,OAAAA,GAAAA;AACTF,YAAAA,QAAAA,CAASG,IAAI,CAACD,OAAAA,CAAAA;AAClB,QAAA;AACJ,KAAA;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["import { SectionSeparator } from \"formatter\";\n\nimport { FormatOptions } from \"formatter\";\n\nexport const DEFAULT_CHARACTER_ENCODING = \"utf8\";\nexport const LIBRARY_NAME = \"riotprompt\";\n\nexport const DEFAULT_PERSONA_ROLE = \"developer\";\n\nexport const DEFAULT_INSTRUCTIONS_AREA_TITLE = \"Instructions\";\nexport const DEFAULT_CONTENTS_AREA_TITLE = \"Contents\";\nexport const DEFAULT_CONTEXT_AREA_TITLE = \"Context\";\n\nexport const DEFAULT_IGNORE_PATTERNS: string[] = [\n \"^\\\\..*\", // Hidden files (e.g., .git, .DS_Store)\n \"\\\\.(jpg|jpeg|png|gif|bmp|svg|webp|ico)$\", // Image files\n \"\\\\.(mp3|wav|ogg|aac|flac)$\", // Audio files\n \"\\\\.(mp4|mov|avi|mkv|webm)$\", // Video files\n \"\\\\.(pdf|doc|docx|xls|xlsx|ppt|pptx)$\", // Document files\n \"\\\\.(zip|tar|gz|rar|7z)$\" // Compressed files\n];\n\nexport const DEFAULT_SECTION_SEPARATOR: SectionSeparator = \"tag\";\nexport const DEFAULT_SECTION_INDENTATION = true;\nexport const DEFAULT_SECTION_TAG = \"section\";\nexport const DEFAULT_SECTION_TITLE_PROPERTY = \"title\";\n\nexport const DEFAULT_FORMAT_OPTIONS: FormatOptions = {\n sectionSeparator: DEFAULT_SECTION_SEPARATOR,\n sectionIndentation: DEFAULT_SECTION_INDENTATION,\n sectionTitleProperty: DEFAULT_SECTION_TITLE_PROPERTY,\n sectionDepth: 0,\n}\n"],"names":["DEFAULT_CHARACTER_ENCODING","LIBRARY_NAME","DEFAULT_PERSONA_ROLE","DEFAULT_IGNORE_PATTERNS","DEFAULT_SECTION_SEPARATOR","DEFAULT_SECTION_INDENTATION","DEFAULT_SECTION_TITLE_PROPERTY","DEFAULT_FORMAT_OPTIONS","sectionSeparator","sectionIndentation","sectionTitleProperty","sectionDepth"],"mappings":"AAIO,MAAMA,6BAA6B;AACnC,MAAMC,eAAe;AAErB,MAAMC,uBAAuB;MAMvBC,uBAAoC,GAAA;AAC7C,IAAA,QAAA;AACA,IAAA,yCAAA;AACA,IAAA,4BAAA;AACA,IAAA,4BAAA;AACA,IAAA,sCAAA;AACA,IAAA,yBAAA;;AAGG,MAAMC,4BAA8C;AACpD,MAAMC,8BAA8B;AAEpC,MAAMC,iCAAiC;MAEjCC,sBAAwC,GAAA;IACjDC,gBAAkBJ,EAAAA,yBAAAA;IAClBK,kBAAoBJ,EAAAA,2BAAAA;IACpBK,oBAAsBJ,EAAAA,8BAAAA;IACtBK,YAAc,EAAA;AAClB;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["import { SectionSeparator } from \"formatter\";\n\nimport { FormatOptions } from \"formatter\";\n\nexport const DEFAULT_CHARACTER_ENCODING = \"utf8\";\nexport const LIBRARY_NAME = \"riotprompt\";\n\nexport const DEFAULT_PERSONA_ROLE = \"developer\";\n\nexport const DEFAULT_INSTRUCTIONS_AREA_TITLE = \"Instructions\";\nexport const DEFAULT_CONTENTS_AREA_TITLE = \"Contents\";\nexport const DEFAULT_CONTEXT_AREA_TITLE = \"Context\";\n\nexport const DEFAULT_IGNORE_PATTERNS: string[] = [\n \"^\\\\..*\", // Hidden files (e.g., .git, .DS_Store)\n \"\\\\.(jpg|jpeg|png|gif|bmp|svg|webp|ico)$\", // Image files\n \"\\\\.(mp3|wav|ogg|aac|flac)$\", // Audio files\n \"\\\\.(mp4|mov|avi|mkv|webm)$\", // Video files\n \"\\\\.(pdf|doc|docx|xls|xlsx|ppt|pptx)$\", // Document files\n \"\\\\.(zip|tar|gz|rar|7z)$\" // Compressed files\n];\n\nexport const DEFAULT_SECTION_SEPARATOR: SectionSeparator = \"tag\";\nexport const DEFAULT_SECTION_INDENTATION = true;\nexport const DEFAULT_SECTION_TAG = \"section\";\nexport const DEFAULT_SECTION_TITLE_PROPERTY = \"title\";\n\nexport const DEFAULT_FORMAT_OPTIONS: FormatOptions = {\n sectionSeparator: DEFAULT_SECTION_SEPARATOR,\n sectionIndentation: DEFAULT_SECTION_INDENTATION,\n sectionTitleProperty: DEFAULT_SECTION_TITLE_PROPERTY,\n sectionDepth: 0,\n}\n"],"names":["DEFAULT_CHARACTER_ENCODING","LIBRARY_NAME","DEFAULT_PERSONA_ROLE","DEFAULT_IGNORE_PATTERNS","DEFAULT_SECTION_SEPARATOR","DEFAULT_SECTION_INDENTATION","DEFAULT_SECTION_TITLE_PROPERTY","DEFAULT_FORMAT_OPTIONS","sectionSeparator","sectionIndentation","sectionTitleProperty","sectionDepth"],"mappings":"AAIO,MAAMA,6BAA6B;AACnC,MAAMC,eAAe;AAErB,MAAMC,uBAAuB;MAMvBC,uBAAAA,GAAoC;AAC7C,IAAA,QAAA;AACA,IAAA,yCAAA;AACA,IAAA,4BAAA;AACA,IAAA,4BAAA;AACA,IAAA,sCAAA;AACA,IAAA,yBAAA;;AAGG,MAAMC,4BAA8C;AACpD,MAAMC,8BAA8B;AAEpC,MAAMC,iCAAiC;MAEjCC,sBAAAA,GAAwC;IACjDC,gBAAAA,EAAkBJ,yBAAAA;IAClBK,kBAAAA,EAAoBJ,2BAAAA;IACpBK,oBAAAA,EAAsBJ,8BAAAA;IACtBK,YAAAA,EAAc;AAClB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sources":["../src/formatter.ts"],"sourcesContent":["import { Instruction } from \"riotprompt\";\nimport { z } from \"zod\";\nimport * as Chat from \"./chat\";\nimport { getPersonaRole, Message, Model } from \"./chat\";\nimport { DEFAULT_FORMAT_OPTIONS } from \"./constants\";\nimport { Section } from \"./items/section\";\nimport { Weighted } from \"./items/weighted\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Prompt } from \"./prompt\";\nimport { clean, stringifyJSON } from \"./util/general\";\n\nexport const SectionSeparatorSchema = z.enum([\"tag\", \"markdown\"]);\nexport const SectionTitlePropertySchema = z.enum([\"title\", \"name\"]);\n\nexport type SectionSeparator = z.infer<typeof SectionSeparatorSchema>;\nexport type SectionTitleProperty = z.infer<typeof SectionTitlePropertySchema>;\n\n\nexport const FormatOptionsSchema = z.object({\n sectionSeparator: SectionSeparatorSchema,\n sectionIndentation: z.boolean(),\n sectionTitleProperty: SectionTitlePropertySchema,\n sectionTitlePrefix: z.string().optional(),\n sectionTitleSeparator: z.string().optional(),\n sectionDepth: z.number().default(1),\n});\n\nexport type FormatOptions = z.infer<typeof FormatOptionsSchema>;\n\n\nexport const OptionSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n formatOptions: FormatOptionsSchema.partial().optional().default(DEFAULT_FORMAT_OPTIONS),\n});\n\nexport type Options = z.infer<typeof OptionSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n formatPersona: (model: Model, persona: Section<Instruction>) => Message;\n format: <T extends Weighted>(weightedText: T | Section<T>, sectionDepth?: number) => string;\n formatArray: <T extends Weighted>(items: (T | Section<T>)[], sectionDepth?: number) => string;\n formatPrompt: (model: Model, prompt: Prompt) => Chat.Request;\n}\n\n// Type guard to check if an object is a Section\nfunction isSection<T extends Weighted>(obj: T | Section<T>): obj is Section<T> {\n return obj && typeof obj === 'object' && 'items' in obj && Array.isArray((obj as Section<T>).items);\n}\n\n// Type guard to check if an object is a Section\nfunction isWeighted<T extends Weighted>(obj: T | Section<T>): obj is T {\n return obj && typeof obj === 'object' && 'text' in obj;\n}\n\n\nexport const create = (formatterOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionSchema.parse(formatterOptions || {}) as Required<Options>;\n\n const logger = wrapLogger(options.logger, 'Formatter');\n\n let formatOptions: FormatOptions = DEFAULT_FORMAT_OPTIONS;\n if (options?.formatOptions) {\n formatOptions = {\n ...formatOptions,\n ...clean(options.formatOptions),\n };\n }\n\n const formatPersona = (model: Model, persona: Section<Instruction>): Message => {\n logger.silly(`Formatting persona`);\n if (persona) {\n const formattedPersona = formatSection(persona);\n\n return {\n role: getPersonaRole(model),\n content: `${formattedPersona}`,\n }\n } else {\n throw new Error(\"Persona is required\");\n }\n }\n\n const format = <T extends Weighted>(\n item: T | Section<T>,\n sectionDepth?: number,\n ): string => {\n logger.silly(`Formatting ${isSection(item) ? \"section\" : \"item\"} Item: %s`, stringifyJSON(item));\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n logger.silly(`\\t\\tCurrent section depth: ${currentSectionDepth}`);\n\n let result: string = \"\";\n if (isSection(item)) {\n result = formatSection(item, currentSectionDepth + 1);\n } else if (isWeighted(item)) {\n result = item.text;\n } else {\n //If the item is neither a section nor a weighted item, it is empty.\n result = '';\n }\n return result;\n }\n\n const formatSection = <T extends Weighted>(section: Section<T>, sectionDepth?: number): string => {\n logger.silly(`Formatting section`);\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n logger.silly(`\\t\\tCurrent section depth: ${currentSectionDepth}`);\n\n if (section) {\n const formattedItems = section.items.map(item => format(item, currentSectionDepth)).join(\"\\n\\n\");\n\n if (formatOptions.sectionSeparator === \"tag\") {\n return `<${section.title ?? \"section\"}>\\n${formattedItems}\\n</${section.title ?? \"section\"}>`;\n } else {\n // Default depth to 1 if not provided, resulting in H2 (##) matching the test case.\n const headingLevel = currentSectionDepth;\n const hashes = '#'.repeat(headingLevel);\n logger.silly(`\\t\\tHeading level: ${headingLevel}`);\n logger.silly(`\\t\\tSection title: ${section.title}`);\n return `${hashes} ${formatOptions.sectionTitlePrefix ? `${formatOptions.sectionTitlePrefix} ${formatOptions.sectionTitleSeparator} ` : \"\"}${section.title}\\n\\n${formattedItems}`;\n }\n } else {\n return '';\n }\n }\n\n // Helper function to format arrays of items or sections\n const formatArray = <T extends Weighted>(\n items: (T | Section<T>)[],\n sectionDepth?: number\n ): string => {\n logger.silly(`Formatting array`);\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n return items.map(item => format(item, currentSectionDepth)).join(\"\\n\\n\");\n }\n\n const formatPrompt = (model: Model, prompt: Prompt): Chat.Request => {\n logger.silly('Formatting prompt');\n const chatRequest: Chat.Request = Chat.createRequest(model);\n\n if (prompt.persona) {\n [prompt.persona].forEach((persona: Section<Instruction>) => {\n chatRequest.addMessage(formatPersona(model, persona));\n });\n }\n\n let formattedAreas: string = formatSection(prompt.instructions) + '\\n\\n';\n\n if (prompt.contents) {\n formattedAreas += formatSection(prompt.contents) + '\\n\\n';\n }\n\n if (prompt.contexts) {\n formattedAreas += formatSection(prompt.contexts) + '\\n\\n';\n }\n\n chatRequest.addMessage({\n role: \"user\",\n content: formattedAreas,\n });\n\n return chatRequest;\n }\n\n return {\n formatPersona,\n format,\n formatPrompt,\n formatArray,\n }\n}\n"],"names":["SectionSeparatorSchema","z","enum","SectionTitlePropertySchema","FormatOptionsSchema","object","sectionSeparator","sectionIndentation","boolean","sectionTitleProperty","sectionTitlePrefix","string","optional","sectionTitleSeparator","sectionDepth","number","default","OptionSchema","logger","any","DEFAULT_LOGGER","formatOptions","partial","DEFAULT_FORMAT_OPTIONS","isSection","obj","Array","isArray","items","isWeighted","create","formatterOptions","options","parse","wrapLogger","clean","formatPersona","model","persona","silly","formattedPersona","formatSection","role","getPersonaRole","content","Error","format","item","stringifyJSON","currentSectionDepth","result","text","section","formattedItems","map","join","title","headingLevel","hashes","repeat","formatArray","formatPrompt","prompt","chatRequest","Chat","forEach","addMessage","formattedAreas","instructions","contents","contexts"],"mappings":";;;;;;AAWaA,MAAAA,sBAAAA,GAAyBC,CAAEC,CAAAA,IAAI,CAAC;AAAC,IAAA,KAAA;AAAO,IAAA;CAAW;AACnDC,MAAAA,0BAAAA,GAA6BF,CAAEC,CAAAA,IAAI,CAAC;AAAC,IAAA,OAAA;AAAS,IAAA;CAAO;AAMrDE,MAAAA,mBAAAA,GAAsBH,CAAEI,CAAAA,MAAM,CAAC;IACxCC,gBAAkBN,EAAAA,sBAAAA;AAClBO,IAAAA,kBAAAA,EAAoBN,EAAEO,OAAO,EAAA;IAC7BC,oBAAsBN,EAA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CAAAA;AAChD,aAAA,CAAA;AACJ;AAEA,QAAA,IAAI6B,cAAyB1B,GAAAA,aAAAA,CAAcqB,MAAOM,CAAAA,YAAY,CAAI,GAAA,MAAA;QAElE,IAAIN,MAAAA,CAAOO,QAAQ,EAAE;YACjBF,cAAkB1B,IAAAA,aAAAA,CAAcqB,MAAOO,CAAAA,QAAQ,CAAI,GAAA,MAAA;AACvD;QAEA,IAAIP,MAAAA,CAAOQ,QAAQ,EAAE;YACjBH,cAAkB1B,IAAAA,aAAAA,CAAcqB,MAAOQ,CAAAA,QAAQ,CAAI,GAAA,MAAA;AACvD;AAEAP,QAAAA,WAAAA,CAAYG,UAAU,CAAC;YACnBxB,IAAM,EAAA,MAAA;YACNE,OAASuB,EAAAA;AACb,SAAA,CAAA;QAEA,OAAOJ,WAAAA;AACX,KAAA;IAEA,OAAO;AACH3B,QAAAA,aAAAA;AACAU,QAAAA,MAAAA;AACAe,QAAAA,YAAAA;AACAD,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"formatter.js","sources":["../src/formatter.ts"],"sourcesContent":["import { Instruction } from \"riotprompt\";\nimport { z } from \"zod\";\nimport * as Chat from \"./chat\";\nimport { getPersonaRole, Message, Model } from \"./chat\";\nimport { DEFAULT_FORMAT_OPTIONS } from \"./constants\";\nimport { Section } from \"./items/section\";\nimport { Weighted } from \"./items/weighted\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Prompt } from \"./prompt\";\nimport { clean, stringifyJSON } from \"./util/general\";\n\nexport const SectionSeparatorSchema = z.enum([\"tag\", \"markdown\"]);\nexport const SectionTitlePropertySchema = z.enum([\"title\", \"name\"]);\n\nexport type SectionSeparator = z.infer<typeof SectionSeparatorSchema>;\nexport type SectionTitleProperty = z.infer<typeof SectionTitlePropertySchema>;\n\n\nexport const FormatOptionsSchema = z.object({\n sectionSeparator: SectionSeparatorSchema,\n sectionIndentation: z.boolean(),\n sectionTitleProperty: SectionTitlePropertySchema,\n sectionTitlePrefix: z.string().optional(),\n sectionTitleSeparator: z.string().optional(),\n sectionDepth: z.number().default(1),\n});\n\nexport type FormatOptions = z.infer<typeof FormatOptionsSchema>;\n\n\nexport const OptionSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n formatOptions: FormatOptionsSchema.partial().optional().default(DEFAULT_FORMAT_OPTIONS),\n});\n\nexport type Options = z.infer<typeof OptionSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n formatPersona: (model: Model, persona: Section<Instruction>) => Message;\n format: <T extends Weighted>(weightedText: T | Section<T>, sectionDepth?: number) => string;\n formatArray: <T extends Weighted>(items: (T | Section<T>)[], sectionDepth?: number) => string;\n formatPrompt: (model: Model, prompt: Prompt) => Chat.Request;\n}\n\n// Type guard to check if an object is a Section\nfunction isSection<T extends Weighted>(obj: T | Section<T>): obj is Section<T> {\n return obj && typeof obj === 'object' && 'items' in obj && Array.isArray((obj as Section<T>).items);\n}\n\n// Type guard to check if an object is a Section\nfunction isWeighted<T extends Weighted>(obj: T | Section<T>): obj is T {\n return obj && typeof obj === 'object' && 'text' in obj;\n}\n\n\nexport const create = (formatterOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionSchema.parse(formatterOptions || {}) as Required<Options>;\n\n const logger = wrapLogger(options.logger, 'Formatter');\n\n let formatOptions: FormatOptions = DEFAULT_FORMAT_OPTIONS;\n if (options?.formatOptions) {\n formatOptions = {\n ...formatOptions,\n ...clean(options.formatOptions),\n };\n }\n\n const formatPersona = (model: Model, persona: Section<Instruction>): Message => {\n logger.silly(`Formatting persona`);\n if (persona) {\n const formattedPersona = formatSection(persona);\n\n return {\n role: getPersonaRole(model),\n content: `${formattedPersona}`,\n }\n } else {\n throw new Error(\"Persona is required\");\n }\n }\n\n const format = <T extends Weighted>(\n item: T | Section<T>,\n sectionDepth?: number,\n ): string => {\n logger.silly(`Formatting ${isSection(item) ? \"section\" : \"item\"} Item: %s`, stringifyJSON(item));\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n logger.silly(`\\t\\tCurrent section depth: ${currentSectionDepth}`);\n\n let result: string = \"\";\n if (isSection(item)) {\n result = formatSection(item, currentSectionDepth + 1);\n } else if (isWeighted(item)) {\n result = item.text;\n } else {\n //If the item is neither a section nor a weighted item, it is empty.\n result = '';\n }\n return result;\n }\n\n const formatSection = <T extends Weighted>(section: Section<T>, sectionDepth?: number): string => {\n logger.silly(`Formatting section`);\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n logger.silly(`\\t\\tCurrent section depth: ${currentSectionDepth}`);\n\n if (section) {\n const formattedItems = section.items.map(item => format(item, currentSectionDepth)).join(\"\\n\\n\");\n\n if (formatOptions.sectionSeparator === \"tag\") {\n return `<${section.title ?? \"section\"}>\\n${formattedItems}\\n</${section.title ?? \"section\"}>`;\n } else {\n // Default depth to 1 if not provided, resulting in H2 (##) matching the test case.\n const headingLevel = currentSectionDepth;\n const hashes = '#'.repeat(headingLevel);\n logger.silly(`\\t\\tHeading level: ${headingLevel}`);\n logger.silly(`\\t\\tSection title: ${section.title}`);\n return `${hashes} ${formatOptions.sectionTitlePrefix ? `${formatOptions.sectionTitlePrefix} ${formatOptions.sectionTitleSeparator} ` : \"\"}${section.title}\\n\\n${formattedItems}`;\n }\n } else {\n return '';\n }\n }\n\n // Helper function to format arrays of items or sections\n const formatArray = <T extends Weighted>(\n items: (T | Section<T>)[],\n sectionDepth?: number\n ): string => {\n logger.silly(`Formatting array`);\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n return items.map(item => format(item, currentSectionDepth)).join(\"\\n\\n\");\n }\n\n const formatPrompt = (model: Model, prompt: Prompt): Chat.Request => {\n logger.silly('Formatting prompt');\n const chatRequest: Chat.Request = Chat.createRequest(model);\n\n if (prompt.persona) {\n [prompt.persona].forEach((persona: Section<Instruction>) => {\n chatRequest.addMessage(formatPersona(model, persona));\n });\n }\n\n let formattedAreas: string = formatSection(prompt.instructions) + '\\n\\n';\n\n if (prompt.contents) {\n formattedAreas += formatSection(prompt.contents) + '\\n\\n';\n }\n\n if (prompt.contexts) {\n formattedAreas += formatSection(prompt.contexts) + '\\n\\n';\n }\n\n chatRequest.addMessage({\n role: \"user\",\n content: formattedAreas,\n });\n\n return chatRequest;\n }\n\n return {\n formatPersona,\n format,\n formatPrompt,\n formatArray,\n }\n}\n"],"names":["SectionSeparatorSchema","z","enum","SectionTitlePropertySchema","FormatOptionsSchema","object","sectionSeparator","sectionIndentation","boolean","sectionTitleProperty","sectionTitlePrefix","string","optional","sectionTitleSeparator","sectionDepth","number","default","OptionSchema","logger","any","DEFAULT_LOGGER","formatOptions","partial","DEFAULT_FORMAT_OPTIONS","isSection","obj","Array","isArray","items","isWeighted","create","formatterOptions","options","parse","wrapLogger","clean","formatPersona","model","persona","silly","formattedPersona","formatSection","role","getPersonaRole","content","Error","format","item","stringifyJSON","currentSectionDepth","result","text","section","formattedItems","map","join","title","headingLevel","hashes","repeat","formatArray","formatPrompt","prompt","chatRequest","Chat","forEach","addMessage","formattedAreas","instructions","contents","contexts"],"mappings":";;;;;;AAWO,MAAMA,sBAAAA,GAAyBC,CAAAA,CAAEC,IAAI,CAAC;AAAC,IAAA,KAAA;AAAO,IAAA;CAAW;AACzD,MAAMC,0BAAAA,GAA6BF,CAAAA,CAAEC,IAAI,CAAC;AAAC,IAAA,OAAA;AAAS,IAAA;CAAO;AAM3D,MAAME,mBAAAA,GAAsBH,CAAAA,CAAEI,MAAM,CAAC;IACxCC,gBAAAA,EAAkBN,sBAAAA;AAClBO,IAAAA,kBAAAA,EAAoBN,EAAEO,OAAO,EAAA;IAC7BC,oBAAAA,EAAsBN,0BAAAA;IACtBO,kBAAAA,EAAoBT,CAAAA,CAAEU,MAAM,EAAA,CAAGC,QAAQ,EAAA;IACvCC,qBAAAA,EAAuBZ,CAAAA,CAAEU,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC1CE,IAAAA,YAAAA,EAAcb,CAAAA,CAAEc,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AAcqB,MAAAA,CAAOM,YAAY,CAAA,GAAI,MAAA;QAElE,IAAIN,MAAAA,CAAOO,QAAQ,EAAE;YACjBF,cAAAA,IAAkB1B,aAAAA,CAAcqB,MAAAA,CAAOO,QAAQ,CAAA,GAAI,MAAA;AACvD,QAAA;QAEA,IAAIP,MAAAA,CAAOQ,QAAQ,EAAE;YACjBH,cAAAA,IAAkB1B,aAAAA,CAAcqB,MAAAA,CAAOQ,QAAQ,CAAA,GAAI,MAAA;AACvD,QAAA;AAEAP,QAAAA,WAAAA,CAAYG,UAAU,CAAC;YACnBxB,IAAAA,EAAM,MAAA;YACNE,OAAAA,EAASuB;AACb,SAAA,CAAA;QAEA,OAAOJ,WAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACH3B,QAAAA,aAAAA;AACAU,QAAAA,MAAAA;AACAe,QAAAA,YAAAA;AACAD,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","sources":["../../src/items/content.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\n// Define Content as a type alias for Weighted\nexport type Content = Weighted;\n\n// Export create function\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Content => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Content>(text, weightedOptions);\n}\n\n"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;AAKA;MACaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,qBAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAAwBL,IAAME,EAAAA,eAAAA,CAAAA;AACzC;;;;"}
1
+ {"version":3,"file":"content.js","sources":["../../src/items/content.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\n// Define Content as a type alias for Weighted\nexport type Content = Weighted;\n\n// Export create function\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Content => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Content>(text, weightedOptions);\n}\n\n"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;AAKA;MACaA,MAAAA,GAAS,CAACC,IAAAA,EAAcC,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,qBAAAA,CAAsBC,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAAwBL,IAAAA,EAAME,eAAAA,CAAAA;AACzC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sources":["../../src/items/context.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Context = Weighted;\n\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Context => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Context>(text, weightedOptions);\n}\n\n"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;MAIaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,qBAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAAwBL,IAAME,EAAAA,eAAAA,CAAAA;AACzC;;;;"}
1
+ {"version":3,"file":"context.js","sources":["../../src/items/context.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Context = Weighted;\n\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Context => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Context>(text, weightedOptions);\n}\n\n"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;MAIaA,MAAAA,GAAS,CAACC,IAAAA,EAAcC,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,qBAAAA,CAAsBC,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAAwBL,IAAAA,EAAME,eAAAA,CAAAA;AACzC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"instruction.js","sources":["../../src/items/instruction.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Instruction = Weighted;\n\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Instruction => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Instruction>(text, weightedOptions);\n}"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;MAIaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,qBAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAA4BL,IAAME,EAAAA,eAAAA,CAAAA;AAC7C;;;;"}
1
+ {"version":3,"file":"instruction.js","sources":["../../src/items/instruction.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Instruction = Weighted;\n\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Instruction => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Instruction>(text, weightedOptions);\n}"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;MAIaA,MAAAA,GAAS,CAACC,IAAAA,EAAcC,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,qBAAAA,CAAsBC,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAA4BL,IAAAA,EAAME,eAAAA,CAAAA;AAC7C;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"parameters.js","sources":["../../src/items/parameters.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const ParametersSchema = z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.union([z.string(), z.number(), z.boolean()]))]));\n\nexport type Parameters = z.infer<typeof ParametersSchema>;\n\nexport const create = (parameters: Parameters): Parameters => {\n return parameters;\n}\n\nexport const apply = (text: string, parameters?: Parameters): string => {\n if (!parameters) {\n return text;\n }\n\n // First, trim parameters keys to handle whitespace in placeholder names\n const trimmedParams: Record<string, any> = {};\n Object.keys(parameters).forEach(key => {\n trimmedParams[key.trim()] = parameters[key];\n });\n\n // Process all placeholders, preserving ones that don't have matching parameters\n return text.replace(/\\{\\{([^{}]+)\\}\\}/g, (match, p1) => {\n const paramKey = p1.trim();\n const parameter = trimmedParams[paramKey];\n\n if (parameter === undefined) {\n // Preserve the original placeholder if parameter doesn't exist\n return match;\n } else if (typeof parameter === 'string') {\n return parameter;\n } else if (typeof parameter === 'number') {\n return parameter.toString();\n } else if (typeof parameter === 'boolean') {\n return parameter.toString();\n } else if (Array.isArray(parameter)) {\n return parameter.join(', ');\n } else {\n return match;\n }\n });\n}"],"names":["ParametersSchema","z","record","string","union","number","boolean","array","create","parameters","apply","text","trimmedParams","Object","keys","forEach","key","trim","replace","match","p1","paramKey","parameter","undefined","toString","Array","isArray","join"],"mappings":";;AAEO,MAAMA,gBAAmBC,GAAAA,CAAAA,CAAEC,MAAM,CAACD,EAAEE,MAAM,EAAA,EAAIF,CAAEG,CAAAA,KAAK,CAAC;AAACH,IAAAA,CAAAA,CAAEE,MAAM,EAAA;AAAIF,IAAAA,CAAAA,CAAEI,MAAM,EAAA;AAAIJ,IAAAA,CAAAA,CAAEK,OAAO,EAAA;AAAIL,IAAAA,CAAAA,CAAEM,KAAK,CAACN,CAAEG,CAAAA,KAAK,CAAC;AAACH,QAAAA,CAAAA,CAAEE,MAAM,EAAA;AAAIF,QAAAA,CAAAA,CAAEI,MAAM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../src/items/parameters.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const ParametersSchema = z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.union([z.string(), z.number(), z.boolean()]))]));\n\nexport type Parameters = z.infer<typeof ParametersSchema>;\n\nexport const create = (parameters: Parameters): Parameters => {\n return parameters;\n}\n\nexport const apply = (text: string, parameters?: Parameters): string => {\n if (!parameters) {\n return text;\n }\n\n // First, trim parameters keys to handle whitespace in placeholder names\n const trimmedParams: Record<string, any> = {};\n Object.keys(parameters).forEach(key => {\n trimmedParams[key.trim()] = parameters[key];\n });\n\n // Process all placeholders, preserving ones that don't have matching parameters\n return text.replace(/\\{\\{([^{}]+)\\}\\}/g, (match, p1) => {\n const paramKey = p1.trim();\n const parameter = trimmedParams[paramKey];\n\n if (parameter === undefined) {\n // Preserve the original placeholder if parameter doesn't exist\n return match;\n } else if (typeof parameter === 'string') {\n return parameter;\n } else if (typeof parameter === 'number') {\n return parameter.toString();\n } else if (typeof parameter === 'boolean') {\n return parameter.toString();\n } else if (Array.isArray(parameter)) {\n return parameter.join(', ');\n } else {\n return match;\n }\n });\n}"],"names":["ParametersSchema","z","record","string","union","number","boolean","array","create","parameters","apply","text","trimmedParams","Object","keys","forEach","key","trim","replace","match","p1","paramKey","parameter","undefined","toString","Array","isArray","join"],"mappings":";;AAEO,MAAMA,gBAAAA,GAAmBC,CAAAA,CAAEC,MAAM,CAACD,EAAEE,MAAM,EAAA,EAAIF,CAAAA,CAAEG,KAAK,CAAC;AAACH,IAAAA,CAAAA,CAAEE,MAAM,EAAA;AAAIF,IAAAA,CAAAA,CAAEI,MAAM,EAAA;AAAIJ,IAAAA,CAAAA,CAAEK,OAAO,EAAA;AAAIL,IAAAA,CAAAA,CAAEM,KAAK,CAACN,CAAAA,CAAEG,KAAK,CAAC;AAACH,QAAAA,CAAAA,CAAEE,MAAM,EAAA;AAAIF,QAAAA,CAAAA,CAAEI,MAAM,EAAA;AAAIJ,QAAAA,CAAAA,CAA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@ -1 +1 @@
1
- {"version":3,"file":"section.js","sources":["../../src/items/section.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ParametersSchema } from \"./parameters\";\nimport { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport interface Section<T extends Weighted> {\n title?: string;\n items: (T | Section<T>)[];\n weight?: number;\n add: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n append: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n prepend: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n insert: (\n index: number,\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n replace: (\n index: number,\n item: T | Section<T> | string,\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n remove: (index: number) => Section<T>;\n}\n\nexport const SectionOptionsSchema = z.object({\n title: z.string().optional(),\n weight: z.number().optional(),\n itemWeight: z.number().optional(),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type SectionOptions = z.infer<typeof SectionOptionsSchema>;\n\nexport const isSection = (object: any): boolean => {\n return object !== undefined && object != null && typeof object === 'object' && 'items' in object;\n}\n\nexport const convertToSection = (\n object: any,\n options: Partial<SectionOptions> = {}\n): Section<Weighted> => {\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n const weightedOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n if (isSection(object)) {\n const section = create({ ...sectionOptions, title: object.title });\n object.items.forEach((item: any) => {\n if (isSection(item)) {\n section.append(convertToSection(item, sectionOptions));\n } else {\n section.append(createWeighted(item.text, weightedOptions));\n }\n });\n return section;\n } else {\n throw new Error('Object is not a section');\n }\n}\n\nexport const create = <T extends Weighted>(\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n const items: (T | Section<T>)[] = [];\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n const sectionItemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n const append = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n append(item);\n });\n } else {\n if (typeof item === 'string') {\n items.push(createWeighted<T>(item, itemOptions));\n } else {\n items.push(item);\n }\n }\n return section;\n }\n\n const prepend = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n prepend(item);\n });\n } else {\n if (typeof item === 'string') {\n items.unshift(createWeighted<T>(item, itemOptions));\n } else {\n items.unshift(item);\n }\n }\n return section;\n }\n\n const insert = (index: number, item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n insert(index, item);\n });\n } else {\n if (typeof item === 'string') {\n items.splice(index, 0, createWeighted<T>(item, itemOptions));\n } else {\n items.splice(index, 0, item);\n }\n }\n return section;\n }\n\n const remove = (index: number): Section<T> => {\n items.splice(index, 1);\n return section;\n }\n\n const replace = (index: number, item: T | Section<T> | string, options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (typeof item === 'string') {\n items[index] = createWeighted<T>(item, itemOptions);\n } else {\n items[index] = item;\n }\n return section;\n }\n\n const add = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n return append(item, itemOptions);\n }\n\n const section: Section<T> = {\n title: sectionOptions.title,\n items,\n weight: sectionOptions.weight,\n add,\n append,\n prepend,\n insert,\n remove,\n replace,\n }\n\n return section;\n}\n\n\n"],"names":["SectionOptionsSchema","z","object","title","string","optional","weight","number","itemWeight","parameters","ParametersSchema","default","create","options","items","sectionOptions","parse","sectionItemOptions","WeightedOptionsSchema","append","item","itemOptions","Array","isArray","forEach","push","createWeighted","section","prepend","unshift","insert","index","splice","remove","replace","add"],"mappings":";;;;AAiCaA,MAAAA,oBAAAA,GAAuBC,CAAEC,CAAAA,MAAM,CAAC;IACzCC,KAAOF,EAAAA,CAAAA,CAAEG,MAAM,EAAA,CAAGC,QAAQ,EAAA;IAC1BC,MAAQL,EAAAA,CAAAA,CAAEM,MAAM,EAAA,CAAGF,QAAQ,EAAA;IAC3BG,UAAYP,EAAAA,CAAAA,CAAEM,MAAM,EAAA,CAAGF,QAAQ,EAAA;AAC/BI,IAAAA,UAAAA,EAAYC,gBAAiBL,CAAAA,QAAQ,EAAGM,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAG;AAkCUC,MAAAA,MAAAA,GAAS,CAClBC,OAAAA,GAAmC,EAAE,GAAA;AAErC,IAAA,MAAMC,QAA4B,EAAE;IACpC,MAAMC,cAAAA,GAAiBf,oBAAqBgB,CAAAA,KAAK,CAACH,OAAAA,CAAAA;IAElD,MAAMI,kBAAAA,GAAqBC,qBAAsBF,CAAAA,KAAK,CAAC;AACnD,QAAA,GAAGD,cAAc;AACjBT,QAAAA,MAAAA,EAAQS,eAAeP;AAC3B,KAAA,CAAA;AAEA,IAAA,MAAMW,MAAS,GAAA,CAACC,IAA+DP,EAAAA,OAAAA,GAAoC,EAAE,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C,MAAA;YACHP,KAAK,CAACiB,MAAM,GAAGX,IAAAA;AACnB;QACA,OAAOO,OAAAA;AACX,KAAA;AAEA,IAAA,MAAMQ,GAAM,GAAA,CAACf,IAA+DP,EAAAA,OAAAA,GAAoC,EAAE,GAAA;QAC9G,IAAIQ,WAAAA,GAA+BH,qBAAsBF,CAAAA,KAAK,CAACH,OAAAA,CAAAA;QAC/DQ,WAAc,GAAA;AAAE,YAAA,GAAGJ,kBAAkB;AAAE,YAAA,GAAGI;AAAY,SAAA;AAEtD,QAAA,OAAOF,OAAOC,IAAMC,EAAAA,WAAAA,CAAAA;AACxB,KAAA;AAEA,IAAA,MAAMM,OAAsB,GAAA;AACxBxB,QAAAA,KAAAA,EAAOY,eAAeZ,KAAK;AAC3BW,QAAAA,KAAAA;AACAR,QAAAA,MAAAA,EAAQS,eAAeT,MAAM;AAC7B6B,QAAAA,GAAAA;AACAhB,QAAAA,MAAAA;AACAS,QAAAA,OAAAA;AACAE,QAAAA,MAAAA;AACAG,QAAAA,MAAAA;AACAC,QAAAA;AACJ,KAAA;IAEA,OAAOP,OAAAA;AACX;;;;"}
1
+ {"version":3,"file":"section.js","sources":["../../src/items/section.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ParametersSchema } from \"./parameters\";\nimport { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport interface Section<T extends Weighted> {\n title?: string;\n items: (T | Section<T>)[];\n weight?: number;\n add: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n append: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n prepend: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n insert: (\n index: number,\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n replace: (\n index: number,\n item: T | Section<T> | string,\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n remove: (index: number) => Section<T>;\n}\n\nexport const SectionOptionsSchema = z.object({\n title: z.string().optional(),\n weight: z.number().optional(),\n itemWeight: z.number().optional(),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type SectionOptions = z.infer<typeof SectionOptionsSchema>;\n\nexport const isSection = (object: any): boolean => {\n return object !== undefined && object != null && typeof object === 'object' && 'items' in object;\n}\n\nexport const convertToSection = (\n object: any,\n options: Partial<SectionOptions> = {}\n): Section<Weighted> => {\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n const weightedOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n if (isSection(object)) {\n const section = create({ ...sectionOptions, title: object.title });\n object.items.forEach((item: any) => {\n if (isSection(item)) {\n section.append(convertToSection(item, sectionOptions));\n } else {\n section.append(createWeighted(item.text, weightedOptions));\n }\n });\n return section;\n } else {\n throw new Error('Object is not a section');\n }\n}\n\nexport const create = <T extends Weighted>(\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n const items: (T | Section<T>)[] = [];\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n const sectionItemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n const append = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n append(item);\n });\n } else {\n if (typeof item === 'string') {\n items.push(createWeighted<T>(item, itemOptions));\n } else {\n items.push(item);\n }\n }\n return section;\n }\n\n const prepend = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n prepend(item);\n });\n } else {\n if (typeof item === 'string') {\n items.unshift(createWeighted<T>(item, itemOptions));\n } else {\n items.unshift(item);\n }\n }\n return section;\n }\n\n const insert = (index: number, item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n insert(index, item);\n });\n } else {\n if (typeof item === 'string') {\n items.splice(index, 0, createWeighted<T>(item, itemOptions));\n } else {\n items.splice(index, 0, item);\n }\n }\n return section;\n }\n\n const remove = (index: number): Section<T> => {\n items.splice(index, 1);\n return section;\n }\n\n const replace = (index: number, item: T | Section<T> | string, options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (typeof item === 'string') {\n items[index] = createWeighted<T>(item, itemOptions);\n } else {\n items[index] = item;\n }\n return section;\n }\n\n const add = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n return append(item, itemOptions);\n }\n\n const section: Section<T> = {\n title: sectionOptions.title,\n items,\n weight: sectionOptions.weight,\n add,\n append,\n prepend,\n insert,\n remove,\n replace,\n }\n\n return section;\n}\n\n\n"],"names":["SectionOptionsSchema","z","object","title","string","optional","weight","number","itemWeight","parameters","ParametersSchema","default","create","options","items","sectionOptions","parse","sectionItemOptions","WeightedOptionsSchema","append","item","itemOptions","Array","isArray","forEach","push","createWeighted","section","prepend","unshift","insert","index","splice","remove","replace","add"],"mappings":";;;;AAiCO,MAAMA,oBAAAA,GAAuBC,CAAAA,CAAEC,MAAM,CAAC;IACzCC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AEA,IAAA,MAAMM,OAAAA,GAAsB;AACxBxB,QAAAA,KAAAA,EAAOY,eAAeZ,KAAK;AAC3BW,QAAAA,KAAAA;AACAR,QAAAA,MAAAA,EAAQS,eAAeT,MAAM;AAC7B6B,QAAAA,GAAAA;AACAhB,QAAAA,MAAAA;AACAS,QAAAA,OAAAA;AACAE,QAAAA,MAAAA;AACAG,QAAAA,MAAAA;AACAC,QAAAA;AACJ,KAAA;IAEA,OAAOP,OAAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"trait.js","sources":["../../src/items/trait.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Trait = Weighted;\n\nexport const create = (text: string, options: WeightedOptions = {}): Trait => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Trait>(text, weightedOptions);\n}"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;MAIaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAA2B,EAAE,GAAA;IAC9D,MAAMC,eAAAA,GAAkBC,qBAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAAsBL,IAAME,EAAAA,eAAAA,CAAAA;AACvC;;;;"}
1
+ {"version":3,"file":"trait.js","sources":["../../src/items/trait.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Trait = Weighted;\n\nexport const create = (text: string, options: WeightedOptions = {}): Trait => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Trait>(text, weightedOptions);\n}"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;MAIaA,MAAAA,GAAS,CAACC,IAAAA,EAAcC,OAAAA,GAA2B,EAAE,GAAA;IAC9D,MAAMC,eAAAA,GAAkBC,qBAAAA,CAAsBC,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAAsBL,IAAAA,EAAME,eAAAA,CAAAA;AACvC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"weighted.js","sources":["../../src/items/weighted.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ParametersSchema, apply as applyParameters } from \"./parameters\";\n\nexport const WeightedSchema = z.object({\n text: z.string(),\n weight: z.number().optional(),\n});\n\nexport type Weighted = z.infer<typeof WeightedSchema>;\n\nexport const WeightedOptionsSchema = z.object({\n weight: z.number().optional(),\n parameters: ParametersSchema.optional(),\n});\n\nexport type WeightedOptions = z.infer<typeof WeightedOptionsSchema>;\n\n\nexport const create = <T extends Weighted>(\n text: string,\n options: Partial<WeightedOptions> = {}\n): T => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n const parameterizedText = applyParameters(text, weightedOptions.parameters);\n\n return {\n text: parameterizedText,\n weight: weightedOptions.weight,\n } as T;\n}"],"names":["z","object","text","string","weight","number","optional","WeightedOptionsSchema","parameters","ParametersSchema","create","options","weightedOptions","parse","parameterizedText","applyParameters"],"mappings":";;;AAG8BA,CAAEC,CAAAA,MAAM,CAAC;AACnCC,IAAAA,IAAAA,EAAMF,EAAEG,MAAM,EAAA;IACdC,MAAQJ,EAAAA,CAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ;AAC/B,CAAG;AAIUC,MAAAA,qBAAAA,GAAwBP,CAAEC,CAAAA,MAAM,CAAC;IAC1CG,MAAQJ,EAAAA,CAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC3BE,IAAAA,UAAAA,EAAYC,iBAAiBH,QAAQ;AACzC,CAAG;MAKUI,MAAS,GAAA,CAClBR,IACAS,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IAEtC,MAAMC,eAAAA,GAAkBL,qBAAsBM,CAAAA,KAAK,CAACF,OAAAA,CAAAA;AACpD,IAAA,MAAMG,iBAAoBC,GAAAA,KAAAA,CAAgBb,IAAMU,EAAAA,eAAAA,CAAgBJ,UAAU,CAAA;IAE1E,OAAO;QACHN,IAAMY,EAAAA,iBAAAA;AACNV,QAAAA,MAAAA,EAAQQ,gBAAgBR;AAC5B,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"weighted.js","sources":["../../src/items/weighted.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ParametersSchema, apply as applyParameters } from \"./parameters\";\n\nexport const WeightedSchema = z.object({\n text: z.string(),\n weight: z.number().optional(),\n});\n\nexport type Weighted = z.infer<typeof WeightedSchema>;\n\nexport const WeightedOptionsSchema = z.object({\n weight: z.number().optional(),\n parameters: ParametersSchema.optional(),\n});\n\nexport type WeightedOptions = z.infer<typeof WeightedOptionsSchema>;\n\n\nexport const create = <T extends Weighted>(\n text: string,\n options: Partial<WeightedOptions> = {}\n): T => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n const parameterizedText = applyParameters(text, weightedOptions.parameters);\n\n return {\n text: parameterizedText,\n weight: weightedOptions.weight,\n } as T;\n}"],"names":["z","object","text","string","weight","number","optional","WeightedOptionsSchema","parameters","ParametersSchema","create","options","weightedOptions","parse","parameterizedText","applyParameters"],"mappings":";;;AAG8BA,CAAAA,CAAEC,MAAM,CAAC;AACnCC,IAAAA,IAAAA,EAAMF,EAAEG,MAAM,EAAA;IACdC,MAAAA,EAAQJ,CAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ;AAC/B,CAAA;AAIO,MAAMC,qBAAAA,GAAwBP,CAAAA,CAAEC,MAAM,CAAC;IAC1CG,MAAAA,EAAQJ,CAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC3BE,IAAAA,UAAAA,EAAYC,iBAAiBH,QAAQ;AACzC,CAAA;MAKaI,MAAAA,GAAS,CAClBR,IAAAA,EACAS,OAAAA,GAAoC,EAAE,GAAA;IAEtC,MAAMC,eAAAA,GAAkBL,qBAAAA,CAAsBM,KAAK,CAACF,OAAAA,CAAAA;AACpD,IAAA,MAAMG,iBAAAA,GAAoBC,KAAAA,CAAgBb,IAAAA,EAAMU,eAAAA,CAAgBJ,UAAU,CAAA;IAE1E,OAAO;QACHN,IAAAA,EAAMY,iBAAAA;AACNV,QAAAA,MAAAA,EAAQQ,gBAAgBR;AAC5B,KAAA;AACJ;;;;"}
package/dist/loader.js CHANGED
@@ -9,6 +9,7 @@ import './formatter.js';
9
9
  import './parser.js';
10
10
  import './override.js';
11
11
  import './builder.js';
12
+ import './recipes.js';
12
13
  import { create as create$1 } from './util/storage.js';
13
14
 
14
15
  const OptionsSchema = z.object({
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sources":["../src/loader.ts"],"sourcesContent":["import path from \"path\";\nimport { z } from \"zod\";\nimport { DEFAULT_IGNORE_PATTERNS } from \"./constants\";\nimport { ParametersSchema } from \"./items/parameters\";\nimport { SectionOptions, SectionOptionsSchema } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Section, Weighted, createSection } from \"./riotprompt\";\nimport * as Storage from \"./util/storage\";\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),\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 load: <T extends Weighted>(contextDirectories?: string[], options?: SectionOptions) => Promise<Section<T>[]>;\n}\n\n/**\n * Extracts the first header from Markdown text\n * @param markdownText The Markdown text to parse\n * @returns The first header found in the Markdown or null if none is found\n */\nexport function extractFirstHeader(markdownText: string): string | null {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match && match[2]) {\n return match[2].trim();\n }\n\n return null;\n}\n\n/**\n * Removes the first header from Markdown text\n * @param markdownText The Markdown text to process\n * @returns The Markdown text without the first header\n */\nexport function removeFirstHeader(markdownText: string): string {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match) {\n return markdownText.replace(headerRegex, '').trim();\n }\n\n return markdownText;\n}\n\nexport const create = (loaderOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(loaderOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Loader');\n const ignorePatterns = options.ignorePatterns;\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 /**\n * Loads context from the provided directories and returns instruction sections\n * \n * @param contextDirectories Directories containing context files\n * @returns Array of instruction sections loaded from context directories\n */\n const load = async<T extends Weighted>(\n contextDirectories: string[] = [],\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const sectionOptions = loadOptions(options);\n\n logger.debug(`Loading context from ${contextDirectories}`);\n const contextSections: Section<T>[] = [];\n\n if (!contextDirectories || contextDirectories.length === 0) {\n logger.debug(`No context directories provided, returning empty context`);\n return contextSections;\n }\n\n const storage = Storage.create({ log: logger.debug });\n\n // Add context sections from each directory\n for (const contextDir of contextDirectories) {\n try {\n const dirName = path.basename(contextDir);\n logger.debug(`Processing context directory ${dirName}`);\n let mainContextSection: Section<T>;\n\n // First check if there's a context.md file\n const contextFile = path.join(contextDir, 'context.md');\n\n if (await storage.exists(contextFile)) {\n logger.debug(`Found context.md file in ${contextDir}`);\n const mainContextContent = await storage.readFile(contextFile, 'utf8');\n // Extract the first header from the Markdown content\n const firstHeader = extractFirstHeader(mainContextContent);\n\n // Use the header from context.md as the section title, or fallback to directory name\n const sectionTitle = firstHeader || dirName;\n mainContextSection = createSection<T>({ ...sectionOptions, title: sectionTitle });\n\n // Add content without the header\n if (firstHeader) {\n mainContextSection.add(removeFirstHeader(mainContextContent), { ...sectionOptions });\n } else {\n mainContextSection.add(mainContextContent, { ...sectionOptions });\n }\n } else {\n // If no context.md exists, use directory name as title\n mainContextSection = createSection<T>({ ...sectionOptions, title: dirName });\n }\n\n // Get all other files in the directory\n const files = await storage.listFiles(contextDir);\n const ignorePatternsRegex = ignorePatterns.map(pattern => new RegExp(pattern, 'i'));\n\n const filteredFiles = files.filter(file =>\n !ignorePatternsRegex.some(regex => regex.test(file))\n );\n\n for (const file of filteredFiles) {\n // Skip the context.md file as it's already processed\n if (file === 'context.md') continue;\n\n logger.debug(`Processing file ${file} in ${contextDir}`);\n const filePath = path.join(contextDir, file);\n if (await storage.isFile(filePath)) {\n const fileContent = await storage.readFile(filePath, 'utf8');\n let sectionName = file;\n let contentToAdd = fileContent;\n\n // Extract header if it exists\n if (file.endsWith('.md')) {\n const fileHeader = extractFirstHeader(fileContent);\n if (fileHeader) {\n sectionName = fileHeader;\n // Remove the header from the content\n contentToAdd = removeFirstHeader(fileContent);\n }\n }\n\n // Create a subsection with the extracted name\n const fileSection = createSection<T>({ ...sectionOptions, title: sectionName });\n fileSection.add(contentToAdd, { ...sectionOptions });\n\n // Add this file section to the main context section\n mainContextSection.add(fileSection as unknown as T, { ...sectionOptions });\n }\n }\n\n contextSections.push(mainContextSection);\n } catch (error) {\n logger.error(`Error processing context directory ${contextDir}: ${error}`);\n }\n }\n\n return contextSections;\n }\n\n\n return {\n load\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","ignorePatterns","array","string","DEFAULT_IGNORE_PATTERNS","parameters","ParametersSchema","extractFirstHeader","markdownText","headerRegex","match","trim","removeFirstHeader","replace","create","loaderOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","load","contextDirectories","debug","contextSections","length","storage","Storage","log","contextDir","dirName","path","basename","mainContextSection","contextFile","join","exists","mainContextContent","readFile","firstHeader","sectionTitle","createSection","title","add","files","listFiles","ignorePatternsRegex","map","pattern","RegExp","filteredFiles","filter","file","some","regex","test","filePath","isFile","fileContent","sectionName","contentToAdd","endsWith","fileHeader","fileSection","push","error"],"mappings":";;;;;;;;;;;;;AASA,MAAMA,aAAAA,GAAgBC,CAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;IACnCC,cAAgBP,EAAAA,CAAAA,CAAEQ,KAAK,CAACR,CAAAA,CAAES,MAAM,EAAIL,CAAAA,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAACK,uBAAAA,CAAAA;AACvDC,IAAAA,UAAAA,EAAYC,gBAAiBR,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAUA;;;;IAKO,SAASQ,kBAAAA,CAAmBC,YAAoB,EAAA;;AAEnD,IAAA,MAAMC,WAAc,GAAA,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAaE,CAAAA,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAASA,IAAAA,KAAK,CAAC,CAAA,CAAE,EAAE;AACnB,QAAA,OAAOA,KAAK,CAAC,CAAE,CAAA,CAACC,IAAI,EAAA;AACxB;IAEA,OAAO,IAAA;AACX;AAEA;;;;IAKO,SAASC,iBAAAA,CAAkBJ,YAAoB,EAAA;;AAElD,IAAA,MAAMC,WAAc,GAAA,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAaE,CAAAA,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAAO,EAAA;AACP,QAAA,OAAOF,YAAaK,CAAAA,OAAO,CAACJ,WAAAA,EAAa,IAAIE,IAAI,EAAA;AACrD;IAEA,OAAOH,YAAAA;AACX;AAEO,MAAMM,SAAS,CAACC,aAAAA,GAAAA;AACnB,IAAA,M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AGlDe,kBAAmBU,CAAAA,GAAG,CAACoB,WAA6B,EAAA;AAAE,4BAAA,GAAG7C;AAAe,yBAAA,CAAA;AAC5E;AACJ;AAEAM,gBAAAA,eAAAA,CAAgBwC,IAAI,CAAC/B,kBAAAA,CAAAA;AACzB,aAAA,CAAE,OAAOgC,KAAO,EAAA;gBACZvE,MAAOuE,CAAAA,KAAK,CAAC,CAAC,mCAAmC,EAAEpC,UAAW,CAAA,EAAE,EAAEoC,KAAO,CAAA,CAAA,CAAA;AAC7E;AACJ;QAEA,OAAOzC,eAAAA;AACX,KAAA;IAGA,OAAO;AACHH,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"loader.js","sources":["../src/loader.ts"],"sourcesContent":["import path from \"path\";\nimport { z } from \"zod\";\nimport { DEFAULT_IGNORE_PATTERNS } from \"./constants\";\nimport { ParametersSchema } from \"./items/parameters\";\nimport { SectionOptions, SectionOptionsSchema } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Section, Weighted, createSection } from \"./riotprompt\";\nimport * as Storage from \"./util/storage\";\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),\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 load: <T extends Weighted>(contextDirectories?: string[], options?: SectionOptions) => Promise<Section<T>[]>;\n}\n\n/**\n * Extracts the first header from Markdown text\n * @param markdownText The Markdown text to parse\n * @returns The first header found in the Markdown or null if none is found\n */\nexport function extractFirstHeader(markdownText: string): string | null {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match && match[2]) {\n return match[2].trim();\n }\n\n return null;\n}\n\n/**\n * Removes the first header from Markdown text\n * @param markdownText The Markdown text to process\n * @returns The Markdown text without the first header\n */\nexport function removeFirstHeader(markdownText: string): string {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match) {\n return markdownText.replace(headerRegex, '').trim();\n }\n\n return markdownText;\n}\n\nexport const create = (loaderOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(loaderOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Loader');\n const ignorePatterns = options.ignorePatterns;\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 /**\n * Loads context from the provided directories and returns instruction sections\n * \n * @param contextDirectories Directories containing context files\n * @returns Array of instruction sections loaded from context directories\n */\n const load = async<T extends Weighted>(\n contextDirectories: string[] = [],\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const sectionOptions = loadOptions(options);\n\n logger.debug(`Loading context from ${contextDirectories}`);\n const contextSections: Section<T>[] = [];\n\n if (!contextDirectories || contextDirectories.length === 0) {\n logger.debug(`No context directories provided, returning empty context`);\n return contextSections;\n }\n\n const storage = Storage.create({ log: logger.debug });\n\n // Add context sections from each directory\n for (const contextDir of contextDirectories) {\n try {\n const dirName = path.basename(contextDir);\n logger.debug(`Processing context directory ${dirName}`);\n let mainContextSection: Section<T>;\n\n // First check if there's a context.md file\n const contextFile = path.join(contextDir, 'context.md');\n\n if (await storage.exists(contextFile)) {\n logger.debug(`Found context.md file in ${contextDir}`);\n const mainContextContent = await storage.readFile(contextFile, 'utf8');\n // Extract the first header from the Markdown content\n const firstHeader = extractFirstHeader(mainContextContent);\n\n // Use the header from context.md as the section title, or fallback to directory name\n const sectionTitle = firstHeader || dirName;\n mainContextSection = createSection<T>({ ...sectionOptions, title: sectionTitle });\n\n // Add content without the header\n if (firstHeader) {\n mainContextSection.add(removeFirstHeader(mainContextContent), { ...sectionOptions });\n } else {\n mainContextSection.add(mainContextContent, { ...sectionOptions });\n }\n } else {\n // If no context.md exists, use directory name as title\n mainContextSection = createSection<T>({ ...sectionOptions, title: dirName });\n }\n\n // Get all other files in the directory\n const files = await storage.listFiles(contextDir);\n const ignorePatternsRegex = ignorePatterns.map(pattern => new RegExp(pattern, 'i'));\n\n const filteredFiles = files.filter(file =>\n !ignorePatternsRegex.some(regex => regex.test(file))\n );\n\n for (const file of filteredFiles) {\n // Skip the context.md file as it's already processed\n if (file === 'context.md') continue;\n\n logger.debug(`Processing file ${file} in ${contextDir}`);\n const filePath = path.join(contextDir, file);\n if (await storage.isFile(filePath)) {\n const fileContent = await storage.readFile(filePath, 'utf8');\n let sectionName = file;\n let contentToAdd = fileContent;\n\n // Extract header if it exists\n if (file.endsWith('.md')) {\n const fileHeader = extractFirstHeader(fileContent);\n if (fileHeader) {\n sectionName = fileHeader;\n // Remove the header from the content\n contentToAdd = removeFirstHeader(fileContent);\n }\n }\n\n // Create a subsection with the extracted name\n const fileSection = createSection<T>({ ...sectionOptions, title: sectionName });\n fileSection.add(contentToAdd, { ...sectionOptions });\n\n // Add this file section to the main context section\n mainContextSection.add(fileSection as unknown as T, { ...sectionOptions });\n }\n }\n\n contextSections.push(mainContextSection);\n } catch (error) {\n logger.error(`Error processing context directory ${contextDir}: ${error}`);\n }\n }\n\n return contextSections;\n }\n\n\n return {\n load\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","ignorePatterns","array","string","DEFAULT_IGNORE_PATTERNS","parameters","ParametersSchema","extractFirstHeader","markdownText","headerRegex","match","trim","removeFirstHeader","replace","create","loaderOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","load","contextDirectories","debug","contextSections","length","storage","Storage","log","contextDir","dirName","path","basename","mainContextSection","contextFile","join","exists","mainContextContent","readFile","firstHeader","sectionTitle","createSection","title","add","files","listFiles","ignorePatternsRegex","map","pattern","RegExp","filteredFiles","filter","file","some","regex","test","filePath","isFile","fileContent","sectionName","contentToAdd","endsWith","fileHeader","fileSection","push","error"],"mappings":";;;;;;;;;;;;;;AASA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;IACnCC,cAAAA,EAAgBP,CAAAA,CAAEQ,KAAK,CAACR,CAAAA,CAAES,MAAM,EAAA,CAAA,CAAIL,QAAQ,EAAA,CAAGC,OAAO,CAACK,uBAAAA,CAAAA;AACvDC,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBR,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAUA;;;;IAKO,SAASQ,kBAAAA,CAAmBC,YAAoB,EAAA;;AAEnD,IAAA,MAAMC,WAAAA,GAAc,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAAA,CAAaE,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAAAA,IAASA,KAAK,CAAC,CAAA,CAAE,EAAE;AACnB,QAAA,OAAOA,KAAK,CAAC,CAAA,CAAE,CAACC,IAAI,EAAA;AACxB,IAAA;IAEA,OAAO,IAAA;AACX;AAEA;;;;IAKO,SAASC,iBAAAA,CAAkBJ,YAAoB,EAAA;;AAElD,IAAA,MAAMC,WAAAA,GAAc,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAAA,CAAaE,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAAAA,EAAO;AACP,QAAA,OAAOF,YAAAA,CAAaK,OAAO,CAACJ,WAAAA,EAAa,IAAIE,IAAI,EAAA;AACrD,IAAA;IAEA,OA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AE,4BAAA,GAAGvB,cAAc;4BAAEwB,KAAAA,EAAOiB;AAAY,yBAAA,CAAA;wBAC7EI,WAAAA,CAAYpB,GAAG,CAACiB,YAAAA,EAAc;AAAE,4BAAA,GAAG1C;AAAe,yBAAA,CAAA;;wBAGlDe,kBAAAA,CAAmBU,GAAG,CAACoB,WAAAA,EAA6B;AAAE,4BAAA,GAAG7C;AAAe,yBAAA,CAAA;AAC5E,oBAAA;AACJ,gBAAA;AAEAM,gBAAAA,eAAAA,CAAgBwC,IAAI,CAAC/B,kBAAAA,CAAAA;AACzB,YAAA,CAAA,CAAE,OAAOgC,KAAAA,EAAO;gBACZvE,MAAAA,CAAOuE,KAAK,CAAC,CAAC,mCAAmC,EAAEpC,UAAAA,CAAW,EAAE,EAAEoC,KAAAA,CAAAA,CAAO,CAAA;AAC7E,YAAA;AACJ,QAAA;QAEA,OAAOzC,eAAAA;AACX,IAAA,CAAA;IAGA,OAAO;AACHH,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { LIBRARY_NAME } from \"./constants\";\n\nexport interface Logger {\n name: string;\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n}\n\nexport const DEFAULT_LOGGER: Logger = {\n name: 'default',\n debug: (message: string, ...args: any[]) => console.debug(message, ...args),\n info: (message: string, ...args: any[]) => console.info(message, ...args),\n warn: (message: string, ...args: any[]) => console.warn(message, ...args),\n error: (message: string, ...args: any[]) => console.error(message, ...args),\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n verbose: (message: string, ...args: any[]) => { },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n silly: (message: string, ...args: any[]) => { },\n}\n\nexport const wrapLogger = (toWrap: Logger, name?: string): Logger => {\n\n const requiredMethods: (keyof Logger)[] = ['debug', 'info', 'warn', 'error', 'verbose', 'silly'];\n const missingMethods = requiredMethods.filter(method => typeof toWrap[method] !== 'function');\n\n if (missingMethods.length > 0) {\n throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);\n }\n\n const log = (level: keyof Logger, message: string, ...args: any[]) => {\n message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;\n\n if (level === 'debug') toWrap.debug(message, ...args);\n else if (level === 'info') toWrap.info(message, ...args);\n else if (level === 'warn') toWrap.warn(message, ...args);\n else if (level === 'error') toWrap.error(message, ...args);\n else if (level === 'verbose') toWrap.verbose(message, ...args);\n else if (level === 'silly') toWrap.silly(message, ...args);\n }\n\n return {\n name: 'wrapped',\n debug: (message: string, ...args: any[]) => log('debug', message, ...args),\n info: (message: string, ...args: any[]) => log('info', message, ...args),\n warn: (message: string, ...args: any[]) => log('warn', message, ...args),\n error: (message: string, ...args: any[]) => log('error', message, ...args),\n verbose: (message: string, ...args: any[]) => log('verbose', message, ...args),\n silly: (message: string, ...args: any[]) => log('silly', message, ...args),\n }\n}"],"names":["DEFAULT_LOGGER","name","debug","message","args","console","info","warn","error","verbose","silly","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","join","log","level","LIBRARY_NAME"],"mappings":";;MAaaA,cAAyB,GAAA;IAClCC,IAAM,EAAA,SAAA;AACNC,IAAAA,KAAAA,EAAO,CAACC,OAAiB,EAAA,GAAGC,OAAgBC,OAAQH,CAAAA,KAAK,CAACC,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACtEE,IAAAA,IAAAA,EAAM,CAACH,OAAiB,EAAA,GAAGC,OAAgBC,OAAQC,CAAAA,IAAI,CAACH,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACpEG,IAAAA,IAAAA,EAAM,CAACJ,OAAiB,EAAA,GAAGC,OAAgBC,OAAQE,CAAAA,IAAI,CAACJ,OAAYC,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AAA,CAAI,SAASjB,OAAYC,EAAAA,GAAAA,IAAAA;AACzE,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { LIBRARY_NAME } from \"./constants\";\n\nexport interface Logger {\n name: string;\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n}\n\nexport const DEFAULT_LOGGER: Logger = {\n name: 'default',\n debug: (message: string, ...args: any[]) => console.debug(message, ...args),\n info: (message: string, ...args: any[]) => console.info(message, ...args),\n warn: (message: string, ...args: any[]) => console.warn(message, ...args),\n error: (message: string, ...args: any[]) => console.error(message, ...args),\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n verbose: (message: string, ...args: any[]) => { },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n silly: (message: string, ...args: any[]) => { },\n}\n\nexport const wrapLogger = (toWrap: Logger, name?: string): Logger => {\n\n const requiredMethods: (keyof Logger)[] = ['debug', 'info', 'warn', 'error', 'verbose', 'silly'];\n const missingMethods = requiredMethods.filter(method => typeof toWrap[method] !== 'function');\n\n if (missingMethods.length > 0) {\n throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);\n }\n\n const log = (level: keyof Logger, message: string, ...args: any[]) => {\n message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;\n\n if (level === 'debug') toWrap.debug(message, ...args);\n else if (level === 'info') toWrap.info(message, ...args);\n else if (level === 'warn') toWrap.warn(message, ...args);\n else if (level === 'error') toWrap.error(message, ...args);\n else if (level === 'verbose') toWrap.verbose(message, ...args);\n else if (level === 'silly') toWrap.silly(message, ...args);\n }\n\n return {\n name: 'wrapped',\n debug: (message: string, ...args: any[]) => log('debug', message, ...args),\n info: (message: string, ...args: any[]) => log('info', message, ...args),\n warn: (message: string, ...args: any[]) => log('warn', message, ...args),\n error: (message: string, ...args: any[]) => log('error', message, ...args),\n verbose: (message: string, ...args: any[]) => log('verbose', message, ...args),\n silly: (message: string, ...args: any[]) => log('silly', message, ...args),\n }\n}"],"names":["DEFAULT_LOGGER","name","debug","message","args","console","info","warn","error","verbose","silly","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","join","log","level","LIBRARY_NAME"],"mappings":";;MAaaA,cAAAA,GAAyB;IAClCC,IAAAA,EAAM,SAAA;AACNC,IAAAA,KAAAA,EAAO,CAACC,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQH,KAAK,CAACC,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACtEE,IAAAA,IAAAA,EAAM,CAACH,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQC,IAAI,CAACH,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACpEG,IAAAA,IAAAA,EAAM,CAACJ,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQE,IAAI,CAACJ,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACpEI,IAAAA,KAAAA,EAAO,CAACL,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQG,KAAK,CAACL,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;;IAEtEK,OAAAA,EAAS,CAACN,OAAAA,EAAiB,GAAGC,IAAAA,GAAAA,CAAkB,CAAA;;IAEhDM,KAAAA,EAAO,CAACP,OAAAA,EAAiB,GAAGC,IAAAA,GAAAA,CAAkB;AAClD;AAEO,MAAMO,UAAAA,GAAa,CAACC,MAAAA,EAAgBX,IAAAA,GAAAA;AAEvC,IAAA,MAAMY,eAAAA,GAAoC;AAAC,QAAA,OAAA;AAAS,QAAA,MAAA;AAAQ,QAAA,MAAA;AAAQ,QAAA,OAAA;AAAS,QAAA,SAAA;AAAW,QAAA;AAAQ,KAAA;IAChG,MAAMC,cAAAA,GAAiBD,e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EAAM,SAAA;AACNC,QAAAA,KAAAA,EAAO,CAACC,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,SAASjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACrEE,QAAAA,IAAAA,EAAM,CAACH,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,QAAQjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACnEG,QAAAA,IAAAA,EAAM,CAACJ,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,QAAQjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACnEI,QAAAA,KAAAA,EAAO,CAACL,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,SAASjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACrEK,QAAAA,OAAAA,EAAS,CAACN,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,WAAWjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACzEM,QAAAA,KAAAA,EAAO,CAACP,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,SAASjB,OAAAA,EAAAA,GAAYC,IAAAA;AACzE,KAAA;AACJ;;;;"}
@@ -3,18 +3,18 @@ import { SectionOptions } from './items/section';
3
3
  import { Section, Weighted } from './riotprompt';
4
4
  declare const OptionsSchema: z.ZodObject<{
5
5
  logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
6
- configDir: z.ZodDefault<z.ZodString>;
6
+ configDirs: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
7
7
  overrides: z.ZodDefault<z.ZodBoolean>;
8
8
  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">]>>>>;
9
9
  }, "strip", z.ZodTypeAny, {
10
10
  parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
11
- configDir: string;
11
+ configDirs: string[];
12
12
  overrides: boolean;
13
13
  logger?: any;
14
14
  }, {
15
15
  parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
16
16
  logger?: any;
17
- configDir?: string | undefined;
17
+ configDirs?: string[] | undefined;
18
18
  overrides?: boolean | undefined;
19
19
  }>;
20
20
  export type Options = z.infer<typeof OptionsSchema>;
@@ -23,8 +23,8 @@ export interface Instance {
23
23
  customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;
24
24
  override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<{
25
25
  override?: Section<T>;
26
- prepend?: Section<T>;
27
- append?: Section<T>;
26
+ prepends: Section<T>[];
27
+ appends: Section<T>[];
28
28
  }>;
29
29
  }
30
30
  export declare const create: (overrideOptions?: OptionsParam) => Instance;
package/dist/override.js CHANGED
@@ -8,11 +8,14 @@ import { create as create$1 } from './formatter.js';
8
8
  import { create as create$3 } from './parser.js';
9
9
  import './loader.js';
10
10
  import './builder.js';
11
+ import './recipes.js';
11
12
  import { create as create$2 } from './util/storage.js';
12
13
 
13
14
  const OptionsSchema = z.object({
14
15
  logger: z.any().optional().default(DEFAULT_LOGGER),
15
- configDir: z.string().default('./overrides'),
16
+ configDirs: z.array(z.string()).default([
17
+ './overrides'
18
+ ]),
16
19
  overrides: z.boolean().default(false),
17
20
  parameters: ParametersSchema.optional().default({})
18
21
  });
@@ -35,42 +38,54 @@ const create = (overrideOptions = {})=>{
35
38
  };
36
39
  const override = async (overrideFile, section, sectionOptions = {})=>{
37
40
  const currentSectionOptions = loadOptions(sectionOptions);
38
- const baseFile = path__default.join(options.configDir, overrideFile);
39
- const preFile = baseFile.replace('.md', '-pre.md');
40
- const postFile = baseFile.replace('.md', '-post.md');
41
- const response = {};
42
- if (await storage.exists(preFile)) {
43
- logger.silly('Found pre file %s', preFile);
44
- const parser$1 = create$3({
45
- logger
46
- });
47
- response.prepend = await parser$1.parseFile(preFile, currentSectionOptions);
48
- }
49
- if (await storage.exists(postFile)) {
50
- logger.silly('Found post file %s', postFile);
51
- const parser$1 = create$3({
52
- logger
53
- });
54
- response.append = await parser$1.parseFile(postFile, currentSectionOptions);
55
- }
56
- if (await storage.exists(baseFile)) {
57
- logger.silly('Found base file %s', baseFile);
58
- if (options.overrides) {
59
- logger.warn('WARNING: Core directives are being overwritten by custom configuration');
41
+ const response = {
42
+ prepends: [],
43
+ appends: []
44
+ };
45
+ // Process directories in order (closest to furthest)
46
+ for(let i = 0; i < options.configDirs.length; i++){
47
+ const configDir = options.configDirs[i];
48
+ const baseFile = path__default.join(configDir, overrideFile);
49
+ const preFile = baseFile.replace('.md', '-pre.md');
50
+ const postFile = baseFile.replace('.md', '-post.md');
51
+ // Check for prepend files (-pre.md)
52
+ if (await storage.exists(preFile)) {
53
+ logger.silly('Found pre file %s (layer %d)', preFile, i + 1);
60
54
  const parser$1 = create$3({
61
55
  logger
62
56
  });
63
- response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
64
- } else {
65
- logger.error('ERROR: Core directives are being overwritten by custom configuration');
66
- throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
57
+ const prependSection = await parser$1.parseFile(preFile, currentSectionOptions);
58
+ response.prepends.push(prependSection);
59
+ }
60
+ // Check for append files (-post.md)
61
+ if (await storage.exists(postFile)) {
62
+ logger.silly('Found post file %s (layer %d)', postFile, i + 1);
63
+ const parser$1 = create$3({
64
+ logger
65
+ });
66
+ const appendSection = await parser$1.parseFile(postFile, currentSectionOptions);
67
+ response.appends.push(appendSection);
68
+ }
69
+ // Check for complete override files - use the first (closest) one found
70
+ if (!response.override && await storage.exists(baseFile)) {
71
+ logger.silly('Found base file %s (layer %d)', baseFile, i + 1);
72
+ if (options.overrides) {
73
+ logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);
74
+ const parser$1 = create$3({
75
+ logger
76
+ });
77
+ response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
78
+ } else {
79
+ logger.error('ERROR: Core directives are being overwritten by custom configuration');
80
+ throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
81
+ }
67
82
  }
68
83
  }
69
84
  return response;
70
85
  };
71
86
  const customize = async (overrideFile, section, sectionOptions = {})=>{
72
87
  const currentSectionOptions = loadOptions(sectionOptions);
73
- const { overrideContent, prepend, append } = await override(overrideFile, section, currentSectionOptions);
88
+ const { override: overrideContent, prepends, appends } = await override(overrideFile, section, currentSectionOptions);
74
89
  let finalSection = section;
75
90
  if (overrideContent) {
76
91
  if (options.overrides) {
@@ -81,11 +96,13 @@ const create = (overrideOptions = {})=>{
81
96
  throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
82
97
  }
83
98
  }
84
- if (prepend) {
99
+ // Apply prepends in order (closest layer first)
100
+ for (const prepend of prepends){
85
101
  logger.silly('Prepend found, adding to content from file %s', prepend);
86
102
  finalSection = finalSection.prepend(prepend);
87
103
  }
88
- if (append) {
104
+ // Apply appends in reverse order (furthest layers first, then closest)
105
+ for (const append of appends.reverse()){
89
106
  logger.silly('Append found, adding to content from file %s', append);
90
107
  finalSection = finalSection.append(append);
91
108
  }