@riotprompt/riotprompt 0.0.1 → 0.0.2
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.
- package/dist/logger.js +4 -2
- package/dist/logger.js.map +1 -1
- package/dist/riotprompt.cjs +104 -102
- package/dist/riotprompt.cjs.map +1 -1
- package/package.json +16 -14
- package/vite.config.ts +2 -2
- package/dist/builder.cjs +0 -152
- package/dist/builder.cjs.map +0 -1
- package/dist/chat.cjs +0 -26
- package/dist/chat.cjs.map +0 -1
- package/dist/constants.cjs +0 -34
- package/dist/constants.cjs.map +0 -1
- package/dist/formatter.cjs +0 -139
- package/dist/formatter.cjs.map +0 -1
- package/dist/items/content.cjs +0 -14
- package/dist/items/content.cjs.map +0 -1
- package/dist/items/context.cjs +0 -13
- package/dist/items/context.cjs.map +0 -1
- package/dist/items/instruction.cjs +0 -13
- package/dist/items/instruction.cjs.map +0 -1
- package/dist/items/parameters.cjs +0 -53
- package/dist/items/parameters.cjs.map +0 -1
- package/dist/items/section.cjs +0 -120
- package/dist/items/section.cjs.map +0 -1
- package/dist/items/trait.cjs +0 -13
- package/dist/items/trait.cjs.map +0 -1
- package/dist/items/weighted.cjs +0 -27
- package/dist/items/weighted.cjs.map +0 -1
- package/dist/loader.cjs +0 -167
- package/dist/loader.cjs.map +0 -1
- package/dist/logger.cjs +0 -51
- package/dist/logger.cjs.map +0 -1
- package/dist/override.cjs +0 -109
- package/dist/override.cjs.map +0 -1
- package/dist/parse/markdown.cjs +0 -114
- package/dist/parse/markdown.cjs.map +0 -1
- package/dist/parse/text.cjs +0 -33
- package/dist/parse/text.cjs.map +0 -1
- package/dist/parser.cjs +0 -99
- package/dist/parser.cjs.map +0 -1
- package/dist/prompt.cjs +0 -15
- package/dist/prompt.cjs.map +0 -1
- package/dist/util/general.cjs +0 -52
- package/dist/util/general.cjs.map +0 -1
- package/dist/util/markdown.cjs +0 -115
- package/dist/util/markdown.cjs.map +0 -1
- package/dist/util/storage.cjs +0 -155
- package/dist/util/storage.cjs.map +0 -1
- package/dist/util/text.cjs +0 -42
- package/dist/util/text.cjs.map +0 -1
package/dist/items/section.cjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
const weighted = require('./weighted.cjs');
|
|
8
|
-
|
|
9
|
-
const SectionOptionsSchema = zod.z.object({
|
|
10
|
-
title: zod.z.string().optional(),
|
|
11
|
-
weight: zod.z.number().optional(),
|
|
12
|
-
itemWeight: zod.z.number().optional(),
|
|
13
|
-
parameters: parameters.ParametersSchema.optional().default({})
|
|
14
|
-
});
|
|
15
|
-
const create = (options = {})=>{
|
|
16
|
-
const items = [];
|
|
17
|
-
const sectionOptions = SectionOptionsSchema.parse(options);
|
|
18
|
-
const sectionItemOptions = weighted.WeightedOptionsSchema.parse({
|
|
19
|
-
...sectionOptions,
|
|
20
|
-
weight: sectionOptions.itemWeight
|
|
21
|
-
});
|
|
22
|
-
const append = (item, options = {})=>{
|
|
23
|
-
let itemOptions = weighted.WeightedOptionsSchema.parse(options);
|
|
24
|
-
itemOptions = {
|
|
25
|
-
...sectionItemOptions,
|
|
26
|
-
...itemOptions
|
|
27
|
-
};
|
|
28
|
-
if (Array.isArray(item)) {
|
|
29
|
-
item.forEach((item)=>{
|
|
30
|
-
append(item);
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
if (typeof item === 'string') {
|
|
34
|
-
items.push(weighted.create(item, itemOptions));
|
|
35
|
-
} else {
|
|
36
|
-
items.push(item);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return section;
|
|
40
|
-
};
|
|
41
|
-
const prepend = (item, options = {})=>{
|
|
42
|
-
let itemOptions = weighted.WeightedOptionsSchema.parse(options);
|
|
43
|
-
itemOptions = {
|
|
44
|
-
...sectionItemOptions,
|
|
45
|
-
...itemOptions
|
|
46
|
-
};
|
|
47
|
-
if (Array.isArray(item)) {
|
|
48
|
-
item.forEach((item)=>{
|
|
49
|
-
prepend(item);
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
if (typeof item === 'string') {
|
|
53
|
-
items.unshift(weighted.create(item, itemOptions));
|
|
54
|
-
} else {
|
|
55
|
-
items.unshift(item);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return section;
|
|
59
|
-
};
|
|
60
|
-
const insert = (index, item, options = {})=>{
|
|
61
|
-
let itemOptions = weighted.WeightedOptionsSchema.parse(options);
|
|
62
|
-
itemOptions = {
|
|
63
|
-
...sectionItemOptions,
|
|
64
|
-
...itemOptions
|
|
65
|
-
};
|
|
66
|
-
if (Array.isArray(item)) {
|
|
67
|
-
item.forEach((item)=>{
|
|
68
|
-
insert(index, item);
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
if (typeof item === 'string') {
|
|
72
|
-
items.splice(index, 0, weighted.create(item, itemOptions));
|
|
73
|
-
} else {
|
|
74
|
-
items.splice(index, 0, item);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return section;
|
|
78
|
-
};
|
|
79
|
-
const remove = (index)=>{
|
|
80
|
-
items.splice(index, 1);
|
|
81
|
-
return section;
|
|
82
|
-
};
|
|
83
|
-
const replace = (index, item, options = {})=>{
|
|
84
|
-
let itemOptions = weighted.WeightedOptionsSchema.parse(options);
|
|
85
|
-
itemOptions = {
|
|
86
|
-
...sectionItemOptions,
|
|
87
|
-
...itemOptions
|
|
88
|
-
};
|
|
89
|
-
if (typeof item === 'string') {
|
|
90
|
-
items[index] = weighted.create(item, itemOptions);
|
|
91
|
-
} else {
|
|
92
|
-
items[index] = item;
|
|
93
|
-
}
|
|
94
|
-
return section;
|
|
95
|
-
};
|
|
96
|
-
const add = (item, options = {})=>{
|
|
97
|
-
let itemOptions = weighted.WeightedOptionsSchema.parse(options);
|
|
98
|
-
itemOptions = {
|
|
99
|
-
...sectionItemOptions,
|
|
100
|
-
...itemOptions
|
|
101
|
-
};
|
|
102
|
-
return append(item, itemOptions);
|
|
103
|
-
};
|
|
104
|
-
const section = {
|
|
105
|
-
title: sectionOptions.title,
|
|
106
|
-
items,
|
|
107
|
-
weight: sectionOptions.weight,
|
|
108
|
-
add,
|
|
109
|
-
append,
|
|
110
|
-
prepend,
|
|
111
|
-
insert,
|
|
112
|
-
remove,
|
|
113
|
-
replace
|
|
114
|
-
};
|
|
115
|
-
return section;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
exports.SectionOptionsSchema = SectionOptionsSchema;
|
|
119
|
-
exports.create = create;
|
|
120
|
-
//# sourceMappingURL=section.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"section.cjs","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,KAAEC,CAAAA,MAAM,CAAC;IACzCC,KAAOF,EAAAA,KAAAA,CAAEG,MAAM,EAAA,CAAGC,QAAQ,EAAA;IAC1BC,MAAQL,EAAAA,KAAAA,CAAEM,MAAM,EAAA,CAAGF,QAAQ,EAAA;IAC3BG,UAAYP,EAAAA,KAAAA,CAAEM,MAA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|
@@ -1,13 +0,0 @@
|
|
|
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
|
package/dist/items/trait.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|
package/dist/items/weighted.cjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;;"}
|
package/dist/loader.cjs
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const zod = require('zod');
|
|
7
|
-
const constants = require('./constants.cjs');
|
|
8
|
-
const parameters = require('./items/parameters.cjs');
|
|
9
|
-
const section = require('./items/section.cjs');
|
|
10
|
-
const logger = require('./logger.cjs');
|
|
11
|
-
require('./items/weighted.cjs');
|
|
12
|
-
require('./formatter.cjs');
|
|
13
|
-
require('./parser.cjs');
|
|
14
|
-
require('./override.cjs');
|
|
15
|
-
require('./builder.cjs');
|
|
16
|
-
const storage = require('./util/storage.cjs');
|
|
17
|
-
|
|
18
|
-
const OptionsSchema = zod.z.object({
|
|
19
|
-
logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
|
|
20
|
-
ignorePatterns: zod.z.array(zod.z.string()).optional().default(constants.DEFAULT_IGNORE_PATTERNS),
|
|
21
|
-
parameters: parameters.ParametersSchema.optional().default({})
|
|
22
|
-
});
|
|
23
|
-
/**
|
|
24
|
-
* Extracts the first header from Markdown text
|
|
25
|
-
* @param markdownText The Markdown text to parse
|
|
26
|
-
* @returns The first header found in the Markdown or null if none is found
|
|
27
|
-
*/ function extractFirstHeader(markdownText) {
|
|
28
|
-
// Regular expression to match Markdown headers (# Header, ## Header, etc.)
|
|
29
|
-
const headerRegex = /^(#{1,6})\s+(.+?)(?:\n|$)/m;
|
|
30
|
-
const match = markdownText.match(headerRegex);
|
|
31
|
-
if (match && match[2]) {
|
|
32
|
-
return match[2].trim();
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Removes the first header from Markdown text
|
|
38
|
-
* @param markdownText The Markdown text to process
|
|
39
|
-
* @returns The Markdown text without the first header
|
|
40
|
-
*/ function removeFirstHeader(markdownText) {
|
|
41
|
-
// Regular expression to match Markdown headers (# Header, ## Header, etc.)
|
|
42
|
-
const headerRegex = /^(#{1,6})\s+(.+?)(?:\n|$)/m;
|
|
43
|
-
const match = markdownText.match(headerRegex);
|
|
44
|
-
if (match) {
|
|
45
|
-
return markdownText.replace(headerRegex, '').trim();
|
|
46
|
-
}
|
|
47
|
-
return markdownText;
|
|
48
|
-
}
|
|
49
|
-
const create = (loaderOptions)=>{
|
|
50
|
-
const options = OptionsSchema.parse(loaderOptions || {});
|
|
51
|
-
const parameters = options.parameters;
|
|
52
|
-
const logger$1 = logger.wrapLogger(options.logger, 'Loader');
|
|
53
|
-
const ignorePatterns = options.ignorePatterns;
|
|
54
|
-
const loadOptions = (sectionOptions = {})=>{
|
|
55
|
-
const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
|
|
56
|
-
return {
|
|
57
|
-
...currentOptions,
|
|
58
|
-
parameters: {
|
|
59
|
-
...parameters,
|
|
60
|
-
...currentOptions.parameters
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Loads context from the provided directories and returns instruction sections
|
|
66
|
-
*
|
|
67
|
-
* @param contextDirectories Directories containing context files
|
|
68
|
-
* @returns Array of instruction sections loaded from context directories
|
|
69
|
-
*/ const load = async (contextDirectories = [], options = {})=>{
|
|
70
|
-
const sectionOptions = loadOptions(options);
|
|
71
|
-
logger$1.debug(`Loading context from ${contextDirectories}`);
|
|
72
|
-
const contextSections = [];
|
|
73
|
-
if (!contextDirectories || contextDirectories.length === 0) {
|
|
74
|
-
logger$1.debug(`No context directories provided, returning empty context`);
|
|
75
|
-
return contextSections;
|
|
76
|
-
}
|
|
77
|
-
const storage$1 = storage.create({
|
|
78
|
-
log: logger$1.debug
|
|
79
|
-
});
|
|
80
|
-
// Add context sections from each directory
|
|
81
|
-
for (const contextDir of contextDirectories){
|
|
82
|
-
try {
|
|
83
|
-
const dirName = path.basename(contextDir);
|
|
84
|
-
logger$1.debug(`Processing context directory ${dirName}`);
|
|
85
|
-
let mainContextSection;
|
|
86
|
-
// First check if there's a context.md file
|
|
87
|
-
const contextFile = path.join(contextDir, 'context.md');
|
|
88
|
-
if (await storage$1.exists(contextFile)) {
|
|
89
|
-
logger$1.debug(`Found context.md file in ${contextDir}`);
|
|
90
|
-
const mainContextContent = await storage$1.readFile(contextFile, 'utf8');
|
|
91
|
-
// Extract the first header from the Markdown content
|
|
92
|
-
const firstHeader = extractFirstHeader(mainContextContent);
|
|
93
|
-
// Use the header from context.md as the section title, or fallback to directory name
|
|
94
|
-
const sectionTitle = firstHeader || dirName;
|
|
95
|
-
mainContextSection = section.create({
|
|
96
|
-
...sectionOptions,
|
|
97
|
-
title: sectionTitle
|
|
98
|
-
});
|
|
99
|
-
// Add content without the header
|
|
100
|
-
if (firstHeader) {
|
|
101
|
-
mainContextSection.add(removeFirstHeader(mainContextContent), {
|
|
102
|
-
...sectionOptions
|
|
103
|
-
});
|
|
104
|
-
} else {
|
|
105
|
-
mainContextSection.add(mainContextContent, {
|
|
106
|
-
...sectionOptions
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
// If no context.md exists, use directory name as title
|
|
111
|
-
mainContextSection = section.create({
|
|
112
|
-
...sectionOptions,
|
|
113
|
-
title: dirName
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
// Get all other files in the directory
|
|
117
|
-
const files = await storage$1.listFiles(contextDir);
|
|
118
|
-
const ignorePatternsRegex = ignorePatterns.map((pattern)=>new RegExp(pattern, 'i'));
|
|
119
|
-
const filteredFiles = files.filter((file)=>!ignorePatternsRegex.some((regex)=>regex.test(file)));
|
|
120
|
-
for (const file of filteredFiles){
|
|
121
|
-
// Skip the context.md file as it's already processed
|
|
122
|
-
if (file === 'context.md') continue;
|
|
123
|
-
logger$1.debug(`Processing file ${file} in ${contextDir}`);
|
|
124
|
-
const filePath = path.join(contextDir, file);
|
|
125
|
-
if (await storage$1.isFile(filePath)) {
|
|
126
|
-
const fileContent = await storage$1.readFile(filePath, 'utf8');
|
|
127
|
-
let sectionName = file;
|
|
128
|
-
let contentToAdd = fileContent;
|
|
129
|
-
// Extract header if it exists
|
|
130
|
-
if (file.endsWith('.md')) {
|
|
131
|
-
const fileHeader = extractFirstHeader(fileContent);
|
|
132
|
-
if (fileHeader) {
|
|
133
|
-
sectionName = fileHeader;
|
|
134
|
-
// Remove the header from the content
|
|
135
|
-
contentToAdd = removeFirstHeader(fileContent);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// Create a subsection with the extracted name
|
|
139
|
-
const fileSection = section.create({
|
|
140
|
-
...sectionOptions,
|
|
141
|
-
title: sectionName
|
|
142
|
-
});
|
|
143
|
-
fileSection.add(contentToAdd, {
|
|
144
|
-
...sectionOptions
|
|
145
|
-
});
|
|
146
|
-
// Add this file section to the main context section
|
|
147
|
-
mainContextSection.add(fileSection, {
|
|
148
|
-
...sectionOptions
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
contextSections.push(mainContextSection);
|
|
153
|
-
} catch (error) {
|
|
154
|
-
logger$1.error(`Error processing context directory ${contextDir}: ${error}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return contextSections;
|
|
158
|
-
};
|
|
159
|
-
return {
|
|
160
|
-
load
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
exports.create = create;
|
|
165
|
-
exports.extractFirstHeader = extractFirstHeader;
|
|
166
|
-
exports.removeFirstHeader = removeFirstHeader;
|
|
167
|
-
//# sourceMappingURL=loader.cjs.map
|
package/dist/loader.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader.cjs","sources":["../src/loader.ts"],"sourcesContent":["import path from \"path\";\nimport { z } from \"zod\";\nimport { DEFAULT_IGNORE_PATTERNS } from \"./constants\";\nimport { ParametersSchema } from \"./items/parameters\";\nimport { SectionOptions, SectionOptionsSchema } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Section, Weighted, createSection } from \"./riotprompt\";\nimport * as Storage from \"./util/storage\";\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n load: <T extends Weighted>(contextDirectories?: string[], options?: SectionOptions) => Promise<Section<T>[]>;\n}\n\n/**\n * Extracts the first header from Markdown text\n * @param markdownText The Markdown text to parse\n * @returns The first header found in the Markdown or null if none is found\n */\nexport function extractFirstHeader(markdownText: string): string | null {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match && match[2]) {\n return match[2].trim();\n }\n\n return null;\n}\n\n/**\n * Removes the first header from Markdown text\n * @param markdownText The Markdown text to process\n * @returns The Markdown text without the first header\n */\nexport function removeFirstHeader(markdownText: string): string {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match) {\n return markdownText.replace(headerRegex, '').trim();\n }\n\n return markdownText;\n}\n\nexport const create = (loaderOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(loaderOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Loader');\n const ignorePatterns = options.ignorePatterns;\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n /**\n * Loads context from the provided directories and returns instruction sections\n * \n * @param contextDirectories Directories containing context files\n * @returns Array of instruction sections loaded from context directories\n */\n const load = async<T extends Weighted>(\n contextDirectories: string[] = [],\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const sectionOptions = loadOptions(options);\n\n logger.debug(`Loading context from ${contextDirectories}`);\n const contextSections: Section<T>[] = [];\n\n if (!contextDirectories || contextDirectories.length === 0) {\n logger.debug(`No context directories provided, returning empty context`);\n return contextSections;\n }\n\n const storage = Storage.create({ log: logger.debug });\n\n // Add context sections from each directory\n for (const contextDir of contextDirectories) {\n try {\n const dirName = path.basename(contextDir);\n logger.debug(`Processing context directory ${dirName}`);\n let mainContextSection: Section<T>;\n\n // First check if there's a context.md file\n const contextFile = path.join(contextDir, 'context.md');\n\n if (await storage.exists(contextFile)) {\n logger.debug(`Found context.md file in ${contextDir}`);\n const mainContextContent = await storage.readFile(contextFile, 'utf8');\n // Extract the first header from the Markdown content\n const firstHeader = extractFirstHeader(mainContextContent);\n\n // Use the header from context.md as the section title, or fallback to directory name\n const sectionTitle = firstHeader || dirName;\n mainContextSection = createSection<T>({ ...sectionOptions, title: sectionTitle });\n\n // Add content without the header\n if (firstHeader) {\n mainContextSection.add(removeFirstHeader(mainContextContent), { ...sectionOptions });\n } else {\n mainContextSection.add(mainContextContent, { ...sectionOptions });\n }\n } else {\n // If no context.md exists, use directory name as title\n mainContextSection = createSection<T>({ ...sectionOptions, title: dirName });\n }\n\n // Get all other files in the directory\n const files = await storage.listFiles(contextDir);\n const ignorePatternsRegex = ignorePatterns.map(pattern => new RegExp(pattern, 'i'));\n\n const filteredFiles = files.filter(file =>\n !ignorePatternsRegex.some(regex => regex.test(file))\n );\n\n for (const file of filteredFiles) {\n // Skip the context.md file as it's already processed\n if (file === 'context.md') continue;\n\n logger.debug(`Processing file ${file} in ${contextDir}`);\n const filePath = path.join(contextDir, file);\n if (await storage.isFile(filePath)) {\n const fileContent = await storage.readFile(filePath, 'utf8');\n let sectionName = file;\n let contentToAdd = fileContent;\n\n // Extract header if it exists\n if (file.endsWith('.md')) {\n const fileHeader = extractFirstHeader(fileContent);\n if (fileHeader) {\n sectionName = fileHeader;\n // Remove the header from the content\n contentToAdd = removeFirstHeader(fileContent);\n }\n }\n\n // Create a subsection with the extracted name\n const fileSection = createSection<T>({ ...sectionOptions, title: sectionName });\n fileSection.add(contentToAdd, { ...sectionOptions });\n\n // Add this file section to the main context section\n mainContextSection.add(fileSection as unknown as T, { ...sectionOptions });\n }\n }\n\n contextSections.push(mainContextSection);\n } catch (error) {\n logger.error(`Error processing context directory ${contextDir}: ${error}`);\n }\n }\n\n return contextSections;\n }\n\n\n return {\n load\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","ignorePatterns","array","string","DEFAULT_IGNORE_PATTERNS","parameters","ParametersSchema","extractFirstHeader","markdownText","headerRegex","match","trim","removeFirstHeader","replace","create","loaderOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","load","contextDirectories","debug","contextSections","length","storage","Storage","log","contextDir","dirName","path","basename","mainContextSection","contextFile","join","exists","mainContextContent","readFile","firstHeader","sectionTitle","createSection","title","add","files","listFiles","ignorePatternsRegex","map","pattern","RegExp","filteredFiles","filter","file","some","regex","test","filePath","isFile","fileContent","sectionName","contentToAdd","endsWith","fileHeader","fileSection","push","error"],"mappings":";;;;;;;;;;;;;;;;;AASA,MAAMA,aAAAA,GAAgBC,KAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,MAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,qBAAAA,CAAAA;IACnCC,cAAgBP,EAAAA,KAAAA,CAAEQ,KAAK,CAACR,KAAAA,CAAES,MAAM,EAAIL,CAAAA,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAACK,iCAAAA,CAAAA;AACvDC,IAAAA,UAAAA,EAAYC,2BAAiBR,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAUA;;;;IAKO,SAASQ,kBAAAA,CAAmBC,YAAoB,EAAA;;AAEnD,IAAA,MAAMC,WAAc,GAAA,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAaE,CAAAA,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAASA,IAAAA,KAAK,CAAC,CAAA,CAAE,EAAE;AACnB,QAAA,OAAOA,KAAK,CAAC,CAAE,CAAA,CAACC,IAAI,EAAA;AACxB;IAEA,OAAO,IAAA;AACX;AAEA;;;;IAKO,SAASC,iBAAAA,CAAkBJ,YAAoB,EAAA;;AAElD,IAAA,MAAMC,WAAc,GAAA,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAaE,CAAAA,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAAO,EAAA;AACP,QAAA,OAAOF,YAAaK,CAAAA,OAAO,CAACJ,WAAAA,EAAa,IAAIE,IAAI,EAAA;AACrD;IAEA,OAAOH,YAAAA;AACX;AAEO,MAAMM,SAAS,CAACC,aAAAA,GAAAA;AACnB,IAAA,MAAMC,O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,kBAAmBU,CAAAA,GAAG,CAACoB,WAA6B,EAAA;AAAE,4BAAA,GAAG7C;AAAe,yBAAA,CAAA;AAC5E;AACJ;AAEAM,gBAAAA,eAAAA,CAAgBwC,IAAI,CAAC/B,kBAAAA,CAAAA;AACzB,aAAA,CAAE,OAAOgC,KAAO,EAAA;gBACZvE,QAAOuE,CAAAA,KAAK,CAAC,CAAC,mCAAmC,EAAEpC,UAAW,CAAA,EAAE,EAAEoC,KAAO,CAAA,CAAA,CAAA;AAC7E;AACJ;QAEA,OAAOzC,eAAAA;AACX,KAAA;IAGA,OAAO;AACHH,QAAAA;AACJ,KAAA;AACJ;;;;;;"}
|
package/dist/logger.cjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const constants = require('./constants.cjs');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_LOGGER = {
|
|
8
|
-
name: 'default',
|
|
9
|
-
debug: (message, ...args)=>console.debug(message, ...args),
|
|
10
|
-
info: (message, ...args)=>console.info(message, ...args),
|
|
11
|
-
warn: (message, ...args)=>console.warn(message, ...args),
|
|
12
|
-
error: (message, ...args)=>console.error(message, ...args),
|
|
13
|
-
verbose: (message, ...args)=>console.log(message, ...args),
|
|
14
|
-
silly: (message, ...args)=>console.log(message, ...args)
|
|
15
|
-
};
|
|
16
|
-
const wrapLogger = (toWrap, name)=>{
|
|
17
|
-
const requiredMethods = [
|
|
18
|
-
'debug',
|
|
19
|
-
'info',
|
|
20
|
-
'warn',
|
|
21
|
-
'error',
|
|
22
|
-
'verbose',
|
|
23
|
-
'silly'
|
|
24
|
-
];
|
|
25
|
-
const missingMethods = requiredMethods.filter((method)=>typeof toWrap[method] !== 'function');
|
|
26
|
-
if (missingMethods.length > 0) {
|
|
27
|
-
throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);
|
|
28
|
-
}
|
|
29
|
-
const log = (level, message, ...args)=>{
|
|
30
|
-
message = `[${constants.LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;
|
|
31
|
-
if (level === 'debug') toWrap.debug(message, ...args);
|
|
32
|
-
else if (level === 'info') toWrap.info(message, ...args);
|
|
33
|
-
else if (level === 'warn') toWrap.warn(message, ...args);
|
|
34
|
-
else if (level === 'error') toWrap.error(message, ...args);
|
|
35
|
-
else if (level === 'verbose') toWrap.verbose(message, ...args);
|
|
36
|
-
else if (level === 'silly') toWrap.silly(message, ...args);
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
name: 'wrapped',
|
|
40
|
-
debug: (message, ...args)=>log('debug', message, ...args),
|
|
41
|
-
info: (message, ...args)=>log('info', message, ...args),
|
|
42
|
-
warn: (message, ...args)=>log('warn', message, ...args),
|
|
43
|
-
error: (message, ...args)=>log('error', message, ...args),
|
|
44
|
-
verbose: (message, ...args)=>log('verbose', message, ...args),
|
|
45
|
-
silly: (message, ...args)=>log('silly', message, ...args)
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
exports.DEFAULT_LOGGER = DEFAULT_LOGGER;
|
|
50
|
-
exports.wrapLogger = wrapLogger;
|
|
51
|
-
//# sourceMappingURL=logger.cjs.map
|
package/dist/logger.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.cjs","sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { LIBRARY_NAME } from \"./constants\";\n\nexport interface Logger {\n name: string;\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n}\n\nexport const DEFAULT_LOGGER: Logger = {\n name: 'default',\n debug: (message: string, ...args: any[]) => console.debug(message, ...args),\n info: (message: string, ...args: any[]) => console.info(message, ...args),\n warn: (message: string, ...args: any[]) => console.warn(message, ...args),\n error: (message: string, ...args: any[]) => console.error(message, ...args),\n verbose: (message: string, ...args: any[]) => console.log(message, ...args),\n silly: (message: string, ...args: any[]) => console.log(message, ...args),\n}\n\nexport const wrapLogger = (toWrap: Logger, name?: string): Logger => {\n\n const requiredMethods: (keyof Logger)[] = ['debug', 'info', 'warn', 'error', 'verbose', 'silly'];\n const missingMethods = requiredMethods.filter(method => typeof toWrap[method] !== 'function');\n\n if (missingMethods.length > 0) {\n throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);\n }\n\n const log = (level: keyof Logger, message: string, ...args: any[]) => {\n message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;\n\n if (level === 'debug') toWrap.debug(message, ...args);\n else if (level === 'info') toWrap.info(message, ...args);\n else if (level === 'warn') toWrap.warn(message, ...args);\n else if (level === 'error') toWrap.error(message, ...args);\n else if (level === 'verbose') toWrap.verbose(message, ...args);\n else if (level === 'silly') toWrap.silly(message, ...args);\n }\n\n return {\n name: 'wrapped',\n debug: (message: string, ...args: any[]) => log('debug', message, ...args),\n info: (message: string, ...args: any[]) => log('info', message, ...args),\n warn: (message: string, ...args: any[]) => log('warn', message, ...args),\n error: (message: string, ...args: any[]) => log('error', message, ...args),\n verbose: (message: string, ...args: any[]) => log('verbose', message, ...args),\n silly: (message: string, ...args: any[]) => log('silly', message, ...args),\n }\n}"],"names":["DEFAULT_LOGGER","name","debug","message","args","console","info","warn","error","verbose","log","silly","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","join","level","LIBRARY_NAME"],"mappings":";;;;;;MAaaA,cAAyB,GAAA;IAClCC,IAAM,EAAA,SAAA;AACNC,IAAAA,KAAAA,EAAO,CAACC,OAAiB,EAAA,GAAGC,OAAgBC,OAAQH,CAAAA,KAAK,CAACC,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACtEE,IAAAA,IAAAA,EAAM,CAACH,OAAiB,EAA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,EAAA,GAAGC,IAAgBM,GAAAA,GAAAA,CAAI,SAASP,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACrEK,QAAAA,OAAAA,EAAS,CAACN,OAAiB,EAAA,GAAGC,IAAgBM,GAAAA,GAAAA,CAAI,WAAWP,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACzEO,QAAAA,KAAAA,EAAO,CAACR,OAAiB,EAAA,GAAGC,IAAgBM,GAAAA,GAAAA,CAAI,SAASP,OAAYC,EAAAA,GAAAA,IAAAA;AACzE,KAAA;AACJ;;;;;"}
|
package/dist/override.cjs
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const zod = require('zod');
|
|
7
|
-
const parameters = require('./items/parameters.cjs');
|
|
8
|
-
const section = require('./items/section.cjs');
|
|
9
|
-
const logger = require('./logger.cjs');
|
|
10
|
-
require('./items/weighted.cjs');
|
|
11
|
-
const formatter = require('./formatter.cjs');
|
|
12
|
-
const parser = require('./parser.cjs');
|
|
13
|
-
require('./loader.cjs');
|
|
14
|
-
require('./builder.cjs');
|
|
15
|
-
const storage = require('./util/storage.cjs');
|
|
16
|
-
|
|
17
|
-
const OptionsSchema = zod.z.object({
|
|
18
|
-
logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
|
|
19
|
-
configDir: zod.z.string().default('./overrides'),
|
|
20
|
-
overrides: zod.z.boolean().default(false),
|
|
21
|
-
parameters: parameters.ParametersSchema.optional().default({})
|
|
22
|
-
});
|
|
23
|
-
const create = (overrideOptions = {})=>{
|
|
24
|
-
const options = OptionsSchema.parse(overrideOptions);
|
|
25
|
-
const parameters = options.parameters;
|
|
26
|
-
const logger$1 = logger.wrapLogger(options === null || options === void 0 ? void 0 : options.logger, 'Override');
|
|
27
|
-
const storage$1 = storage.create({
|
|
28
|
-
log: logger$1.debug
|
|
29
|
-
});
|
|
30
|
-
const loadOptions = (sectionOptions = {})=>{
|
|
31
|
-
const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
|
|
32
|
-
return {
|
|
33
|
-
...currentOptions,
|
|
34
|
-
parameters: {
|
|
35
|
-
...parameters,
|
|
36
|
-
...currentOptions.parameters
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const override = async (overrideFile, section, sectionOptions = {})=>{
|
|
41
|
-
const currentSectionOptions = loadOptions(sectionOptions);
|
|
42
|
-
const baseFile = path.join(options.configDir, overrideFile);
|
|
43
|
-
const preFile = baseFile.replace('.md', '-pre.md');
|
|
44
|
-
const postFile = baseFile.replace('.md', '-post.md');
|
|
45
|
-
const response = {};
|
|
46
|
-
if (await storage$1.exists(preFile)) {
|
|
47
|
-
logger$1.silly('Found pre file %s', preFile);
|
|
48
|
-
const parser$1 = parser.create({
|
|
49
|
-
logger: logger$1
|
|
50
|
-
});
|
|
51
|
-
response.prepend = await parser$1.parseFile(preFile, currentSectionOptions);
|
|
52
|
-
}
|
|
53
|
-
if (await storage$1.exists(postFile)) {
|
|
54
|
-
logger$1.silly('Found post file %s', postFile);
|
|
55
|
-
const parser$1 = parser.create({
|
|
56
|
-
logger: logger$1
|
|
57
|
-
});
|
|
58
|
-
response.append = await parser$1.parseFile(postFile, currentSectionOptions);
|
|
59
|
-
}
|
|
60
|
-
if (await storage$1.exists(baseFile)) {
|
|
61
|
-
logger$1.silly('Found base file %s', baseFile);
|
|
62
|
-
if (options.overrides) {
|
|
63
|
-
logger$1.warn('WARNING: Core directives are being overwritten by custom configuration');
|
|
64
|
-
const parser$1 = parser.create({
|
|
65
|
-
logger: logger$1
|
|
66
|
-
});
|
|
67
|
-
response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
|
|
68
|
-
} else {
|
|
69
|
-
logger$1.error('ERROR: Core directives are being overwritten by custom configuration');
|
|
70
|
-
throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return response;
|
|
74
|
-
};
|
|
75
|
-
const customize = async (overrideFile, section, sectionOptions = {})=>{
|
|
76
|
-
const currentSectionOptions = loadOptions(sectionOptions);
|
|
77
|
-
const { overrideContent, prepend, append } = await override(overrideFile, section, currentSectionOptions);
|
|
78
|
-
let finalSection = section;
|
|
79
|
-
if (overrideContent) {
|
|
80
|
-
if (options.overrides) {
|
|
81
|
-
logger$1.warn('Override found, replacing content from file %s', overrideContent);
|
|
82
|
-
finalSection = overrideContent;
|
|
83
|
-
} else {
|
|
84
|
-
logger$1.error('ERROR: Core directives are being overwritten by custom configuration');
|
|
85
|
-
throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (prepend) {
|
|
89
|
-
logger$1.silly('Prepend found, adding to content from file %s', prepend);
|
|
90
|
-
finalSection = finalSection.prepend(prepend);
|
|
91
|
-
}
|
|
92
|
-
if (append) {
|
|
93
|
-
logger$1.silly('Append found, adding to content from file %s', append);
|
|
94
|
-
finalSection = finalSection.append(append);
|
|
95
|
-
}
|
|
96
|
-
const formatter$1 = formatter.create({
|
|
97
|
-
logger: logger$1
|
|
98
|
-
});
|
|
99
|
-
logger$1.silly('Final section %s:\n\n%s\n\n', logger$1.name, formatter$1.format(finalSection));
|
|
100
|
-
return finalSection;
|
|
101
|
-
};
|
|
102
|
-
return {
|
|
103
|
-
override,
|
|
104
|
-
customize
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
exports.create = create;
|
|
109
|
-
//# sourceMappingURL=override.cjs.map
|
package/dist/override.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"override.cjs","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDir: z.string().default('./overrides'),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const baseFile = path.join(options.configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n const response: { override?: Section<T>, prepend?: Section<T>, append?: Section<T> } = {};\n\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s', preFile);\n const parser = Parser.create({ logger });\n response.prepend = await parser.parseFile<T>(preFile, currentSectionOptions);\n }\n\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s', postFile);\n const parser = Parser.create({ logger });\n response.append = await parser.parseFile<T>(postFile, currentSectionOptions);\n }\n\n if (await storage.exists(baseFile)) {\n logger.silly('Found base file %s', baseFile);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration');\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { overrideContent, prepend, append }: { overrideContent?: Section<T>, prepend?: Section<T>, append?: Section<T> } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n if (prepend) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n if (append) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDir","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","baseFile","path","join","preFile","replace","postFile","response","exists","silly","parser","Parser","prepend","parseFile","append","warn","error","Error","customize","overrideContent","finalSection","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,KAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,MAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,qBAAAA,CAAAA;AACnCC,IAAAA,SAAAA,EAAWP,KAAEQ,CAAAA,MAAM,EAAGH,CAAAA,OAAO,CAAC,aAAA,CAAA;AAC9BI,IAAAA,SAAAA,EAAWT,KAAEU,CAAAA,OAAO,EAAGL,CAAAA,OAAO,CAAC,KAAA,CAAA;AAC/BM,IAAAA,UAAAA,EAAYC,2BAAiBR,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAYaQ,MAAAA,MAAAA,GAAS,CAACC,eAAAA,GAAgC,EAAE,GAAA;IACrD,MAAMC,OAAAA,GAA6BhB,aAAciB,CAAAA,KAAK,CAACF,eAAAA,CAAAA;IAEvD,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAMT,WAASe,iBAAWF,CAAAA,OAAAA,KAAAA,IAAAA,IAAAA,OAAAA,KAAAA,MAAAA,GAAAA,MAAAA,GAAAA,OAAAA,CAASb,MAAM,EAAE,UAAA,CAAA;IAC3C,MAAMgB,SAAAA,GAAUC,cAAc,CAAC;AAAEC,QAAAA,GAAAA,EAAKlB,SAAOmB;AAAM,KAAA,CAAA;AAEnD,IAAA,MAAMC,WAAc,GAAA,CAACC,cAA0C,GAAA,EAAE,GAAA;QAC7D,MAAMC,cAAAA,GAAiBC,4BAAqBT,CAAAA,KAAK,CAACO,cAAAA,CAAAA;QAClD,OAAO;AACH,YAAA,GAAGC,cAAc;YACjBb,UAAY,EAAA;AACR,gBAAA,GAAGA,UAAU;AACb,gBAAA,GAAGa,eAAeb;AACtB;AACJ,SAAA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