@riotprompt/riotprompt 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +54 -470
  2. package/dist/builder.d.ts +3 -3
  3. package/dist/builder.js +7 -2
  4. package/dist/builder.js.map +1 -1
  5. package/dist/chat.js.map +1 -1
  6. package/dist/constants.js.map +1 -1
  7. package/dist/formatter.js.map +1 -1
  8. package/dist/items/content.js.map +1 -1
  9. package/dist/items/context.js.map +1 -1
  10. package/dist/items/instruction.js.map +1 -1
  11. package/dist/items/parameters.js.map +1 -1
  12. package/dist/items/section.js.map +1 -1
  13. package/dist/items/trait.js.map +1 -1
  14. package/dist/items/weighted.js.map +1 -1
  15. package/dist/loader.js +1 -0
  16. package/dist/loader.js.map +1 -1
  17. package/dist/logger.js +4 -2
  18. package/dist/logger.js.map +1 -1
  19. package/dist/override.d.ts +5 -5
  20. package/dist/override.js +47 -30
  21. package/dist/override.js.map +1 -1
  22. package/dist/parse/markdown.js.map +1 -1
  23. package/dist/parse/text.js.map +1 -1
  24. package/dist/parser.js.map +1 -1
  25. package/dist/prompt.js.map +1 -1
  26. package/dist/recipes.d.ts +405 -0
  27. package/dist/recipes.js +424 -0
  28. package/dist/recipes.js.map +1 -0
  29. package/dist/riotprompt.cjs +586 -132
  30. package/dist/riotprompt.cjs.map +1 -1
  31. package/dist/riotprompt.d.ts +3 -0
  32. package/dist/riotprompt.js +3 -0
  33. package/dist/riotprompt.js.map +1 -1
  34. package/dist/util/general.js.map +1 -1
  35. package/dist/util/markdown.js.map +1 -1
  36. package/dist/util/storage.js.map +1 -1
  37. package/dist/util/text.js.map +1 -1
  38. package/package.json +35 -28
  39. package/.gitcarve/config.yaml +0 -10
  40. package/.gitcarve/context/content.md +0 -11
  41. package/.markdown-doctest-setup.mjs +0 -23
  42. package/.nvmrc +0 -1
  43. package/dist/builder.cjs +0 -152
  44. package/dist/builder.cjs.map +0 -1
  45. package/dist/chat.cjs +0 -26
  46. package/dist/chat.cjs.map +0 -1
  47. package/dist/constants.cjs +0 -34
  48. package/dist/constants.cjs.map +0 -1
  49. package/dist/formatter.cjs +0 -139
  50. package/dist/formatter.cjs.map +0 -1
  51. package/dist/items/content.cjs +0 -14
  52. package/dist/items/content.cjs.map +0 -1
  53. package/dist/items/context.cjs +0 -13
  54. package/dist/items/context.cjs.map +0 -1
  55. package/dist/items/instruction.cjs +0 -13
  56. package/dist/items/instruction.cjs.map +0 -1
  57. package/dist/items/parameters.cjs +0 -53
  58. package/dist/items/parameters.cjs.map +0 -1
  59. package/dist/items/section.cjs +0 -120
  60. package/dist/items/section.cjs.map +0 -1
  61. package/dist/items/trait.cjs +0 -13
  62. package/dist/items/trait.cjs.map +0 -1
  63. package/dist/items/weighted.cjs +0 -27
  64. package/dist/items/weighted.cjs.map +0 -1
  65. package/dist/loader.cjs +0 -167
  66. package/dist/loader.cjs.map +0 -1
  67. package/dist/logger.cjs +0 -51
  68. package/dist/logger.cjs.map +0 -1
  69. package/dist/override.cjs +0 -109
  70. package/dist/override.cjs.map +0 -1
  71. package/dist/parse/markdown.cjs +0 -114
  72. package/dist/parse/markdown.cjs.map +0 -1
  73. package/dist/parse/text.cjs +0 -33
  74. package/dist/parse/text.cjs.map +0 -1
  75. package/dist/parser.cjs +0 -99
  76. package/dist/parser.cjs.map +0 -1
  77. package/dist/prompt.cjs +0 -15
  78. package/dist/prompt.cjs.map +0 -1
  79. package/dist/util/general.cjs +0 -52
  80. package/dist/util/general.cjs.map +0 -1
  81. package/dist/util/markdown.cjs +0 -115
  82. package/dist/util/markdown.cjs.map +0 -1
  83. package/dist/util/storage.cjs +0 -155
  84. package/dist/util/storage.cjs.map +0 -1
  85. package/dist/util/text.cjs +0 -42
  86. package/dist/util/text.cjs.map +0 -1
  87. package/docs/loader.md +0 -237
  88. package/docs/override.md +0 -323
  89. package/docs/parser.md +0 -130
  90. package/eslint.config.mjs +0 -82
  91. package/nodemon.json +0 -14
  92. package/vite.config.ts +0 -114
  93. package/vitest.config.ts +0 -25
package/dist/loader.cjs DELETED
@@ -1,167 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const path = require('path');
6
- const zod = require('zod');
7
- const constants = require('./constants.cjs');
8
- const parameters = require('./items/parameters.cjs');
9
- const section = require('./items/section.cjs');
10
- const logger = require('./logger.cjs');
11
- require('./items/weighted.cjs');
12
- require('./formatter.cjs');
13
- require('./parser.cjs');
14
- require('./override.cjs');
15
- require('./builder.cjs');
16
- const storage = require('./util/storage.cjs');
17
-
18
- const OptionsSchema = zod.z.object({
19
- logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
20
- ignorePatterns: zod.z.array(zod.z.string()).optional().default(constants.DEFAULT_IGNORE_PATTERNS),
21
- parameters: parameters.ParametersSchema.optional().default({})
22
- });
23
- /**
24
- * Extracts the first header from Markdown text
25
- * @param markdownText The Markdown text to parse
26
- * @returns The first header found in the Markdown or null if none is found
27
- */ function extractFirstHeader(markdownText) {
28
- // Regular expression to match Markdown headers (# Header, ## Header, etc.)
29
- const headerRegex = /^(#{1,6})\s+(.+?)(?:\n|$)/m;
30
- const match = markdownText.match(headerRegex);
31
- if (match && match[2]) {
32
- return match[2].trim();
33
- }
34
- return null;
35
- }
36
- /**
37
- * Removes the first header from Markdown text
38
- * @param markdownText The Markdown text to process
39
- * @returns The Markdown text without the first header
40
- */ function removeFirstHeader(markdownText) {
41
- // Regular expression to match Markdown headers (# Header, ## Header, etc.)
42
- const headerRegex = /^(#{1,6})\s+(.+?)(?:\n|$)/m;
43
- const match = markdownText.match(headerRegex);
44
- if (match) {
45
- return markdownText.replace(headerRegex, '').trim();
46
- }
47
- return markdownText;
48
- }
49
- const create = (loaderOptions)=>{
50
- const options = OptionsSchema.parse(loaderOptions || {});
51
- const parameters = options.parameters;
52
- const logger$1 = logger.wrapLogger(options.logger, 'Loader');
53
- const ignorePatterns = options.ignorePatterns;
54
- const loadOptions = (sectionOptions = {})=>{
55
- const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
56
- return {
57
- ...currentOptions,
58
- parameters: {
59
- ...parameters,
60
- ...currentOptions.parameters
61
- }
62
- };
63
- };
64
- /**
65
- * Loads context from the provided directories and returns instruction sections
66
- *
67
- * @param contextDirectories Directories containing context files
68
- * @returns Array of instruction sections loaded from context directories
69
- */ const load = async (contextDirectories = [], options = {})=>{
70
- const sectionOptions = loadOptions(options);
71
- logger$1.debug(`Loading context from ${contextDirectories}`);
72
- const contextSections = [];
73
- if (!contextDirectories || contextDirectories.length === 0) {
74
- logger$1.debug(`No context directories provided, returning empty context`);
75
- return contextSections;
76
- }
77
- const storage$1 = storage.create({
78
- log: logger$1.debug
79
- });
80
- // Add context sections from each directory
81
- for (const contextDir of contextDirectories){
82
- try {
83
- const dirName = path.basename(contextDir);
84
- logger$1.debug(`Processing context directory ${dirName}`);
85
- let mainContextSection;
86
- // First check if there's a context.md file
87
- const contextFile = path.join(contextDir, 'context.md');
88
- if (await storage$1.exists(contextFile)) {
89
- logger$1.debug(`Found context.md file in ${contextDir}`);
90
- const mainContextContent = await storage$1.readFile(contextFile, 'utf8');
91
- // Extract the first header from the Markdown content
92
- const firstHeader = extractFirstHeader(mainContextContent);
93
- // Use the header from context.md as the section title, or fallback to directory name
94
- const sectionTitle = firstHeader || dirName;
95
- mainContextSection = section.create({
96
- ...sectionOptions,
97
- title: sectionTitle
98
- });
99
- // Add content without the header
100
- if (firstHeader) {
101
- mainContextSection.add(removeFirstHeader(mainContextContent), {
102
- ...sectionOptions
103
- });
104
- } else {
105
- mainContextSection.add(mainContextContent, {
106
- ...sectionOptions
107
- });
108
- }
109
- } else {
110
- // If no context.md exists, use directory name as title
111
- mainContextSection = section.create({
112
- ...sectionOptions,
113
- title: dirName
114
- });
115
- }
116
- // Get all other files in the directory
117
- const files = await storage$1.listFiles(contextDir);
118
- const ignorePatternsRegex = ignorePatterns.map((pattern)=>new RegExp(pattern, 'i'));
119
- const filteredFiles = files.filter((file)=>!ignorePatternsRegex.some((regex)=>regex.test(file)));
120
- for (const file of filteredFiles){
121
- // Skip the context.md file as it's already processed
122
- if (file === 'context.md') continue;
123
- logger$1.debug(`Processing file ${file} in ${contextDir}`);
124
- const filePath = path.join(contextDir, file);
125
- if (await storage$1.isFile(filePath)) {
126
- const fileContent = await storage$1.readFile(filePath, 'utf8');
127
- let sectionName = file;
128
- let contentToAdd = fileContent;
129
- // Extract header if it exists
130
- if (file.endsWith('.md')) {
131
- const fileHeader = extractFirstHeader(fileContent);
132
- if (fileHeader) {
133
- sectionName = fileHeader;
134
- // Remove the header from the content
135
- contentToAdd = removeFirstHeader(fileContent);
136
- }
137
- }
138
- // Create a subsection with the extracted name
139
- const fileSection = section.create({
140
- ...sectionOptions,
141
- title: sectionName
142
- });
143
- fileSection.add(contentToAdd, {
144
- ...sectionOptions
145
- });
146
- // Add this file section to the main context section
147
- mainContextSection.add(fileSection, {
148
- ...sectionOptions
149
- });
150
- }
151
- }
152
- contextSections.push(mainContextSection);
153
- } catch (error) {
154
- logger$1.error(`Error processing context directory ${contextDir}: ${error}`);
155
- }
156
- }
157
- return contextSections;
158
- };
159
- return {
160
- load
161
- };
162
- };
163
-
164
- exports.create = create;
165
- exports.extractFirstHeader = extractFirstHeader;
166
- exports.removeFirstHeader = removeFirstHeader;
167
- //# sourceMappingURL=loader.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.cjs","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,KAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,MAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,qBAAAA,CAAAA;IACnCC,cAAgBP,EAAAA,KAAAA,CAAEQ,KAAK,CAACR,KAAAA,CAAES,MAAM,EAAIL,CAAAA,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAACK,iCAAAA,CAAAA;AACvDC,IAAAA,UAAAA,EAAYC,2BAAiBR,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,YAAa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wBAAA,IAAIG,WAAcP,GAAAA,IAAAA;AAClB,wBAAA,IAAIQ,YAAeF,GAAAA,WAAAA;;wBAGnB,IAAIN,IAAAA,CAAKS,QAAQ,CAAC,KAAQ,CAAA,EAAA;AACtB,4BAAA,MAAMC,aAAazD,kBAAmBqD,CAAAA,WAAAA,CAAAA;AACtC,4BAAA,IAAII,UAAY,EAAA;gCACZH,WAAcG,GAAAA,UAAAA;;AAEdF,gCAAAA,YAAAA,GAAelD,iBAAkBgD,CAAAA,WAAAA,CAAAA;AACrC;AACJ;;AAGA,wBAAA,MAAMK,cAActB,cAAiB,CAAA;AAAE,4BAAA,GAAGvB,cAAc;4BAAEwB,KAAOiB,EAAAA;AAAY,yBAAA,CAAA;wBAC7EI,WAAYpB,CAAAA,GAAG,CAACiB,YAAc,EAAA;AAAE,4BAAA,GAAG1C;AAAe,yBAAA,CAAA;;wBAGlDe,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,QAAOuE,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;;;;;;"}
package/dist/logger.cjs DELETED
@@ -1,51 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const constants = require('./constants.cjs');
6
-
7
- const DEFAULT_LOGGER = {
8
- name: 'default',
9
- debug: (message, ...args)=>console.debug(message, ...args),
10
- info: (message, ...args)=>console.info(message, ...args),
11
- warn: (message, ...args)=>console.warn(message, ...args),
12
- error: (message, ...args)=>console.error(message, ...args),
13
- verbose: (message, ...args)=>console.log(message, ...args),
14
- silly: (message, ...args)=>console.log(message, ...args)
15
- };
16
- const wrapLogger = (toWrap, name)=>{
17
- const requiredMethods = [
18
- 'debug',
19
- 'info',
20
- 'warn',
21
- 'error',
22
- 'verbose',
23
- 'silly'
24
- ];
25
- const missingMethods = requiredMethods.filter((method)=>typeof toWrap[method] !== 'function');
26
- if (missingMethods.length > 0) {
27
- throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);
28
- }
29
- const log = (level, message, ...args)=>{
30
- message = `[${constants.LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;
31
- if (level === 'debug') toWrap.debug(message, ...args);
32
- else if (level === 'info') toWrap.info(message, ...args);
33
- else if (level === 'warn') toWrap.warn(message, ...args);
34
- else if (level === 'error') toWrap.error(message, ...args);
35
- else if (level === 'verbose') toWrap.verbose(message, ...args);
36
- else if (level === 'silly') toWrap.silly(message, ...args);
37
- };
38
- return {
39
- name: 'wrapped',
40
- debug: (message, ...args)=>log('debug', message, ...args),
41
- info: (message, ...args)=>log('info', message, ...args),
42
- warn: (message, ...args)=>log('warn', message, ...args),
43
- error: (message, ...args)=>log('error', message, ...args),
44
- verbose: (message, ...args)=>log('verbose', message, ...args),
45
- silly: (message, ...args)=>log('silly', message, ...args)
46
- };
47
- };
48
-
49
- exports.DEFAULT_LOGGER = DEFAULT_LOGGER;
50
- exports.wrapLogger = wrapLogger;
51
- //# sourceMappingURL=logger.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.cjs","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 verbose: (message: string, ...args: any[]) => console.log(message, ...args),\n silly: (message: string, ...args: any[]) => console.log(message, ...args),\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","log","silly","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","join","level","LIBRARY_NAME"],"mappings":";;;;;;MAaaA,cAAyB,GAAA;IAClCC,IAAM,EAAA,SAAA;AACNC,IAAAA,KAAAA,EAAO,CAACC,OAAiB,EAAA,GAAGC,OAAgBC,OAAQH,CAAAA,K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A,CAAI,QAAQP,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACnEI,QAAAA,KAAAA,EAAO,CAACL,OAAiB,EAAA,GAAGC,IAAgBM,GAAAA,GAAAA,CAAI,SAASP,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACrEK,QAAAA,OAAAA,EAAS,CAACN,OAAiB,EAAA,GAAGC,IAAgBM,GAAAA,GAAAA,CAAI,WAAWP,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACzEO,QAAAA,KAAAA,EAAO,CAACR,OAAiB,EAAA,GAAGC,IAAgBM,GAAAA,GAAAA,CAAI,SAASP,OAAYC,EAAAA,GAAAA,IAAAA;AACzE,KAAA;AACJ;;;;;"}
package/dist/override.cjs DELETED
@@ -1,109 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const path = require('path');
6
- const zod = require('zod');
7
- const parameters = require('./items/parameters.cjs');
8
- const section = require('./items/section.cjs');
9
- const logger = require('./logger.cjs');
10
- require('./items/weighted.cjs');
11
- const formatter = require('./formatter.cjs');
12
- const parser = require('./parser.cjs');
13
- require('./loader.cjs');
14
- require('./builder.cjs');
15
- const storage = require('./util/storage.cjs');
16
-
17
- const OptionsSchema = zod.z.object({
18
- logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
19
- configDir: zod.z.string().default('./overrides'),
20
- overrides: zod.z.boolean().default(false),
21
- parameters: parameters.ParametersSchema.optional().default({})
22
- });
23
- const create = (overrideOptions = {})=>{
24
- const options = OptionsSchema.parse(overrideOptions);
25
- const parameters = options.parameters;
26
- const logger$1 = logger.wrapLogger(options === null || options === void 0 ? void 0 : options.logger, 'Override');
27
- const storage$1 = storage.create({
28
- log: logger$1.debug
29
- });
30
- const loadOptions = (sectionOptions = {})=>{
31
- const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
32
- return {
33
- ...currentOptions,
34
- parameters: {
35
- ...parameters,
36
- ...currentOptions.parameters
37
- }
38
- };
39
- };
40
- const override = async (overrideFile, section, sectionOptions = {})=>{
41
- const currentSectionOptions = loadOptions(sectionOptions);
42
- const baseFile = path.join(options.configDir, overrideFile);
43
- const preFile = baseFile.replace('.md', '-pre.md');
44
- const postFile = baseFile.replace('.md', '-post.md');
45
- const response = {};
46
- if (await storage$1.exists(preFile)) {
47
- logger$1.silly('Found pre file %s', preFile);
48
- const parser$1 = parser.create({
49
- logger: logger$1
50
- });
51
- response.prepend = await parser$1.parseFile(preFile, currentSectionOptions);
52
- }
53
- if (await storage$1.exists(postFile)) {
54
- logger$1.silly('Found post file %s', postFile);
55
- const parser$1 = parser.create({
56
- logger: logger$1
57
- });
58
- response.append = await parser$1.parseFile(postFile, currentSectionOptions);
59
- }
60
- if (await storage$1.exists(baseFile)) {
61
- logger$1.silly('Found base file %s', baseFile);
62
- if (options.overrides) {
63
- logger$1.warn('WARNING: Core directives are being overwritten by custom configuration');
64
- const parser$1 = parser.create({
65
- logger: logger$1
66
- });
67
- response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
68
- } else {
69
- logger$1.error('ERROR: Core directives are being overwritten by custom configuration');
70
- throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
71
- }
72
- }
73
- return response;
74
- };
75
- const customize = async (overrideFile, section, sectionOptions = {})=>{
76
- const currentSectionOptions = loadOptions(sectionOptions);
77
- const { overrideContent, prepend, append } = await override(overrideFile, section, currentSectionOptions);
78
- let finalSection = section;
79
- if (overrideContent) {
80
- if (options.overrides) {
81
- logger$1.warn('Override found, replacing content from file %s', overrideContent);
82
- finalSection = overrideContent;
83
- } else {
84
- logger$1.error('ERROR: Core directives are being overwritten by custom configuration');
85
- throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
86
- }
87
- }
88
- if (prepend) {
89
- logger$1.silly('Prepend found, adding to content from file %s', prepend);
90
- finalSection = finalSection.prepend(prepend);
91
- }
92
- if (append) {
93
- logger$1.silly('Append found, adding to content from file %s', append);
94
- finalSection = finalSection.append(append);
95
- }
96
- const formatter$1 = formatter.create({
97
- logger: logger$1
98
- });
99
- logger$1.silly('Final section %s:\n\n%s\n\n', logger$1.name, formatter$1.format(finalSection));
100
- return finalSection;
101
- };
102
- return {
103
- override,
104
- customize
105
- };
106
- };
107
-
108
- exports.create = create;
109
- //# sourceMappingURL=override.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"override.cjs","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDir: z.string().default('./overrides'),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const baseFile = path.join(options.configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n const response: { override?: Section<T>, prepend?: Section<T>, append?: Section<T> } = {};\n\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s', preFile);\n const parser = Parser.create({ logger });\n response.prepend = await parser.parseFile<T>(preFile, currentSectionOptions);\n }\n\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s', postFile);\n const parser = Parser.create({ logger });\n response.append = await parser.parseFile<T>(postFile, currentSectionOptions);\n }\n\n if (await storage.exists(baseFile)) {\n logger.silly('Found base file %s', baseFile);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration');\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { overrideContent, prepend, append }: { overrideContent?: Section<T>, prepend?: Section<T>, append?: Section<T> } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n if (prepend) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n if (append) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDir","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","baseFile","path","join","preFile","replace","postFile","response","exists","silly","parser","Parser","prepend","parseFile","append","warn","error","Error","customize","overrideContent","finalSection","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,KAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,MAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,qBAAAA,CAAAA;AACnCC,IAAAA,SAAAA,EAAWP,KAAEQ,CAAAA,MAAM,EAAGH,CAAAA,OAAO,CAAC,aAAA,CAAA;AAC9BI,IAAAA,SAAAA,EAAWT,KAAEU,CAAAA,OAAO,EAAGL,CAAAA,OAAO,CAAC,KAAA,CAAA;AAC/BM,IAAAA,UAAAA,EAAYC,2BAAiBR,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAYaQ,MAAAA,MAAAA,GAAS,CAACC,eAAAA,GAAgC,EAAE,GAAA;IACrD,MAAMC,OAAAA,GAA6BhB,aAAciB,CAAAA,KAAK,CAACF,eAAAA,CAAAA;IAEvD,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAMT,WAASe,iBAAWF,CAAAA,OAAAA,KAAAA,IAAAA,IAAAA,OAAAA,KAAAA,MAAAA,GAAAA,MAAAA,GAAAA,OAAAA,CAASb,MAAM,EAAE,UA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,QAAO0C,CAAAA,IAAI,CAAC,gDAAkDI,EAAAA,eAAAA,CAAAA;gBAC9DC,YAAeD,GAAAA,eAAAA;aACZ,MAAA;AACH9C,gBAAAA,QAAAA,CAAO2C,KAAK,CAAC,sEAAA,CAAA;AACb,gBAAA,MAAM,IAAIC,KAAM,CAAA,+IAAA,CAAA;AACpB;AACJ;AAEA,QAAA,IAAIL,OAAS,EAAA;YACTvC,QAAOoC,CAAAA,KAAK,CAAC,+CAAiDG,EAAAA,OAAAA,CAAAA;YAC9DQ,YAAeA,GAAAA,YAAAA,CAAaR,OAAO,CAACA,OAAAA,CAAAA;AACxC;AAEA,QAAA,IAAIE,MAAQ,EAAA;YACRzC,QAAOoC,CAAAA,KAAK,CAAC,8CAAgDK,EAAAA,MAAAA,CAAAA;YAC7DM,YAAeA,GAAAA,YAAAA,CAAaN,MAAM,CAACA,MAAAA,CAAAA;AACvC;QAEA,MAAMO,WAAAA,GAAYC,gBAAgB,CAAC;AAAEjD,oBAAAA;AAAO,SAAA,CAAA;QAC5CA,QAAOoC,CAAAA,KAAK,CAAC,6BAA+BpC,EAAAA,QAAAA,CAAOkD,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACJ,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,KAAA;IAEA,OAAO;AACHvB,QAAAA,QAAAA;AACAqB,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -1,114 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const marked = require('marked');
6
- const section = require('../items/section.cjs');
7
- const weighted = require('../items/weighted.cjs');
8
-
9
- const parseMarkdown = (input, options = {})=>{
10
- let markdownContent;
11
- if (typeof input === 'string') {
12
- markdownContent = input;
13
- } else {
14
- markdownContent = input.toString();
15
- }
16
- const sectionOptions = section.SectionOptionsSchema.parse(options);
17
- // Use marked.lexer to get tokens without full parsing/rendering
18
- const tokens = marked.marked.lexer(markdownContent);
19
- // Create the main section (with a Title from the options)
20
- const mainSection = section.create(sectionOptions);
21
- // Track sections at each depth level
22
- const sectionStack = [
23
- mainSection
24
- ];
25
- // Set if we've seen the first token
26
- let isFirstToken = true;
27
- // Set the item options
28
- const itemOptions = weighted.WeightedOptionsSchema.parse({
29
- ...sectionOptions,
30
- weight: sectionOptions.itemWeight
31
- });
32
- for (const token of tokens){
33
- switch(token.type){
34
- case 'heading':
35
- {
36
- const depth = token.depth;
37
- // If this is the first token and it's a heading, use it as the main section title
38
- if (isFirstToken) {
39
- mainSection.title = token.text;
40
- isFirstToken = false;
41
- break;
42
- }
43
- isFirstToken = false;
44
- // Create a new section with this heading
45
- const newSection = section.create({
46
- ...sectionOptions,
47
- title: token.text
48
- });
49
- // Ensure the section stack has the right size based on this heading's depth
50
- // (e.g., a depth-2 heading should be added to the depth-1 section)
51
- // We need to ensure the stack length is exactly depth, not just less than or equal to depth
52
- while(sectionStack.length > depth && sectionStack.length > 1){
53
- sectionStack.pop();
54
- }
55
- // Make sure we're at the right level for this heading
56
- // If we stay at the same heading level (e.g., two h2s in sequence),
57
- // we need to pop once more to get to the parent level
58
- if (sectionStack.length === depth && sectionStack.length > 1) {
59
- sectionStack.pop();
60
- }
61
- // Add new section to its parent
62
- const parentSection = sectionStack[sectionStack.length - 1];
63
- parentSection.add(newSection, itemOptions);
64
- // Push this section onto the stack
65
- sectionStack.push(newSection);
66
- break;
67
- }
68
- case 'paragraph':
69
- {
70
- isFirstToken = false;
71
- const instruction = weighted.create(token.text, itemOptions);
72
- const currentSection = sectionStack[sectionStack.length - 1];
73
- currentSection.add(instruction, itemOptions);
74
- break;
75
- }
76
- case 'list':
77
- {
78
- isFirstToken = false;
79
- // Convert list items to instructions
80
- const listInstructionContent = token.items.map((item)=>`- ${item.text}`).join('\n');
81
- const listInstruction = weighted.create(listInstructionContent, itemOptions);
82
- const currentSection = sectionStack[sectionStack.length - 1];
83
- currentSection.add(listInstruction, itemOptions);
84
- break;
85
- }
86
- case 'code':
87
- {
88
- isFirstToken = false;
89
- // Represent code blocks as instructions
90
- const codeInstruction = weighted.create(`\`\`\`${token.lang || ''}\n${token.text}\n\`\`\``, itemOptions);
91
- const currentSection = sectionStack[sectionStack.length - 1];
92
- currentSection.add(codeInstruction, itemOptions);
93
- break;
94
- }
95
- case 'space':
96
- break;
97
- default:
98
- {
99
- isFirstToken = false;
100
- // Treat other block tokens' text as instructions for robustness
101
- if ('text' in token && token.text) {
102
- const fallbackInstruction = weighted.create(token.text, itemOptions);
103
- const currentSection = sectionStack[sectionStack.length - 1];
104
- currentSection.add(fallbackInstruction, itemOptions);
105
- }
106
- break;
107
- }
108
- }
109
- }
110
- return mainSection;
111
- };
112
-
113
- exports.parseMarkdown = parseMarkdown;
114
- //# sourceMappingURL=markdown.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown.cjs","sources":["../../src/parse/markdown.ts"],"sourcesContent":["import { marked } from 'marked';\nimport { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseMarkdown = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let markdownContent;\n if (typeof input === 'string') {\n markdownContent = input;\n } else {\n markdownContent = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Use marked.lexer to get tokens without full parsing/rendering\n const tokens = marked.lexer(markdownContent);\n\n // Create the main section (with a Title from the options)\n const mainSection = createSection<T>(sectionOptions);\n\n // Track sections at each depth level\n const sectionStack: Section<T>[] = [mainSection];\n\n // Set if we've seen the first token\n let isFirstToken = true;\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n for (const token of tokens) {\n switch (token.type) {\n case 'heading': {\n const depth = token.depth;\n\n // If this is the first token and it's a heading, use it as the main section title\n if (isFirstToken) {\n mainSection.title = token.text;\n isFirstToken = false;\n break;\n }\n\n isFirstToken = false;\n\n // Create a new section with this heading\n const newSection = createSection<T>({ ...sectionOptions, title: token.text });\n\n // Ensure the section stack has the right size based on this heading's depth\n // (e.g., a depth-2 heading should be added to the depth-1 section)\n // We need to ensure the stack length is exactly depth, not just less than or equal to depth\n while (sectionStack.length > depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Make sure we're at the right level for this heading\n // If we stay at the same heading level (e.g., two h2s in sequence),\n // we need to pop once more to get to the parent level\n if (sectionStack.length === depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Add new section to its parent\n const parentSection = sectionStack[sectionStack.length - 1];\n parentSection.add(newSection, itemOptions);\n\n // Push this section onto the stack\n sectionStack.push(newSection);\n break;\n }\n\n case 'paragraph': {\n isFirstToken = false;\n const instruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(instruction, itemOptions);\n break;\n }\n\n case 'list': {\n isFirstToken = false;\n // Convert list items to instructions\n const listInstructionContent = token.items.map((item: any) => `- ${item.text}`).join('\\n');\n const listInstruction: T = createWeighted<T>(listInstructionContent, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(listInstruction, itemOptions);\n break;\n }\n\n case 'code': {\n isFirstToken = false;\n // Represent code blocks as instructions\n const codeInstruction: T = createWeighted<T>(`\\`\\`\\`${token.lang || ''}\\n${token.text}\\n\\`\\`\\``, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(codeInstruction, itemOptions);\n break;\n }\n\n case 'space':\n // Usually ignore space tokens between block elements\n break;\n\n default: {\n isFirstToken = false;\n // Treat other block tokens' text as instructions for robustness\n if ('text' in token && token.text) {\n const fallbackInstruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(fallbackInstruction, itemOptions);\n }\n break;\n }\n }\n }\n return mainSection;\n}\n"],"names":["parseMarkdown","input","options","markdownContent","toString","sectionOptions","SectionOptionsSchema","parse","tokens","marked","lexer","mainSection","createSection","sectionStack","isFirstToken","itemOptions","WeightedOptionsSchema","weight","itemWeight","token","type","depth","title","text","newSection","length","pop","parentSection","add","push","instruction","createWeighted","currentSection","listInstructionContent","items","map","item","join","listInstruction","codeInstruction","lang","fallbackInstruction"],"mappings":";;;;;;;;MAIaA,aAAgB,GAAA,CACzBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,eAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,eAAkBF,GAAAA,KAAAA;KACf,MAAA;AACHE,QAAAA,eAAAA,GAAkBF,MAAMG,QAAQ,EAAA;AACpC;IAEA,MAAMC,cAAAA,GAAiBC,4BAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,MAAAA,GAASC,aAAOC,CAAAA,KAAK,CAACP,eAAAA,CAAAA;;AAG5B,IAAA,MAAMQ,cAAcC,cAAiBP,CAAAA,cAAAA,CAAAA;;AAGrC,IAAA,MAAMQ,YAA6B,GAAA;AAACF,QAAAA;AAAY,KAAA;;AAGhD,IAAA,IAAIG,YAAe,GAAA,IAAA;;IAGnB,MAAMC,WAAAA,GAAcC,8BAAsBT,CAAAA,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBY,QAAAA,MAAAA,EAAQZ,eAAea;AAC3B,KAAA,CAAA;IAEA,KAAK,MAAMC,SAASX,MAAQ,CAAA;AACxB,QAAA,OAAQW,MAAMC,IAAI;YACd,KAAK,SAAA;AAAW,gBAAA;oBACZ,MAAMC,KAAAA,GAAQF,MAAME,KAAK;;AAGzB,oBAAA,IAAIP,YAAc,EAAA;wBACdH,WAAYW,CAAAA,KAAK,GAAGH,KAAAA,CAAMI,IAAI;wBAC9BT,YAAe,GAAA,KAAA;AACf,wBAAA;AACJ;oBAEAA,YAAe,GAAA,KAAA;;AAGf,oBAAA,MAAMU,aAAaZ,cAAi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rE,oBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAaY,CAAAA,MAAM,GAAG,CAAE,CAAA;oBAC5DO,cAAeJ,CAAAA,GAAG,CAACU,eAAiBvB,EAAAA,WAAAA,CAAAA;AACpC,oBAAA;AACJ;YAEA,KAAK,MAAA;AAAQ,gBAAA;oBACTD,YAAe,GAAA,KAAA;;AAEf,oBAAA,MAAMyB,kBAAqBR,eAAkB,CAAA,CAAC,MAAM,EAAEZ,MAAMqB,IAAI,IAAI,EAAG,CAAA,EAAE,EAAErB,KAAMI,CAAAA,IAAI,CAAC,QAAQ,CAAC,EAAER,WAAAA,CAAAA;AACjG,oBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAaY,CAAAA,MAAM,GAAG,CAAE,CAAA;oBAC5DO,cAAeJ,CAAAA,GAAG,CAACW,eAAiBxB,EAAAA,WAAAA,CAAAA;AACpC,oBAAA;AACJ;YAEA,KAAK,OAAA;AAED,gBAAA;AAEJ,YAAA;AAAS,gBAAA;oBACLD,YAAe,GAAA,KAAA;;AAEf,oBAAA,IAAI,MAAUK,IAAAA,KAAAA,IAASA,KAAMI,CAAAA,IAAI,EAAE;AAC/B,wBAAA,MAAMkB,mBAAyBV,GAAAA,eAAAA,CAAkBZ,KAAMI,CAAAA,IAAI,EAAER,WAAAA,CAAAA;AAC7D,wBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAaY,CAAAA,MAAM,GAAG,CAAE,CAAA;wBAC5DO,cAAeJ,CAAAA,GAAG,CAACa,mBAAqB1B,EAAAA,WAAAA,CAAAA;AAC5C;AACA,oBAAA;AACJ;AACJ;AACJ;IACA,OAAOJ,WAAAA;AACX;;;;"}
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const section = require('../items/section.cjs');
6
- const weighted = require('../items/weighted.cjs');
7
-
8
- const parseText = (input, options = {})=>{
9
- let text;
10
- if (typeof input === 'string') {
11
- text = input;
12
- } else {
13
- text = input.toString();
14
- }
15
- const sectionOptions = section.SectionOptionsSchema.parse(options);
16
- // Set the item options
17
- const itemOptions = weighted.WeightedOptionsSchema.parse({
18
- ...sectionOptions,
19
- weight: sectionOptions.itemWeight
20
- });
21
- // Split the text on newlines
22
- const lines = text.split(/\r?\n/).filter((line)=>line.trim().length > 0);
23
- // Create the main section with the supplied title
24
- const mainSection = section.create(sectionOptions);
25
- for (const line of lines){
26
- const instruction = weighted.create(line, itemOptions);
27
- mainSection.add(instruction, itemOptions);
28
- }
29
- return mainSection;
30
- };
31
-
32
- exports.parseText = parseText;
33
- //# sourceMappingURL=text.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text.cjs","sources":["../../src/parse/text.ts"],"sourcesContent":["import { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseText = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let text;\n if (typeof input === 'string') {\n text = input;\n } else {\n text = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n // Split the text on newlines\n const lines = text.split(/\\r?\\n/).filter(line => line.trim().length > 0);\n\n // Create the main section with the supplied title\n const mainSection = createSection<T>(sectionOptions);\n\n for (const line of lines) {\n const instruction: T = createWeighted<T>(line, itemOptions);\n mainSection.add(instruction, itemOptions);\n }\n\n return mainSection;\n}\n"],"names":["parseText","input","options","text","toString","sectionOptions","SectionOptionsSchema","parse","itemOptions","WeightedOptionsSchema","weight","itemWeight","lines","split","filter","line","trim","length","mainSection","createSection","instruction","createWeighted","add"],"mappings":";;;;;;;MAGaA,SAAY,GAAA,CACrBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,IAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,IAAOF,GAAAA,KAAAA;KACJ,MAAA;AACHE,QAAAA,IAAAA,GAAOF,MAAMG,QAAQ,EAAA;AACzB;IAEA,MAAMC,cAAAA,GAAiBC,4BAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,WAAAA,GAAcC,8BAAsBF,CAAAA,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBK,QAAAA,MAAAA,EAAQL,eAAeM;AAC3B,KAAA,CAAA;;AAGA,IAAA,MAAMC,KAAQT,GAAAA,IAAAA,CAAKU,KAAK,CAAC,OAASC,CAAAA,CAAAA,MAAM,CAACC,CAAAA,IAAQA,GAAAA,IAAAA,CAAKC,IAAI,EAAA,CAAGC,MAAM,GAAG,CAAA,CAAA;;AAGtE,IAAA,MAAMC,cAAcC,cAAiBd,CAAAA,cAAAA,CAAAA;IAErC,KAAK,MAAMU,QAAQH,KAAO,CAAA;QACtB,MAAMQ,WAAAA,GAAiBC,gBAAkBN,IAAMP,EAAAA,WAAAA,CAAAA;QAC/CU,WAAYI,CAAAA,GAAG,CAACF,WAAaZ,EAAAA,WAAAA,CAAAA;AACjC;IAEA,OAAOU,WAAAA;AACX;;;;"}