@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,33 @@
1
+ import { z } from 'zod';
2
+ import { Weighted, WeightedOptions } from './weighted';
3
+ export interface Section<T extends Weighted> {
4
+ title?: string;
5
+ items: (T | Section<T>)[];
6
+ weight?: number;
7
+ add: (item: T | T[] | Section<T> | Section<T>[] | string | string[], options?: Partial<WeightedOptions>) => Section<T>;
8
+ append: (item: T | T[] | Section<T> | Section<T>[] | string | string[], options?: Partial<WeightedOptions>) => Section<T>;
9
+ prepend: (item: T | T[] | Section<T> | Section<T>[] | string | string[], options?: Partial<WeightedOptions>) => Section<T>;
10
+ insert: (index: number, item: T | T[] | Section<T> | Section<T>[] | string | string[], options?: Partial<WeightedOptions>) => Section<T>;
11
+ replace: (index: number, item: T | Section<T> | string, options?: Partial<WeightedOptions>) => Section<T>;
12
+ remove: (index: number) => Section<T>;
13
+ }
14
+ export declare const SectionOptionsSchema: z.ZodObject<{
15
+ title: z.ZodOptional<z.ZodString>;
16
+ weight: z.ZodOptional<z.ZodNumber>;
17
+ itemWeight: z.ZodOptional<z.ZodNumber>;
18
+ 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">]>>>>;
19
+ }, "strip", z.ZodTypeAny, {
20
+ parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
21
+ weight?: number | undefined;
22
+ title?: string | undefined;
23
+ itemWeight?: number | undefined;
24
+ }, {
25
+ weight?: number | undefined;
26
+ parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
27
+ title?: string | undefined;
28
+ itemWeight?: number | undefined;
29
+ }>;
30
+ export type SectionOptions = z.infer<typeof SectionOptionsSchema>;
31
+ export declare const isSection: (object: any) => boolean;
32
+ export declare const convertToSection: (object: any, options?: Partial<SectionOptions>) => Section<Weighted>;
33
+ export declare const create: <T extends Weighted>(options?: Partial<SectionOptions>) => Section<T>;
@@ -0,0 +1,115 @@
1
+ import { z } from 'zod';
2
+ import { ParametersSchema } from './parameters.js';
3
+ import { WeightedOptionsSchema, create as create$1 } from './weighted.js';
4
+
5
+ const SectionOptionsSchema = z.object({
6
+ title: z.string().optional(),
7
+ weight: z.number().optional(),
8
+ itemWeight: z.number().optional(),
9
+ parameters: ParametersSchema.optional().default({})
10
+ });
11
+ const create = (options = {})=>{
12
+ const items = [];
13
+ const sectionOptions = SectionOptionsSchema.parse(options);
14
+ const sectionItemOptions = WeightedOptionsSchema.parse({
15
+ ...sectionOptions,
16
+ weight: sectionOptions.itemWeight
17
+ });
18
+ const append = (item, options = {})=>{
19
+ let itemOptions = WeightedOptionsSchema.parse(options);
20
+ itemOptions = {
21
+ ...sectionItemOptions,
22
+ ...itemOptions
23
+ };
24
+ if (Array.isArray(item)) {
25
+ item.forEach((item)=>{
26
+ append(item);
27
+ });
28
+ } else {
29
+ if (typeof item === 'string') {
30
+ items.push(create$1(item, itemOptions));
31
+ } else {
32
+ items.push(item);
33
+ }
34
+ }
35
+ return section;
36
+ };
37
+ const prepend = (item, options = {})=>{
38
+ let itemOptions = WeightedOptionsSchema.parse(options);
39
+ itemOptions = {
40
+ ...sectionItemOptions,
41
+ ...itemOptions
42
+ };
43
+ if (Array.isArray(item)) {
44
+ item.forEach((item)=>{
45
+ prepend(item);
46
+ });
47
+ } else {
48
+ if (typeof item === 'string') {
49
+ items.unshift(create$1(item, itemOptions));
50
+ } else {
51
+ items.unshift(item);
52
+ }
53
+ }
54
+ return section;
55
+ };
56
+ const insert = (index, item, options = {})=>{
57
+ let itemOptions = WeightedOptionsSchema.parse(options);
58
+ itemOptions = {
59
+ ...sectionItemOptions,
60
+ ...itemOptions
61
+ };
62
+ if (Array.isArray(item)) {
63
+ item.forEach((item)=>{
64
+ insert(index, item);
65
+ });
66
+ } else {
67
+ if (typeof item === 'string') {
68
+ items.splice(index, 0, create$1(item, itemOptions));
69
+ } else {
70
+ items.splice(index, 0, item);
71
+ }
72
+ }
73
+ return section;
74
+ };
75
+ const remove = (index)=>{
76
+ items.splice(index, 1);
77
+ return section;
78
+ };
79
+ const replace = (index, item, options = {})=>{
80
+ let itemOptions = WeightedOptionsSchema.parse(options);
81
+ itemOptions = {
82
+ ...sectionItemOptions,
83
+ ...itemOptions
84
+ };
85
+ if (typeof item === 'string') {
86
+ items[index] = create$1(item, itemOptions);
87
+ } else {
88
+ items[index] = item;
89
+ }
90
+ return section;
91
+ };
92
+ const add = (item, options = {})=>{
93
+ let itemOptions = WeightedOptionsSchema.parse(options);
94
+ itemOptions = {
95
+ ...sectionItemOptions,
96
+ ...itemOptions
97
+ };
98
+ return append(item, itemOptions);
99
+ };
100
+ const section = {
101
+ title: sectionOptions.title,
102
+ items,
103
+ weight: sectionOptions.weight,
104
+ add,
105
+ append,
106
+ prepend,
107
+ insert,
108
+ remove,
109
+ replace
110
+ };
111
+ return section;
112
+ };
113
+
114
+ export { SectionOptionsSchema, create };
115
+ //# sourceMappingURL=section.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section.js","sources":["../../src/items/section.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ParametersSchema } from \"./parameters\";\nimport { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport interface Section<T extends Weighted> {\n title?: string;\n items: (T | Section<T>)[];\n weight?: number;\n add: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n append: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n prepend: (\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n insert: (\n index: number,\n item: T | T[] | Section<T> | Section<T>[] | string | string[],\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n replace: (\n index: number,\n item: T | Section<T> | string,\n options?: Partial<WeightedOptions>\n ) => Section<T>;\n remove: (index: number) => Section<T>;\n}\n\nexport const SectionOptionsSchema = z.object({\n title: z.string().optional(),\n weight: z.number().optional(),\n itemWeight: z.number().optional(),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type SectionOptions = z.infer<typeof SectionOptionsSchema>;\n\nexport const isSection = (object: any): boolean => {\n return object !== undefined && object != null && typeof object === 'object' && 'items' in object;\n}\n\nexport const convertToSection = (\n object: any,\n options: Partial<SectionOptions> = {}\n): Section<Weighted> => {\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n const weightedOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n if (isSection(object)) {\n const section = create({ ...sectionOptions, title: object.title });\n object.items.forEach((item: any) => {\n if (isSection(item)) {\n section.append(convertToSection(item, sectionOptions));\n } else {\n section.append(createWeighted(item.text, weightedOptions));\n }\n });\n return section;\n } else {\n throw new Error('Object is not a section');\n }\n}\n\nexport const create = <T extends Weighted>(\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n const items: (T | Section<T>)[] = [];\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n const sectionItemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n const append = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n append(item);\n });\n } else {\n if (typeof item === 'string') {\n items.push(createWeighted<T>(item, itemOptions));\n } else {\n items.push(item);\n }\n }\n return section;\n }\n\n const prepend = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n prepend(item);\n });\n } else {\n if (typeof item === 'string') {\n items.unshift(createWeighted<T>(item, itemOptions));\n } else {\n items.unshift(item);\n }\n }\n return section;\n }\n\n const insert = (index: number, item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (Array.isArray(item)) {\n item.forEach((item) => {\n insert(index, item);\n });\n } else {\n if (typeof item === 'string') {\n items.splice(index, 0, createWeighted<T>(item, itemOptions));\n } else {\n items.splice(index, 0, item);\n }\n }\n return section;\n }\n\n const remove = (index: number): Section<T> => {\n items.splice(index, 1);\n return section;\n }\n\n const replace = (index: number, item: T | Section<T> | string, options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n if (typeof item === 'string') {\n items[index] = createWeighted<T>(item, itemOptions);\n } else {\n items[index] = item;\n }\n return section;\n }\n\n const add = (item: T | T[] | Section<T> | Section<T>[] | string | string[], options: Partial<WeightedOptions> = {}): Section<T> => {\n let itemOptions: WeightedOptions = WeightedOptionsSchema.parse(options);\n itemOptions = { ...sectionItemOptions, ...itemOptions };\n\n return append(item, itemOptions);\n }\n\n const section: Section<T> = {\n title: sectionOptions.title,\n items,\n weight: sectionOptions.weight,\n add,\n append,\n prepend,\n insert,\n remove,\n replace,\n }\n\n return section;\n}\n\n\n"],"names":["SectionOptionsSchema","z","object","title","string","optional","weight","number","itemWeight","parameters","ParametersSchema","default","create","options","items","sectionOptions","parse","sectionItemOptions","WeightedOptionsSchema","append","item","itemOptions","Array","isArray","forEach","push","createWeighted","section","prepend","unshift","insert","index","splice","remove","replace","add"],"mappings":";;;;AAiCaA,MAAAA,oBAAAA,GAAuBC,CAAEC,CAAAA,MAAM,CAAC;IACzCC,KAAOF,EAAAA,CAAAA,CAAEG,MAAM,EAAA,CAAGC,QAAQ,EAAA;IAC1BC,MAAQL,EAAAA,CAAAA,CAAEM,MAAM,EAAA,CAAGF,QAAQ,EAAA;IAC3BG,UAAYP,EAAAA,CAAAA,CAAEM,MAAM,EAAA,CAAGF,QAAQ,EAAA;AAC/BI,IAAAA,UAAAA,EAAYC,gBAAiBL,CAAAA,QAAQ,EAAGM,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAG;AAkCUC,MAAAA,MAAAA,GAAS,CAClBC,OA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A,EAAeX,IAA+BP,EAAAA,OAAAA,GAAoC,EAAE,GAAA;QACjG,IAAIQ,WAAAA,GAA+BH,qBAAsBF,CAAAA,KAAK,CAACH,OAAAA,CAAAA;QAC/DQ,WAAc,GAAA;AAAE,YAAA,GAAGJ,kBAAkB;AAAE,YAAA,GAAGI;AAAY,SAAA;QAEtD,IAAI,OAAOD,SAAS,QAAU,EAAA;AAC1BN,YAAAA,KAAK,CAACiB,KAAAA,CAAM,GAAGL,QAAAA,CAAkBN,IAAMC,EAAAA,WAAAA,CAAAA;SACpC,MAAA;YACHP,KAAK,CAACiB,MAAM,GAAGX,IAAAA;AACnB;QACA,OAAOO,OAAAA;AACX,KAAA;AAEA,IAAA,MAAMQ,GAAM,GAAA,CAACf,IAA+DP,EAAAA,OAAAA,GAAoC,EAAE,GAAA;QAC9G,IAAIQ,WAAAA,GAA+BH,qBAAsBF,CAAAA,KAAK,CAACH,OAAAA,CAAAA;QAC/DQ,WAAc,GAAA;AAAE,YAAA,GAAGJ,kBAAkB;AAAE,YAAA,GAAGI;AAAY,SAAA;AAEtD,QAAA,OAAOF,OAAOC,IAAMC,EAAAA,WAAAA,CAAAA;AACxB,KAAA;AAEA,IAAA,MAAMM,OAAsB,GAAA;AACxBxB,QAAAA,KAAAA,EAAOY,eAAeZ,KAAK;AAC3BW,QAAAA,KAAAA;AACAR,QAAAA,MAAAA,EAAQS,eAAeT,MAAM;AAC7B6B,QAAAA,GAAAA;AACAhB,QAAAA,MAAAA;AACAS,QAAAA,OAAAA;AACAE,QAAAA,MAAAA;AACAG,QAAAA,MAAAA;AACAC,QAAAA;AACJ,KAAA;IAEA,OAAOP,OAAAA;AACX;;;;"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const weighted = require('./weighted.cjs');
6
+
7
+ const create = (text, options = {})=>{
8
+ const weightedOptions = weighted.WeightedOptionsSchema.parse(options);
9
+ return weighted.create(text, weightedOptions);
10
+ };
11
+
12
+ exports.create = create;
13
+ //# sourceMappingURL=trait.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trait.cjs","sources":["../../src/items/trait.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Trait = Weighted;\n\nexport const create = (text: string, options: WeightedOptions = {}): Trait => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Trait>(text, weightedOptions);\n}"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;;;;;MAIaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAA2B,EAAE,GAAA;IAC9D,MAAMC,eAAAA,GAAkBC,8BAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,gBAAsBL,IAAME,EAAAA,eAAAA,CAAAA;AACvC;;;;"}
@@ -0,0 +1,3 @@
1
+ import { Weighted, WeightedOptions } from './weighted';
2
+ export type Trait = Weighted;
3
+ export declare const create: (text: string, options?: WeightedOptions) => Trait;
@@ -0,0 +1,9 @@
1
+ import { WeightedOptionsSchema, create as create$1 } from './weighted.js';
2
+
3
+ const create = (text, options = {})=>{
4
+ const weightedOptions = WeightedOptionsSchema.parse(options);
5
+ return create$1(text, weightedOptions);
6
+ };
7
+
8
+ export { create };
9
+ //# sourceMappingURL=trait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trait.js","sources":["../../src/items/trait.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Trait = Weighted;\n\nexport const create = (text: string, options: WeightedOptions = {}): Trait => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Trait>(text, weightedOptions);\n}"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;MAIaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAA2B,EAAE,GAAA;IAC9D,MAAMC,eAAAA,GAAkBC,qBAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,SAAsBL,IAAME,EAAAA,eAAAA,CAAAA;AACvC;;;;"}
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const zod = require('zod');
6
+ const parameters = require('./parameters.cjs');
7
+
8
+ zod.z.object({
9
+ text: zod.z.string(),
10
+ weight: zod.z.number().optional()
11
+ });
12
+ const WeightedOptionsSchema = zod.z.object({
13
+ weight: zod.z.number().optional(),
14
+ parameters: parameters.ParametersSchema.optional()
15
+ });
16
+ const create = (text, options = {})=>{
17
+ const weightedOptions = WeightedOptionsSchema.parse(options);
18
+ const parameterizedText = parameters.apply(text, weightedOptions.parameters);
19
+ return {
20
+ text: parameterizedText,
21
+ weight: weightedOptions.weight
22
+ };
23
+ };
24
+
25
+ exports.WeightedOptionsSchema = WeightedOptionsSchema;
26
+ exports.create = create;
27
+ //# sourceMappingURL=weighted.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weighted.cjs","sources":["../../src/items/weighted.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ParametersSchema, apply as applyParameters } from \"./parameters\";\n\nexport const WeightedSchema = z.object({\n text: z.string(),\n weight: z.number().optional(),\n});\n\nexport type Weighted = z.infer<typeof WeightedSchema>;\n\nexport const WeightedOptionsSchema = z.object({\n weight: z.number().optional(),\n parameters: ParametersSchema.optional(),\n});\n\nexport type WeightedOptions = z.infer<typeof WeightedOptionsSchema>;\n\n\nexport const create = <T extends Weighted>(\n text: string,\n options: Partial<WeightedOptions> = {}\n): T => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n const parameterizedText = applyParameters(text, weightedOptions.parameters);\n\n return {\n text: parameterizedText,\n weight: weightedOptions.weight,\n } as T;\n}"],"names":["z","object","text","string","weight","number","optional","WeightedOptionsSchema","parameters","ParametersSchema","create","options","weightedOptions","parse","parameterizedText","applyParameters"],"mappings":";;;;;;;AAG8BA,KAAEC,CAAAA,MAAM,CAAC;AACnCC,IAAAA,IAAAA,EAAMF,MAAEG,MAAM,EAAA;IACdC,MAAQJ,EAAAA,KAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ;AAC/B,CAAG;AAIUC,MAAAA,qBAAAA,GAAwBP,KAAEC,CAAAA,MAAM,CAAC;IAC1CG,MAAQJ,EAAAA,KAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC3BE,IAAAA,UAAAA,EAAYC,4BAAiBH,QAAQ;AACzC,CAAG;MAKUI,MAAS,GAAA,CAClBR,IACAS,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IAEtC,MAAMC,eAAAA,GAAkBL,qBAAsBM,CAAAA,KAAK,CAACF,OAAAA,CAAAA;AACpD,IAAA,MAAMG,iBAAoBC,GAAAA,gBAAAA,CAAgBb,IAAMU,EAAAA,eAAAA,CAAgBJ,UAAU,CAAA;IAE1E,OAAO;QACHN,IAAMY,EAAAA,iBAAAA;AACNV,QAAAA,MAAAA,EAAQQ,gBAAgBR;AAC5B,KAAA;AACJ;;;;;"}
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const WeightedSchema: z.ZodObject<{
3
+ text: z.ZodString;
4
+ weight: z.ZodOptional<z.ZodNumber>;
5
+ }, "strip", z.ZodTypeAny, {
6
+ text: string;
7
+ weight?: number | undefined;
8
+ }, {
9
+ text: string;
10
+ weight?: number | undefined;
11
+ }>;
12
+ export type Weighted = z.infer<typeof WeightedSchema>;
13
+ export declare const WeightedOptionsSchema: z.ZodObject<{
14
+ weight: z.ZodOptional<z.ZodNumber>;
15
+ parameters: 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">]>>>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ weight?: number | undefined;
18
+ parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
19
+ }, {
20
+ weight?: number | undefined;
21
+ parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
22
+ }>;
23
+ export type WeightedOptions = z.infer<typeof WeightedOptionsSchema>;
24
+ export declare const create: <T extends Weighted>(text: string, options?: Partial<WeightedOptions>) => T;
@@ -0,0 +1,22 @@
1
+ import { z } from 'zod';
2
+ import { ParametersSchema, apply } from './parameters.js';
3
+
4
+ z.object({
5
+ text: z.string(),
6
+ weight: z.number().optional()
7
+ });
8
+ const WeightedOptionsSchema = z.object({
9
+ weight: z.number().optional(),
10
+ parameters: ParametersSchema.optional()
11
+ });
12
+ const create = (text, options = {})=>{
13
+ const weightedOptions = WeightedOptionsSchema.parse(options);
14
+ const parameterizedText = apply(text, weightedOptions.parameters);
15
+ return {
16
+ text: parameterizedText,
17
+ weight: weightedOptions.weight
18
+ };
19
+ };
20
+
21
+ export { WeightedOptionsSchema, create };
22
+ //# sourceMappingURL=weighted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weighted.js","sources":["../../src/items/weighted.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ParametersSchema, apply as applyParameters } from \"./parameters\";\n\nexport const WeightedSchema = z.object({\n text: z.string(),\n weight: z.number().optional(),\n});\n\nexport type Weighted = z.infer<typeof WeightedSchema>;\n\nexport const WeightedOptionsSchema = z.object({\n weight: z.number().optional(),\n parameters: ParametersSchema.optional(),\n});\n\nexport type WeightedOptions = z.infer<typeof WeightedOptionsSchema>;\n\n\nexport const create = <T extends Weighted>(\n text: string,\n options: Partial<WeightedOptions> = {}\n): T => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n const parameterizedText = applyParameters(text, weightedOptions.parameters);\n\n return {\n text: parameterizedText,\n weight: weightedOptions.weight,\n } as T;\n}"],"names":["z","object","text","string","weight","number","optional","WeightedOptionsSchema","parameters","ParametersSchema","create","options","weightedOptions","parse","parameterizedText","applyParameters"],"mappings":";;;AAG8BA,CAAEC,CAAAA,MAAM,CAAC;AACnCC,IAAAA,IAAAA,EAAMF,EAAEG,MAAM,EAAA;IACdC,MAAQJ,EAAAA,CAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ;AAC/B,CAAG;AAIUC,MAAAA,qBAAAA,GAAwBP,CAAEC,CAAAA,MAAM,CAAC;IAC1CG,MAAQJ,EAAAA,CAAAA,CAAEK,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC3BE,IAAAA,UAAAA,EAAYC,iBAAiBH,QAAQ;AACzC,CAAG;MAKUI,MAAS,GAAA,CAClBR,IACAS,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IAEtC,MAAMC,eAAAA,GAAkBL,qBAAsBM,CAAAA,KAAK,CAACF,OAAAA,CAAAA;AACpD,IAAA,MAAMG,iBAAoBC,GAAAA,KAAAA,CAAgBb,IAAMU,EAAAA,eAAAA,CAAgBJ,UAAU,CAAA;IAE1E,OAAO;QACHN,IAAMY,EAAAA,iBAAAA;AACNV,QAAAA,MAAAA,EAAQQ,gBAAgBR;AAC5B,KAAA;AACJ;;;;"}
@@ -0,0 +1,167 @@
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
@@ -0,0 +1 @@
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,YAAaE,CAAAA,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAASA,IAAAA,KAAK,CAAC,CAAA,CAAE,EAAE;AACnB,QAAA,OAAOA,KAAK,CAAC,CAAE,CAAA,CAACC,IAAI,EAAA;AACxB;IAEA,OAAO,IAAA;AACX;AAEA;;;;IAKO,SAASC,iBAAAA,CAAkBJ,YAAoB,EAAA;;AAElD,IAAA,MAAMC,WAAc,GAAA,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAaE,CAAAA,KAAK,CAACD,WAAAA,CAAAA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AA,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;;;;;;"}
@@ -0,0 +1,35 @@
1
+ import { z } from 'zod';
2
+ import { SectionOptions } from './items/section';
3
+ import { Section, Weighted } from './riotprompt';
4
+ declare const OptionsSchema: z.ZodObject<{
5
+ logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
6
+ ignorePatterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
7
+ 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">]>>>>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
10
+ ignorePatterns: string[];
11
+ logger?: any;
12
+ }, {
13
+ parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
14
+ logger?: any;
15
+ ignorePatterns?: string[] | undefined;
16
+ }>;
17
+ export type Options = z.infer<typeof OptionsSchema>;
18
+ export type OptionsParam = Partial<Options>;
19
+ export interface Instance {
20
+ load: <T extends Weighted>(contextDirectories?: string[], options?: SectionOptions) => Promise<Section<T>[]>;
21
+ }
22
+ /**
23
+ * Extracts the first header from Markdown text
24
+ * @param markdownText The Markdown text to parse
25
+ * @returns The first header found in the Markdown or null if none is found
26
+ */
27
+ export declare function extractFirstHeader(markdownText: string): string | null;
28
+ /**
29
+ * Removes the first header from Markdown text
30
+ * @param markdownText The Markdown text to process
31
+ * @returns The Markdown text without the first header
32
+ */
33
+ export declare function removeFirstHeader(markdownText: string): string;
34
+ export declare const create: (loaderOptions?: OptionsParam) => Instance;
35
+ export {};