@riotprompt/riotprompt 0.0.1

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 (129) hide show
  1. package/.gitcarve/config.yaml +10 -0
  2. package/.gitcarve/context/content.md +11 -0
  3. package/.markdown-doctest-setup.mjs +23 -0
  4. package/.nvmrc +1 -0
  5. package/LICENSE +190 -0
  6. package/README.md +513 -0
  7. package/dist/builder.cjs +152 -0
  8. package/dist/builder.cjs.map +1 -0
  9. package/dist/builder.d.ts +37 -0
  10. package/dist/builder.js +148 -0
  11. package/dist/builder.js.map +1 -0
  12. package/dist/chat.cjs +26 -0
  13. package/dist/chat.cjs.map +1 -0
  14. package/dist/chat.d.ts +14 -0
  15. package/dist/chat.js +21 -0
  16. package/dist/chat.js.map +1 -0
  17. package/dist/constants.cjs +34 -0
  18. package/dist/constants.cjs.map +1 -0
  19. package/dist/constants.d.ts +13 -0
  20. package/dist/constants.js +23 -0
  21. package/dist/constants.js.map +1 -0
  22. package/dist/formatter.cjs +139 -0
  23. package/dist/formatter.cjs.map +1 -0
  24. package/dist/formatter.d.ts +88 -0
  25. package/dist/formatter.js +131 -0
  26. package/dist/formatter.js.map +1 -0
  27. package/dist/items/content.cjs +14 -0
  28. package/dist/items/content.cjs.map +1 -0
  29. package/dist/items/content.d.ts +3 -0
  30. package/dist/items/content.js +10 -0
  31. package/dist/items/content.js.map +1 -0
  32. package/dist/items/context.cjs +13 -0
  33. package/dist/items/context.cjs.map +1 -0
  34. package/dist/items/context.d.ts +3 -0
  35. package/dist/items/context.js +9 -0
  36. package/dist/items/context.js.map +1 -0
  37. package/dist/items/instruction.cjs +13 -0
  38. package/dist/items/instruction.cjs.map +1 -0
  39. package/dist/items/instruction.d.ts +3 -0
  40. package/dist/items/instruction.js +9 -0
  41. package/dist/items/instruction.js.map +1 -0
  42. package/dist/items/parameters.cjs +53 -0
  43. package/dist/items/parameters.cjs.map +1 -0
  44. package/dist/items/parameters.d.ts +5 -0
  45. package/dist/items/parameters.js +47 -0
  46. package/dist/items/parameters.js.map +1 -0
  47. package/dist/items/section.cjs +120 -0
  48. package/dist/items/section.cjs.map +1 -0
  49. package/dist/items/section.d.ts +33 -0
  50. package/dist/items/section.js +115 -0
  51. package/dist/items/section.js.map +1 -0
  52. package/dist/items/trait.cjs +13 -0
  53. package/dist/items/trait.cjs.map +1 -0
  54. package/dist/items/trait.d.ts +3 -0
  55. package/dist/items/trait.js +9 -0
  56. package/dist/items/trait.js.map +1 -0
  57. package/dist/items/weighted.cjs +27 -0
  58. package/dist/items/weighted.cjs.map +1 -0
  59. package/dist/items/weighted.d.ts +24 -0
  60. package/dist/items/weighted.js +22 -0
  61. package/dist/items/weighted.js.map +1 -0
  62. package/dist/loader.cjs +167 -0
  63. package/dist/loader.cjs.map +1 -0
  64. package/dist/loader.d.ts +35 -0
  65. package/dist/loader.js +161 -0
  66. package/dist/loader.js.map +1 -0
  67. package/dist/logger.cjs +51 -0
  68. package/dist/logger.cjs.map +1 -0
  69. package/dist/logger.d.ts +11 -0
  70. package/dist/logger.js +46 -0
  71. package/dist/logger.js.map +1 -0
  72. package/dist/override.cjs +109 -0
  73. package/dist/override.cjs.map +1 -0
  74. package/dist/override.d.ts +31 -0
  75. package/dist/override.js +105 -0
  76. package/dist/override.js.map +1 -0
  77. package/dist/parse/markdown.cjs +114 -0
  78. package/dist/parse/markdown.cjs.map +1 -0
  79. package/dist/parse/markdown.d.ts +3 -0
  80. package/dist/parse/markdown.js +110 -0
  81. package/dist/parse/markdown.js.map +1 -0
  82. package/dist/parse/text.cjs +33 -0
  83. package/dist/parse/text.cjs.map +1 -0
  84. package/dist/parse/text.d.ts +3 -0
  85. package/dist/parse/text.js +29 -0
  86. package/dist/parse/text.js.map +1 -0
  87. package/dist/parser.cjs +99 -0
  88. package/dist/parser.cjs.map +1 -0
  89. package/dist/parser.d.ts +21 -0
  90. package/dist/parser.js +75 -0
  91. package/dist/parser.js.map +1 -0
  92. package/dist/prompt.cjs +15 -0
  93. package/dist/prompt.cjs.map +1 -0
  94. package/dist/prompt.d.ts +16 -0
  95. package/dist/prompt.js +11 -0
  96. package/dist/prompt.js.map +1 -0
  97. package/dist/riotprompt.cjs +1359 -0
  98. package/dist/riotprompt.cjs.map +1 -0
  99. package/dist/riotprompt.d.ts +25 -0
  100. package/dist/riotprompt.js +21 -0
  101. package/dist/riotprompt.js.map +1 -0
  102. package/dist/util/general.cjs +52 -0
  103. package/dist/util/general.cjs.map +1 -0
  104. package/dist/util/general.d.ts +4 -0
  105. package/dist/util/general.js +47 -0
  106. package/dist/util/general.js.map +1 -0
  107. package/dist/util/markdown.cjs +115 -0
  108. package/dist/util/markdown.cjs.map +1 -0
  109. package/dist/util/markdown.d.ts +7 -0
  110. package/dist/util/markdown.js +111 -0
  111. package/dist/util/markdown.js.map +1 -0
  112. package/dist/util/storage.cjs +155 -0
  113. package/dist/util/storage.cjs.map +1 -0
  114. package/dist/util/storage.d.ts +32 -0
  115. package/dist/util/storage.js +132 -0
  116. package/dist/util/storage.js.map +1 -0
  117. package/dist/util/text.cjs +42 -0
  118. package/dist/util/text.cjs.map +1 -0
  119. package/dist/util/text.d.ts +1 -0
  120. package/dist/util/text.js +38 -0
  121. package/dist/util/text.js.map +1 -0
  122. package/docs/loader.md +237 -0
  123. package/docs/override.md +323 -0
  124. package/docs/parser.md +130 -0
  125. package/eslint.config.mjs +82 -0
  126. package/nodemon.json +14 -0
  127. package/package.json +72 -0
  128. package/vite.config.ts +114 -0
  129. package/vitest.config.ts +25 -0
@@ -0,0 +1,114 @@
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
@@ -0,0 +1 @@
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,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OJ,WAAAA;AACX;;;;"}
@@ -0,0 +1,3 @@
1
+ import { Section, SectionOptions } from '../items/section';
2
+ import { Weighted } from '../items/weighted';
3
+ export declare const parseMarkdown: <T extends Weighted>(input: string | Buffer, options?: Partial<SectionOptions>) => Section<T>;
@@ -0,0 +1,110 @@
1
+ import { marked } from 'marked';
2
+ import { SectionOptionsSchema, create } from '../items/section.js';
3
+ import { WeightedOptionsSchema, create as create$1 } from '../items/weighted.js';
4
+
5
+ const parseMarkdown = (input, options = {})=>{
6
+ let markdownContent;
7
+ if (typeof input === 'string') {
8
+ markdownContent = input;
9
+ } else {
10
+ markdownContent = input.toString();
11
+ }
12
+ const sectionOptions = SectionOptionsSchema.parse(options);
13
+ // Use marked.lexer to get tokens without full parsing/rendering
14
+ const tokens = marked.lexer(markdownContent);
15
+ // Create the main section (with a Title from the options)
16
+ const mainSection = create(sectionOptions);
17
+ // Track sections at each depth level
18
+ const sectionStack = [
19
+ mainSection
20
+ ];
21
+ // Set if we've seen the first token
22
+ let isFirstToken = true;
23
+ // Set the item options
24
+ const itemOptions = WeightedOptionsSchema.parse({
25
+ ...sectionOptions,
26
+ weight: sectionOptions.itemWeight
27
+ });
28
+ for (const token of tokens){
29
+ switch(token.type){
30
+ case 'heading':
31
+ {
32
+ const depth = token.depth;
33
+ // If this is the first token and it's a heading, use it as the main section title
34
+ if (isFirstToken) {
35
+ mainSection.title = token.text;
36
+ isFirstToken = false;
37
+ break;
38
+ }
39
+ isFirstToken = false;
40
+ // Create a new section with this heading
41
+ const newSection = create({
42
+ ...sectionOptions,
43
+ title: token.text
44
+ });
45
+ // Ensure the section stack has the right size based on this heading's depth
46
+ // (e.g., a depth-2 heading should be added to the depth-1 section)
47
+ // We need to ensure the stack length is exactly depth, not just less than or equal to depth
48
+ while(sectionStack.length > depth && sectionStack.length > 1){
49
+ sectionStack.pop();
50
+ }
51
+ // Make sure we're at the right level for this heading
52
+ // If we stay at the same heading level (e.g., two h2s in sequence),
53
+ // we need to pop once more to get to the parent level
54
+ if (sectionStack.length === depth && sectionStack.length > 1) {
55
+ sectionStack.pop();
56
+ }
57
+ // Add new section to its parent
58
+ const parentSection = sectionStack[sectionStack.length - 1];
59
+ parentSection.add(newSection, itemOptions);
60
+ // Push this section onto the stack
61
+ sectionStack.push(newSection);
62
+ break;
63
+ }
64
+ case 'paragraph':
65
+ {
66
+ isFirstToken = false;
67
+ const instruction = create$1(token.text, itemOptions);
68
+ const currentSection = sectionStack[sectionStack.length - 1];
69
+ currentSection.add(instruction, itemOptions);
70
+ break;
71
+ }
72
+ case 'list':
73
+ {
74
+ isFirstToken = false;
75
+ // Convert list items to instructions
76
+ const listInstructionContent = token.items.map((item)=>`- ${item.text}`).join('\n');
77
+ const listInstruction = create$1(listInstructionContent, itemOptions);
78
+ const currentSection = sectionStack[sectionStack.length - 1];
79
+ currentSection.add(listInstruction, itemOptions);
80
+ break;
81
+ }
82
+ case 'code':
83
+ {
84
+ isFirstToken = false;
85
+ // Represent code blocks as instructions
86
+ const codeInstruction = create$1(`\`\`\`${token.lang || ''}\n${token.text}\n\`\`\``, itemOptions);
87
+ const currentSection = sectionStack[sectionStack.length - 1];
88
+ currentSection.add(codeInstruction, itemOptions);
89
+ break;
90
+ }
91
+ case 'space':
92
+ break;
93
+ default:
94
+ {
95
+ isFirstToken = false;
96
+ // Treat other block tokens' text as instructions for robustness
97
+ if ('text' in token && token.text) {
98
+ const fallbackInstruction = create$1(token.text, itemOptions);
99
+ const currentSection = sectionStack[sectionStack.length - 1];
100
+ currentSection.add(fallbackInstruction, itemOptions);
101
+ }
102
+ break;
103
+ }
104
+ }
105
+ }
106
+ return mainSection;
107
+ };
108
+
109
+ export { parseMarkdown };
110
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","sources":["../../src/parse/markdown.ts"],"sourcesContent":["import { marked } from 'marked';\nimport { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseMarkdown = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let markdownContent;\n if (typeof input === 'string') {\n markdownContent = input;\n } else {\n markdownContent = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Use marked.lexer to get tokens without full parsing/rendering\n const tokens = marked.lexer(markdownContent);\n\n // Create the main section (with a Title from the options)\n const mainSection = createSection<T>(sectionOptions);\n\n // Track sections at each depth level\n const sectionStack: Section<T>[] = [mainSection];\n\n // Set if we've seen the first token\n let isFirstToken = true;\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n for (const token of tokens) {\n switch (token.type) {\n case 'heading': {\n const depth = token.depth;\n\n // If this is the first token and it's a heading, use it as the main section title\n if (isFirstToken) {\n mainSection.title = token.text;\n isFirstToken = false;\n break;\n }\n\n isFirstToken = false;\n\n // Create a new section with this heading\n const newSection = createSection<T>({ ...sectionOptions, title: token.text });\n\n // Ensure the section stack has the right size based on this heading's depth\n // (e.g., a depth-2 heading should be added to the depth-1 section)\n // We need to ensure the stack length is exactly depth, not just less than or equal to depth\n while (sectionStack.length > depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Make sure we're at the right level for this heading\n // If we stay at the same heading level (e.g., two h2s in sequence),\n // we need to pop once more to get to the parent level\n if (sectionStack.length === depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Add new section to its parent\n const parentSection = sectionStack[sectionStack.length - 1];\n parentSection.add(newSection, itemOptions);\n\n // Push this section onto the stack\n sectionStack.push(newSection);\n break;\n }\n\n case 'paragraph': {\n isFirstToken = false;\n const instruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(instruction, itemOptions);\n break;\n }\n\n case 'list': {\n isFirstToken = false;\n // Convert list items to instructions\n const listInstructionContent = token.items.map((item: any) => `- ${item.text}`).join('\\n');\n const listInstruction: T = createWeighted<T>(listInstructionContent, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(listInstruction, itemOptions);\n break;\n }\n\n case 'code': {\n isFirstToken = false;\n // Represent code blocks as instructions\n const codeInstruction: T = createWeighted<T>(`\\`\\`\\`${token.lang || ''}\\n${token.text}\\n\\`\\`\\``, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(codeInstruction, itemOptions);\n break;\n }\n\n case 'space':\n // Usually ignore space tokens between block elements\n break;\n\n default: {\n isFirstToken = false;\n // Treat other block tokens' text as instructions for robustness\n if ('text' in token && token.text) {\n const fallbackInstruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(fallbackInstruction, itemOptions);\n }\n break;\n }\n }\n }\n return mainSection;\n}\n"],"names":["parseMarkdown","input","options","markdownContent","toString","sectionOptions","SectionOptionsSchema","parse","tokens","marked","lexer","mainSection","createSection","sectionStack","isFirstToken","itemOptions","WeightedOptionsSchema","weight","itemWeight","token","type","depth","title","text","newSection","length","pop","parentSection","add","push","instruction","createWeighted","currentSection","listInstructionContent","items","map","item","join","listInstruction","codeInstruction","lang","fallbackInstruction"],"mappings":";;;;MAIaA,aAAgB,GAAA,CACzBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,eAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,eAAkBF,GAAAA,KAAAA;KACf,MAAA;AACHE,QAAAA,eAAAA,GAAkBF,MAAMG,QAAQ,EAAA;AACpC;IAEA,MAAMC,cAAAA,GAAiBC,oBAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,MAAAA,GAASC,MAAOC,CAAAA,KAAK,CAACP,eAAAA,CAAAA;;AAG5B,IAAA,MAAMQ,cAAcC,MAAiBP,CAAAA,cAAAA,CAAAA;;AAG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,oBAAA,IAAI,MAAUK,IAAAA,KAAAA,IAASA,KAAMI,CAAAA,IAAI,EAAE;AAC/B,wBAAA,MAAMkB,mBAAyBV,GAAAA,QAAAA,CAAkBZ,KAAMI,CAAAA,IAAI,EAAER,WAAAA,CAAAA;AAC7D,wBAAA,MAAMiB,iBAAiBnB,YAAY,CAACA,YAAaY,CAAAA,MAAM,GAAG,CAAE,CAAA;wBAC5DO,cAAeJ,CAAAA,GAAG,CAACa,mBAAqB1B,EAAAA,WAAAA,CAAAA;AAC5C;AACA,oBAAA;AACJ;AACJ;AACJ;IACA,OAAOJ,WAAAA;AACX;;;;"}
@@ -0,0 +1,33 @@
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
@@ -0,0 +1 @@
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;;;;"}
@@ -0,0 +1,3 @@
1
+ import { Section, SectionOptions } from '../items/section';
2
+ import { Weighted } from '../items/weighted';
3
+ export declare const parseText: <T extends Weighted>(input: string | Buffer, options?: Partial<SectionOptions>) => Section<T>;
@@ -0,0 +1,29 @@
1
+ import { SectionOptionsSchema, create } from '../items/section.js';
2
+ import { WeightedOptionsSchema, create as create$1 } from '../items/weighted.js';
3
+
4
+ const parseText = (input, options = {})=>{
5
+ let text;
6
+ if (typeof input === 'string') {
7
+ text = input;
8
+ } else {
9
+ text = input.toString();
10
+ }
11
+ const sectionOptions = SectionOptionsSchema.parse(options);
12
+ // Set the item options
13
+ const itemOptions = WeightedOptionsSchema.parse({
14
+ ...sectionOptions,
15
+ weight: sectionOptions.itemWeight
16
+ });
17
+ // Split the text on newlines
18
+ const lines = text.split(/\r?\n/).filter((line)=>line.trim().length > 0);
19
+ // Create the main section with the supplied title
20
+ const mainSection = create(sectionOptions);
21
+ for (const line of lines){
22
+ const instruction = create$1(line, itemOptions);
23
+ mainSection.add(instruction, itemOptions);
24
+ }
25
+ return mainSection;
26
+ };
27
+
28
+ export { parseText };
29
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sources":["../../src/parse/text.ts"],"sourcesContent":["import { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseText = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let text;\n if (typeof input === 'string') {\n text = input;\n } else {\n text = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n // Split the text on newlines\n const lines = text.split(/\\r?\\n/).filter(line => line.trim().length > 0);\n\n // Create the main section with the supplied title\n const mainSection = createSection<T>(sectionOptions);\n\n for (const line of lines) {\n const instruction: T = createWeighted<T>(line, itemOptions);\n mainSection.add(instruction, itemOptions);\n }\n\n return mainSection;\n}\n"],"names":["parseText","input","options","text","toString","sectionOptions","SectionOptionsSchema","parse","itemOptions","WeightedOptionsSchema","weight","itemWeight","lines","split","filter","line","trim","length","mainSection","createSection","instruction","createWeighted","add"],"mappings":";;;MAGaA,SAAY,GAAA,CACrBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,IAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,IAAOF,GAAAA,KAAAA;KACJ,MAAA;AACHE,QAAAA,IAAAA,GAAOF,MAAMG,QAAQ,EAAA;AACzB;IAEA,MAAMC,cAAAA,GAAiBC,oBAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,WAAAA,GAAcC,qBAAsBF,CAAAA,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBK,QAAAA,MAAAA,EAAQL,eAAeM;AAC3B,KAAA,CAAA;;AAGA,IAAA,MAAMC,KAAQT,GAAAA,IAAAA,CAAKU,KAAK,CAAC,OAASC,CAAAA,CAAAA,MAAM,CAACC,CAAAA,IAAQA,GAAAA,IAAAA,CAAKC,IAAI,EAAA,CAAGC,MAAM,GAAG,CAAA,CAAA;;AAGtE,IAAA,MAAMC,cAAcC,MAAiBd,CAAAA,cAAAA,CAAAA;IAErC,KAAK,MAAMU,QAAQH,KAAO,CAAA;QACtB,MAAMQ,WAAAA,GAAiBC,SAAkBN,IAAMP,EAAAA,WAAAA,CAAAA;QAC/CU,WAAYI,CAAAA,GAAG,CAACF,WAAaZ,EAAAA,WAAAA,CAAAA;AACjC;IAEA,OAAOU,WAAAA;AACX;;;;"}
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const fs = require('fs/promises');
6
+ const path = require('path');
7
+ const zod = require('zod');
8
+ const parameters = require('./items/parameters.cjs');
9
+ const section = require('./items/section.cjs');
10
+ const logger = require('./logger.cjs');
11
+ const markdown$1 = require('./parse/markdown.cjs');
12
+ const text$1 = require('./parse/text.cjs');
13
+ const markdown = require('./util/markdown.cjs');
14
+ const text = require('./util/text.cjs');
15
+
16
+ function _interopNamespaceDefault(e) {
17
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
18
+ if (e) {
19
+ for (const k in e) {
20
+ if (k !== 'default') {
21
+ const d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: () => e[k]
25
+ });
26
+ }
27
+ }
28
+ }
29
+ n.default = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
34
+ const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
35
+
36
+ const OptionsSchema = zod.z.object({
37
+ logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
38
+ parameters: parameters.ParametersSchema.optional().default({})
39
+ });
40
+ const create = (parserOptions)=>{
41
+ const options = OptionsSchema.parse(parserOptions || {});
42
+ const parameters = options.parameters;
43
+ const logger$1 = logger.wrapLogger(options.logger, 'Parser');
44
+ const loadOptions = (sectionOptions = {})=>{
45
+ const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
46
+ return {
47
+ ...currentOptions,
48
+ parameters: {
49
+ ...parameters,
50
+ ...currentOptions.parameters
51
+ }
52
+ };
53
+ };
54
+ const parseFile = async (filePath, options = {})=>{
55
+ const currentOptions = loadOptions(options);
56
+ try {
57
+ const content = await fs__namespace.readFile(filePath, 'utf-8');
58
+ // Only use the filename as title if no title was explicitly provided
59
+ const fileName = path__namespace.basename(filePath, path__namespace.extname(filePath));
60
+ return parse(content, {
61
+ ...currentOptions,
62
+ title: (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.title) || fileName
63
+ });
64
+ } catch (error) {
65
+ // Log the error or handle it appropriately
66
+ logger$1.error(`Error reading or parsing file with marked at ${filePath}:`, error);
67
+ throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
68
+ }
69
+ };
70
+ /**
71
+ * Reads Markdown content and parses it into a single Section.
72
+ *
73
+ * - If the content starts with a heading, that becomes the title of the returned Section
74
+ * - If no heading at the start, creates a Section with no title
75
+ * - Headers within the content create nested sections based on their depth
76
+ * - All content is organized in a hierarchical structure based on heading levels
77
+ *
78
+ * @param content The content to parse
79
+ * @returns A Section containing all content in a hierarchical structure
80
+ */ const parse = (content, options = {})=>{
81
+ const currentOptions = loadOptions(options);
82
+ let mainSection;
83
+ if (markdown.isMarkdown(content)) {
84
+ mainSection = markdown$1.parseMarkdown(content, currentOptions);
85
+ } else if (text.isText(content)) {
86
+ mainSection = text$1.parseText(content, currentOptions);
87
+ } else {
88
+ throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);
89
+ }
90
+ return mainSection;
91
+ };
92
+ return {
93
+ parse,
94
+ parseFile
95
+ };
96
+ };
97
+
98
+ exports.create = create;
99
+ //# sourceMappingURL=parser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.cjs","sources":["../src/parser.ts"],"sourcesContent":["import * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { Section, SectionOptions, SectionOptionsSchema } from './items/section';\nimport { Weighted } from './items/weighted';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { parseMarkdown } from './parse/markdown';\nimport { parseText } from './parse/text';\nimport { isMarkdown } from './util/markdown';\nimport { isText } from './util/text';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Section<T>;\n parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;\n}\n\nexport const create = (parserOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(parserOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Parser');\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const parseFile = async <T extends Weighted>(\n filePath: string,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n // Only use the filename as title if no title was explicitly provided\n const fileName = path.basename(filePath, path.extname(filePath));\n return parse(content, {\n ...currentOptions,\n title: currentOptions?.title || fileName\n });\n } catch (error) {\n // Log the error or handle it appropriately\n logger.error(`Error reading or parsing file with marked at ${filePath}:`, error);\n throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Reads Markdown content and parses it into a single Section.\n * \n * - If the content starts with a heading, that becomes the title of the returned Section\n * - If no heading at the start, creates a Section with no title\n * - Headers within the content create nested sections based on their depth\n * - All content is organized in a hierarchical structure based on heading levels\n *\n * @param content The content to parse\n * @returns A Section containing all content in a hierarchical structure\n */\n const parse = <T extends Weighted>(\n content: string | Buffer,\n options: Partial<SectionOptions> = {}\n ): Section<T> => {\n const currentOptions = loadOptions(options);\n\n let mainSection: Section<T>;\n if (isMarkdown(content)) {\n mainSection = parseMarkdown<T>(content, currentOptions);\n } else if (isText(content)) {\n mainSection = parseText<T>(content, currentOptions);\n } else {\n throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);\n }\n return mainSection;\n }\n\n return {\n parse,\n parseFile\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","parameters","ParametersSchema","create","parserOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","parseFile","filePath","content","fs","readFile","fileName","path","basename","extname","title","error","Error","message","String","mainSection","isMarkdown","parseMarkdown","isText","parseText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAMA,aAAAA,GAAgBC,KAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,MAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,qBAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYC,2BAAiBJ,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAWO,MAAMI,SAAS,CAACC,aAAAA,GAAAA;AACnB,IAAA,MAAMC,OAA6BZ,GAAAA,aAAAA,CAAca,KAAK,CAACF,iBAAiB,EAAC,CAAA;IACzE,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAML,QAASW,GAAAA,iBAAAA,CAAWF,OAAQT,CAAAA,MAAM,EAAE,QAAA,CAAA;AAE1C,IAAA,MAAMY,WAAc,GAAA,CAACC,cAA0C,GAAA,EAAE,GAAA;QAC7D,MAAMC,cAAAA,GAAiBC,4BAAqBL,CAAAA,KAAK,CAACG,cAAAA,CAAAA;QAClD,OAAO;AACH,YAAA,GAAGC,cAAc;YACjBT,UAAY,EAAA;AACR,gBAAA,GAAGA,UAAU;AACb,gBAAA,GAAGS,eAAeT;AACtB;AACJ,SAAA;AACJ,KAAA;AAEA,IAAA,MAAMW,SAAY,GAAA,OACdC,QACAR,EAAAA,O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WAAAA,GAAcI,iBAAahB,OAASJ,EAAAA,cAAAA,CAAAA;SACjC,MAAA;AACH,YAAA,MAAM,IAAIa,KAAAA,CAAM,CAAC,2FAA2F,CAAC,CAAA;AACjH;QACA,OAAOG,WAAAA;AACX,KAAA;IAEA,OAAO;AACHpB,QAAAA,KAAAA;AACAM,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ import { Section, SectionOptions } from './items/section';
3
+ import { Weighted } from './items/weighted';
4
+ declare const OptionsSchema: z.ZodObject<{
5
+ logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
6
+ 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">]>>>>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
9
+ logger?: any;
10
+ }, {
11
+ parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
12
+ logger?: any;
13
+ }>;
14
+ export type Options = z.infer<typeof OptionsSchema>;
15
+ export type OptionsParam = Partial<Options>;
16
+ export interface Instance {
17
+ parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Section<T>;
18
+ parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;
19
+ }
20
+ export declare const create: (parserOptions?: OptionsParam) => Instance;
21
+ export {};
package/dist/parser.js ADDED
@@ -0,0 +1,75 @@
1
+ import * as fs from 'fs/promises';
2
+ import * as path from 'path';
3
+ import { z } from 'zod';
4
+ import { ParametersSchema } from './items/parameters.js';
5
+ import { SectionOptionsSchema } from './items/section.js';
6
+ import { DEFAULT_LOGGER, wrapLogger } from './logger.js';
7
+ import { parseMarkdown } from './parse/markdown.js';
8
+ import { parseText } from './parse/text.js';
9
+ import { isMarkdown } from './util/markdown.js';
10
+ import { isText } from './util/text.js';
11
+
12
+ const OptionsSchema = z.object({
13
+ logger: z.any().optional().default(DEFAULT_LOGGER),
14
+ parameters: ParametersSchema.optional().default({})
15
+ });
16
+ const create = (parserOptions)=>{
17
+ const options = OptionsSchema.parse(parserOptions || {});
18
+ const parameters = options.parameters;
19
+ const logger = wrapLogger(options.logger, 'Parser');
20
+ const loadOptions = (sectionOptions = {})=>{
21
+ const currentOptions = SectionOptionsSchema.parse(sectionOptions);
22
+ return {
23
+ ...currentOptions,
24
+ parameters: {
25
+ ...parameters,
26
+ ...currentOptions.parameters
27
+ }
28
+ };
29
+ };
30
+ const parseFile = async (filePath, options = {})=>{
31
+ const currentOptions = loadOptions(options);
32
+ try {
33
+ const content = await fs.readFile(filePath, 'utf-8');
34
+ // Only use the filename as title if no title was explicitly provided
35
+ const fileName = path.basename(filePath, path.extname(filePath));
36
+ return parse(content, {
37
+ ...currentOptions,
38
+ title: (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.title) || fileName
39
+ });
40
+ } catch (error) {
41
+ // Log the error or handle it appropriately
42
+ logger.error(`Error reading or parsing file with marked at ${filePath}:`, error);
43
+ throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
44
+ }
45
+ };
46
+ /**
47
+ * Reads Markdown content and parses it into a single Section.
48
+ *
49
+ * - If the content starts with a heading, that becomes the title of the returned Section
50
+ * - If no heading at the start, creates a Section with no title
51
+ * - Headers within the content create nested sections based on their depth
52
+ * - All content is organized in a hierarchical structure based on heading levels
53
+ *
54
+ * @param content The content to parse
55
+ * @returns A Section containing all content in a hierarchical structure
56
+ */ const parse = (content, options = {})=>{
57
+ const currentOptions = loadOptions(options);
58
+ let mainSection;
59
+ if (isMarkdown(content)) {
60
+ mainSection = parseMarkdown(content, currentOptions);
61
+ } else if (isText(content)) {
62
+ mainSection = parseText(content, currentOptions);
63
+ } else {
64
+ throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);
65
+ }
66
+ return mainSection;
67
+ };
68
+ return {
69
+ parse,
70
+ parseFile
71
+ };
72
+ };
73
+
74
+ export { create };
75
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sources":["../src/parser.ts"],"sourcesContent":["import * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { Section, SectionOptions, SectionOptionsSchema } from './items/section';\nimport { Weighted } from './items/weighted';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { parseMarkdown } from './parse/markdown';\nimport { parseText } from './parse/text';\nimport { isMarkdown } from './util/markdown';\nimport { isText } from './util/text';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Section<T>;\n parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;\n}\n\nexport const create = (parserOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(parserOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Parser');\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const parseFile = async <T extends Weighted>(\n filePath: string,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n // Only use the filename as title if no title was explicitly provided\n const fileName = path.basename(filePath, path.extname(filePath));\n return parse(content, {\n ...currentOptions,\n title: currentOptions?.title || fileName\n });\n } catch (error) {\n // Log the error or handle it appropriately\n logger.error(`Error reading or parsing file with marked at ${filePath}:`, error);\n throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Reads Markdown content and parses it into a single Section.\n * \n * - If the content starts with a heading, that becomes the title of the returned Section\n * - If no heading at the start, creates a Section with no title\n * - Headers within the content create nested sections based on their depth\n * - All content is organized in a hierarchical structure based on heading levels\n *\n * @param content The content to parse\n * @returns A Section containing all content in a hierarchical structure\n */\n const parse = <T extends Weighted>(\n content: string | Buffer,\n options: Partial<SectionOptions> = {}\n ): Section<T> => {\n const currentOptions = loadOptions(options);\n\n let mainSection: Section<T>;\n if (isMarkdown(content)) {\n mainSection = parseMarkdown<T>(content, currentOptions);\n } else if (isText(content)) {\n mainSection = parseText<T>(content, currentOptions);\n } else {\n throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);\n }\n return mainSection;\n }\n\n return {\n parse,\n parseFile\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","parameters","ParametersSchema","create","parserOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","parseFile","filePath","content","fs","readFile","fileName","path","basename","extname","title","error","Error","message","String","mainSection","isMarkdown","parseMarkdown","isText","parseText"],"mappings":";;;;;;;;;;;AAYA,MAAMA,aAAAA,GAAgBC,CAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYC,gBAAiBJ,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAWO,MAAMI,SAAS,CAACC,aAAAA,GAAAA;AACnB,IAAA,MAAMC,OAA6BZ,GAAAA,aAAAA,CAAca,KAAK,CAACF,iBAAiB,EAAC,CAAA;IACzE,MAAMH,UAAA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,KAAAA,CAAME,OAAO,GAAGC,OAAOH,KAAQ,CAAA,CAAA,CAAA,CAAA;AAC9H;AACJ,KAAA;AAEA;;;;;;;;;;AAUC,QACD,MAAMhB,KAAQ,GAAA,CACVQ,OACAT,EAAAA,OAAAA,GAAmC,EAAE,GAAA;AAErC,QAAA,MAAMK,iBAAiBF,WAAYH,CAAAA,OAAAA,CAAAA;QAEnC,IAAIqB,WAAAA;AACJ,QAAA,IAAIC,WAAWb,OAAU,CAAA,EAAA;AACrBY,YAAAA,WAAAA,GAAcE,cAAiBd,OAASJ,EAAAA,cAAAA,CAAAA;SACrC,MAAA,IAAImB,OAAOf,OAAU,CAAA,EAAA;AACxBY,YAAAA,WAAAA,GAAcI,UAAahB,OAASJ,EAAAA,cAAAA,CAAAA;SACjC,MAAA;AACH,YAAA,MAAM,IAAIa,KAAAA,CAAM,CAAC,2FAA2F,CAAC,CAAA;AACjH;QACA,OAAOG,WAAAA;AACX,KAAA;IAEA,OAAO;AACHpB,QAAAA,KAAAA;AACAM,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const create = ({ persona, instructions, contents, contexts })=>{
6
+ return {
7
+ persona,
8
+ instructions,
9
+ contents,
10
+ contexts
11
+ };
12
+ };
13
+
14
+ exports.create = create;
15
+ //# sourceMappingURL=prompt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.cjs","sources":["../src/prompt.ts"],"sourcesContent":["import { Content } from \"./items/content\";\nimport { Context } from \"./items/context\";\nimport { Instruction } from \"./items/instruction\";\nimport { Section } from \"./items/section\";\n\nexport interface Prompt {\n persona?: Section<Instruction>;\n instructions: Section<Instruction>;\n contents?: Section<Content>;\n contexts?: Section<Context>;\n}\n\nexport const create = ({\n persona,\n instructions,\n contents,\n contexts,\n}: {\n persona?: Section<Instruction>,\n instructions: Section<Instruction>,\n contents?: Section<Content>,\n contexts?: Section<Context>\n}): Prompt => {\n\n return {\n persona,\n instructions,\n contents,\n contexts,\n }\n}"],"names":["create","persona","instructions","contents","contexts"],"mappings":";;;;AAYO,MAAMA,MAAS,GAAA,CAAC,EACnBC,OAAO,EACPC,YAAY,EACZC,QAAQ,EACRC,QAAQ,EAMX,GAAA;IAEG,OAAO;AACHH,QAAAA,OAAAA;AACAC,QAAAA,YAAAA;AACAC,QAAAA,QAAAA;AACAC,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,16 @@
1
+ import { Content } from './items/content';
2
+ import { Context } from './items/context';
3
+ import { Instruction } from './items/instruction';
4
+ import { Section } from './items/section';
5
+ export interface Prompt {
6
+ persona?: Section<Instruction>;
7
+ instructions: Section<Instruction>;
8
+ contents?: Section<Content>;
9
+ contexts?: Section<Context>;
10
+ }
11
+ export declare const create: ({ persona, instructions, contents, contexts, }: {
12
+ persona?: Section<Instruction>;
13
+ instructions: Section<Instruction>;
14
+ contents?: Section<Content>;
15
+ contexts?: Section<Context>;
16
+ }) => Prompt;
package/dist/prompt.js ADDED
@@ -0,0 +1,11 @@
1
+ const create = ({ persona, instructions, contents, contexts })=>{
2
+ return {
3
+ persona,
4
+ instructions,
5
+ contents,
6
+ contexts
7
+ };
8
+ };
9
+
10
+ export { create };
11
+ //# sourceMappingURL=prompt.js.map