@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/parse/markdown.cjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const marked = require('marked');
|
|
6
|
-
const section = require('../items/section.cjs');
|
|
7
|
-
const weighted = require('../items/weighted.cjs');
|
|
8
|
-
|
|
9
|
-
const parseMarkdown = (input, options = {})=>{
|
|
10
|
-
let markdownContent;
|
|
11
|
-
if (typeof input === 'string') {
|
|
12
|
-
markdownContent = input;
|
|
13
|
-
} else {
|
|
14
|
-
markdownContent = input.toString();
|
|
15
|
-
}
|
|
16
|
-
const sectionOptions = section.SectionOptionsSchema.parse(options);
|
|
17
|
-
// Use marked.lexer to get tokens without full parsing/rendering
|
|
18
|
-
const tokens = marked.marked.lexer(markdownContent);
|
|
19
|
-
// Create the main section (with a Title from the options)
|
|
20
|
-
const mainSection = section.create(sectionOptions);
|
|
21
|
-
// Track sections at each depth level
|
|
22
|
-
const sectionStack = [
|
|
23
|
-
mainSection
|
|
24
|
-
];
|
|
25
|
-
// Set if we've seen the first token
|
|
26
|
-
let isFirstToken = true;
|
|
27
|
-
// Set the item options
|
|
28
|
-
const itemOptions = weighted.WeightedOptionsSchema.parse({
|
|
29
|
-
...sectionOptions,
|
|
30
|
-
weight: sectionOptions.itemWeight
|
|
31
|
-
});
|
|
32
|
-
for (const token of tokens){
|
|
33
|
-
switch(token.type){
|
|
34
|
-
case 'heading':
|
|
35
|
-
{
|
|
36
|
-
const depth = token.depth;
|
|
37
|
-
// If this is the first token and it's a heading, use it as the main section title
|
|
38
|
-
if (isFirstToken) {
|
|
39
|
-
mainSection.title = token.text;
|
|
40
|
-
isFirstToken = false;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
isFirstToken = false;
|
|
44
|
-
// Create a new section with this heading
|
|
45
|
-
const newSection = section.create({
|
|
46
|
-
...sectionOptions,
|
|
47
|
-
title: token.text
|
|
48
|
-
});
|
|
49
|
-
// Ensure the section stack has the right size based on this heading's depth
|
|
50
|
-
// (e.g., a depth-2 heading should be added to the depth-1 section)
|
|
51
|
-
// We need to ensure the stack length is exactly depth, not just less than or equal to depth
|
|
52
|
-
while(sectionStack.length > depth && sectionStack.length > 1){
|
|
53
|
-
sectionStack.pop();
|
|
54
|
-
}
|
|
55
|
-
// Make sure we're at the right level for this heading
|
|
56
|
-
// If we stay at the same heading level (e.g., two h2s in sequence),
|
|
57
|
-
// we need to pop once more to get to the parent level
|
|
58
|
-
if (sectionStack.length === depth && sectionStack.length > 1) {
|
|
59
|
-
sectionStack.pop();
|
|
60
|
-
}
|
|
61
|
-
// Add new section to its parent
|
|
62
|
-
const parentSection = sectionStack[sectionStack.length - 1];
|
|
63
|
-
parentSection.add(newSection, itemOptions);
|
|
64
|
-
// Push this section onto the stack
|
|
65
|
-
sectionStack.push(newSection);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case 'paragraph':
|
|
69
|
-
{
|
|
70
|
-
isFirstToken = false;
|
|
71
|
-
const instruction = weighted.create(token.text, itemOptions);
|
|
72
|
-
const currentSection = sectionStack[sectionStack.length - 1];
|
|
73
|
-
currentSection.add(instruction, itemOptions);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
case 'list':
|
|
77
|
-
{
|
|
78
|
-
isFirstToken = false;
|
|
79
|
-
// Convert list items to instructions
|
|
80
|
-
const listInstructionContent = token.items.map((item)=>`- ${item.text}`).join('\n');
|
|
81
|
-
const listInstruction = weighted.create(listInstructionContent, itemOptions);
|
|
82
|
-
const currentSection = sectionStack[sectionStack.length - 1];
|
|
83
|
-
currentSection.add(listInstruction, itemOptions);
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
case 'code':
|
|
87
|
-
{
|
|
88
|
-
isFirstToken = false;
|
|
89
|
-
// Represent code blocks as instructions
|
|
90
|
-
const codeInstruction = weighted.create(`\`\`\`${token.lang || ''}\n${token.text}\n\`\`\``, itemOptions);
|
|
91
|
-
const currentSection = sectionStack[sectionStack.length - 1];
|
|
92
|
-
currentSection.add(codeInstruction, itemOptions);
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
case 'space':
|
|
96
|
-
break;
|
|
97
|
-
default:
|
|
98
|
-
{
|
|
99
|
-
isFirstToken = false;
|
|
100
|
-
// Treat other block tokens' text as instructions for robustness
|
|
101
|
-
if ('text' in token && token.text) {
|
|
102
|
-
const fallbackInstruction = weighted.create(token.text, itemOptions);
|
|
103
|
-
const currentSection = sectionStack[sectionStack.length - 1];
|
|
104
|
-
currentSection.add(fallbackInstruction, itemOptions);
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return mainSection;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
exports.parseMarkdown = parseMarkdown;
|
|
114
|
-
//# sourceMappingURL=markdown.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.cjs","sources":["../../src/parse/markdown.ts"],"sourcesContent":["import { marked } from 'marked';\nimport { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseMarkdown = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let markdownContent;\n if (typeof input === 'string') {\n markdownContent = input;\n } else {\n markdownContent = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Use marked.lexer to get tokens without full parsing/rendering\n const tokens = marked.lexer(markdownContent);\n\n // Create the main section (with a Title from the options)\n const mainSection = createSection<T>(sectionOptions);\n\n // Track sections at each depth level\n const sectionStack: Section<T>[] = [mainSection];\n\n // Set if we've seen the first token\n let isFirstToken = true;\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n for (const token of tokens) {\n switch (token.type) {\n case 'heading': {\n const depth = token.depth;\n\n // If this is the first token and it's a heading, use it as the main section title\n if (isFirstToken) {\n mainSection.title = token.text;\n isFirstToken = false;\n break;\n }\n\n isFirstToken = false;\n\n // Create a new section with this heading\n const newSection = createSection<T>({ ...sectionOptions, title: token.text });\n\n // Ensure the section stack has the right size based on this heading's depth\n // (e.g., a depth-2 heading should be added to the depth-1 section)\n // We need to ensure the stack length is exactly depth, not just less than or equal to depth\n while (sectionStack.length > depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Make sure we're at the right level for this heading\n // If we stay at the same heading level (e.g., two h2s in sequence),\n // we need to pop once more to get to the parent level\n if (sectionStack.length === depth && sectionStack.length > 1) {\n sectionStack.pop();\n }\n\n // Add new section to its parent\n const parentSection = sectionStack[sectionStack.length - 1];\n parentSection.add(newSection, itemOptions);\n\n // Push this section onto the stack\n sectionStack.push(newSection);\n break;\n }\n\n case 'paragraph': {\n isFirstToken = false;\n const instruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(instruction, itemOptions);\n break;\n }\n\n case 'list': {\n isFirstToken = false;\n // Convert list items to instructions\n const listInstructionContent = token.items.map((item: any) => `- ${item.text}`).join('\\n');\n const listInstruction: T = createWeighted<T>(listInstructionContent, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(listInstruction, itemOptions);\n break;\n }\n\n case 'code': {\n isFirstToken = false;\n // Represent code blocks as instructions\n const codeInstruction: T = createWeighted<T>(`\\`\\`\\`${token.lang || ''}\\n${token.text}\\n\\`\\`\\``, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(codeInstruction, itemOptions);\n break;\n }\n\n case 'space':\n // Usually ignore space tokens between block elements\n break;\n\n default: {\n isFirstToken = false;\n // Treat other block tokens' text as instructions for robustness\n if ('text' in token && token.text) {\n const fallbackInstruction: T = createWeighted<T>(token.text, itemOptions);\n const currentSection = sectionStack[sectionStack.length - 1];\n currentSection.add(fallbackInstruction, itemOptions);\n }\n break;\n }\n }\n }\n return mainSection;\n}\n"],"names":["parseMarkdown","input","options","markdownContent","toString","sectionOptions","SectionOptionsSchema","parse","tokens","marked","lexer","mainSection","createSection","sectionStack","isFirstToken","itemOptions","WeightedOptionsSchema","weight","itemWeight","token","type","depth","title","text","newSection","length","pop","parentSection","add","push","instruction","createWeighted","currentSection","listInstructionContent","items","map","item","join","listInstruction","codeInstruction","lang","fallbackInstruction"],"mappings":";;;;;;;;MAIaA,aAAgB,GAAA,CACzBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,eAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,eAAkBF,GAAAA,KAAAA;KACf,MAAA;AACHE,QAAAA,eAAAA,GAAkBF,MAAMG,QAAQ,EAAA;AACpC;IAEA,MAAMC,cAAAA,GAAiBC,4BAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,MAAAA,GAASC,aAAOC,CAAAA,KAAK,CAACP,eAAAA,CAAAA;;AAG5B,IAAA,MAAMQ,cAAcC,cAAiBP,CAAAA,cAAAA,CAAAA;;AAGrC,IAAA,MAAMQ,YAA6B,GAAA;AAACF,QAAAA;AAAY,KAAA;;AAGhD,IAAA,IAAIG,YAAe,GAAA,IAAA;;IAGnB,MAAMC,WAAAA,GAAcC,8BAAsBT,CAAAA,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBY,QAAAA,MAAAA,EAAQZ,eAAea;AAC3B,KAAA,CAAA;IAEA,KAAK,MAAMC,SAASX,MAAQ,CAAA;AACxB,QAAA,OAAQW,MAAMC,IAAI;YACd,KAAK,SAAA;AAAW,gBAAA;oBACZ,MAAMC,KAAAA,GAAQF,MAA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,WAAAA;AACX;;;;"}
|
package/dist/parse/text.cjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const section = require('../items/section.cjs');
|
|
6
|
-
const weighted = require('../items/weighted.cjs');
|
|
7
|
-
|
|
8
|
-
const parseText = (input, options = {})=>{
|
|
9
|
-
let text;
|
|
10
|
-
if (typeof input === 'string') {
|
|
11
|
-
text = input;
|
|
12
|
-
} else {
|
|
13
|
-
text = input.toString();
|
|
14
|
-
}
|
|
15
|
-
const sectionOptions = section.SectionOptionsSchema.parse(options);
|
|
16
|
-
// Set the item options
|
|
17
|
-
const itemOptions = weighted.WeightedOptionsSchema.parse({
|
|
18
|
-
...sectionOptions,
|
|
19
|
-
weight: sectionOptions.itemWeight
|
|
20
|
-
});
|
|
21
|
-
// Split the text on newlines
|
|
22
|
-
const lines = text.split(/\r?\n/).filter((line)=>line.trim().length > 0);
|
|
23
|
-
// Create the main section with the supplied title
|
|
24
|
-
const mainSection = section.create(sectionOptions);
|
|
25
|
-
for (const line of lines){
|
|
26
|
-
const instruction = weighted.create(line, itemOptions);
|
|
27
|
-
mainSection.add(instruction, itemOptions);
|
|
28
|
-
}
|
|
29
|
-
return mainSection;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
exports.parseText = parseText;
|
|
33
|
-
//# sourceMappingURL=text.cjs.map
|
package/dist/parse/text.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.cjs","sources":["../../src/parse/text.ts"],"sourcesContent":["import { create as createSection, Section, SectionOptions, SectionOptionsSchema } from '../items/section';\nimport { create as createWeighted, Weighted, WeightedOptionsSchema } from '../items/weighted';\n\nexport const parseText = <T extends Weighted>(\n input: string | Buffer,\n options: Partial<SectionOptions> = {}\n): Section<T> => {\n\n let text;\n if (typeof input === 'string') {\n text = input;\n } else {\n text = input.toString();\n }\n\n const sectionOptions = SectionOptionsSchema.parse(options);\n\n // Set the item options\n const itemOptions = WeightedOptionsSchema.parse({\n ...sectionOptions,\n weight: sectionOptions.itemWeight,\n });\n\n // Split the text on newlines\n const lines = text.split(/\\r?\\n/).filter(line => line.trim().length > 0);\n\n // Create the main section with the supplied title\n const mainSection = createSection<T>(sectionOptions);\n\n for (const line of lines) {\n const instruction: T = createWeighted<T>(line, itemOptions);\n mainSection.add(instruction, itemOptions);\n }\n\n return mainSection;\n}\n"],"names":["parseText","input","options","text","toString","sectionOptions","SectionOptionsSchema","parse","itemOptions","WeightedOptionsSchema","weight","itemWeight","lines","split","filter","line","trim","length","mainSection","createSection","instruction","createWeighted","add"],"mappings":";;;;;;;MAGaA,SAAY,GAAA,CACrBC,KACAC,EAAAA,OAAAA,GAAmC,EAAE,GAAA;IAGrC,IAAIC,IAAAA;IACJ,IAAI,OAAOF,UAAU,QAAU,EAAA;QAC3BE,IAAOF,GAAAA,KAAAA;KACJ,MAAA;AACHE,QAAAA,IAAAA,GAAOF,MAAMG,QAAQ,EAAA;AACzB;IAEA,MAAMC,cAAAA,GAAiBC,4BAAqBC,CAAAA,KAAK,CAACL,OAAAA,CAAAA;;IAGlD,MAAMM,WAAAA,GAAcC,8BAAsBF,CAAAA,KAAK,CAAC;AAC5C,QAAA,GAAGF,cAAc;AACjBK,QAAAA,MAAAA,EAAQL,eAAeM;AAC3B,KAAA,CAAA;;AAGA,IAAA,MAAMC,KAAQT,GAAAA,IAAAA,CAAKU,KAAK,CAAC,OAASC,CAAAA,CAAAA,MAAM,CAACC,CAAAA,IAAQA,GAAAA,IAAAA,CAAKC,IAAI,EAAA,CAAGC,MAAM,GAAG,CAAA,CAAA;;AAGtE,IAAA,MAAMC,cAAcC,cAAiBd,CAAAA,cAAAA,CAAAA;IAErC,KAAK,MAAMU,QAAQH,KAAO,CAAA;QACtB,MAAMQ,WAAAA,GAAiBC,gBAAkBN,IAAMP,EAAAA,WAAAA,CAAAA;QAC/CU,WAAYI,CAAAA,GAAG,CAACF,WAAaZ,EAAAA,WAAAA,CAAAA;AACjC;IAEA,OAAOU,WAAAA;AACX;;;;"}
|
package/dist/parser.cjs
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const fs = require('fs/promises');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const zod = require('zod');
|
|
8
|
-
const parameters = require('./items/parameters.cjs');
|
|
9
|
-
const section = require('./items/section.cjs');
|
|
10
|
-
const logger = require('./logger.cjs');
|
|
11
|
-
const markdown$1 = require('./parse/markdown.cjs');
|
|
12
|
-
const text$1 = require('./parse/text.cjs');
|
|
13
|
-
const markdown = require('./util/markdown.cjs');
|
|
14
|
-
const text = require('./util/text.cjs');
|
|
15
|
-
|
|
16
|
-
function _interopNamespaceDefault(e) {
|
|
17
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
18
|
-
if (e) {
|
|
19
|
-
for (const k in e) {
|
|
20
|
-
if (k !== 'default') {
|
|
21
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: () => e[k]
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
n.default = e;
|
|
30
|
-
return Object.freeze(n);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
34
|
-
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
35
|
-
|
|
36
|
-
const OptionsSchema = zod.z.object({
|
|
37
|
-
logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
|
|
38
|
-
parameters: parameters.ParametersSchema.optional().default({})
|
|
39
|
-
});
|
|
40
|
-
const create = (parserOptions)=>{
|
|
41
|
-
const options = OptionsSchema.parse(parserOptions || {});
|
|
42
|
-
const parameters = options.parameters;
|
|
43
|
-
const logger$1 = logger.wrapLogger(options.logger, 'Parser');
|
|
44
|
-
const loadOptions = (sectionOptions = {})=>{
|
|
45
|
-
const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
|
|
46
|
-
return {
|
|
47
|
-
...currentOptions,
|
|
48
|
-
parameters: {
|
|
49
|
-
...parameters,
|
|
50
|
-
...currentOptions.parameters
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const parseFile = async (filePath, options = {})=>{
|
|
55
|
-
const currentOptions = loadOptions(options);
|
|
56
|
-
try {
|
|
57
|
-
const content = await fs__namespace.readFile(filePath, 'utf-8');
|
|
58
|
-
// Only use the filename as title if no title was explicitly provided
|
|
59
|
-
const fileName = path__namespace.basename(filePath, path__namespace.extname(filePath));
|
|
60
|
-
return parse(content, {
|
|
61
|
-
...currentOptions,
|
|
62
|
-
title: (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.title) || fileName
|
|
63
|
-
});
|
|
64
|
-
} catch (error) {
|
|
65
|
-
// Log the error or handle it appropriately
|
|
66
|
-
logger$1.error(`Error reading or parsing file with marked at ${filePath}:`, error);
|
|
67
|
-
throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Reads Markdown content and parses it into a single Section.
|
|
72
|
-
*
|
|
73
|
-
* - If the content starts with a heading, that becomes the title of the returned Section
|
|
74
|
-
* - If no heading at the start, creates a Section with no title
|
|
75
|
-
* - Headers within the content create nested sections based on their depth
|
|
76
|
-
* - All content is organized in a hierarchical structure based on heading levels
|
|
77
|
-
*
|
|
78
|
-
* @param content The content to parse
|
|
79
|
-
* @returns A Section containing all content in a hierarchical structure
|
|
80
|
-
*/ const parse = (content, options = {})=>{
|
|
81
|
-
const currentOptions = loadOptions(options);
|
|
82
|
-
let mainSection;
|
|
83
|
-
if (markdown.isMarkdown(content)) {
|
|
84
|
-
mainSection = markdown$1.parseMarkdown(content, currentOptions);
|
|
85
|
-
} else if (text.isText(content)) {
|
|
86
|
-
mainSection = text$1.parseText(content, currentOptions);
|
|
87
|
-
} else {
|
|
88
|
-
throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);
|
|
89
|
-
}
|
|
90
|
-
return mainSection;
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
parse,
|
|
94
|
-
parseFile
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
exports.create = create;
|
|
99
|
-
//# sourceMappingURL=parser.cjs.map
|
package/dist/parser.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.cjs","sources":["../src/parser.ts"],"sourcesContent":["import * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { Section, SectionOptions, SectionOptionsSchema } from './items/section';\nimport { Weighted } from './items/weighted';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { parseMarkdown } from './parse/markdown';\nimport { parseText } from './parse/text';\nimport { isMarkdown } from './util/markdown';\nimport { isText } from './util/text';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Section<T>;\n parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;\n}\n\nexport const create = (parserOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(parserOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Parser');\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const parseFile = async <T extends Weighted>(\n filePath: string,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n // Only use the filename as title if no title was explicitly provided\n const fileName = path.basename(filePath, path.extname(filePath));\n return parse(content, {\n ...currentOptions,\n title: currentOptions?.title || fileName\n });\n } catch (error) {\n // Log the error or handle it appropriately\n logger.error(`Error reading or parsing file with marked at ${filePath}:`, error);\n throw new Error(`Failed to parse instructions from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Reads Markdown content and parses it into a single Section.\n * \n * - If the content starts with a heading, that becomes the title of the returned Section\n * - If no heading at the start, creates a Section with no title\n * - Headers within the content create nested sections based on their depth\n * - All content is organized in a hierarchical structure based on heading levels\n *\n * @param content The content to parse\n * @returns A Section containing all content in a hierarchical structure\n */\n const parse = <T extends Weighted>(\n content: string | Buffer,\n options: Partial<SectionOptions> = {}\n ): Section<T> => {\n const currentOptions = loadOptions(options);\n\n let mainSection: Section<T>;\n if (isMarkdown(content)) {\n mainSection = parseMarkdown<T>(content, currentOptions);\n } else if (isText(content)) {\n mainSection = parseText<T>(content, currentOptions);\n } else {\n throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);\n }\n return mainSection;\n }\n\n return {\n parse,\n parseFile\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","parameters","ParametersSchema","create","parserOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","parseFile","filePath","content","fs","readFile","fileName","path","basename","extname","title","error","Error","message","String","mainSection","isMarkdown","parseMarkdown","isText","parseText"],"mappings":";;;;;;;;;;;;;;;;;;;;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|
-
|
|
5
|
-
const create = ({ persona, instructions, contents, contexts })=>{
|
|
6
|
-
return {
|
|
7
|
-
persona,
|
|
8
|
-
instructions,
|
|
9
|
-
contents,
|
|
10
|
-
contexts
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
exports.create = create;
|
|
15
|
-
//# sourceMappingURL=prompt.cjs.map
|
package/dist/prompt.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.cjs","sources":["../src/prompt.ts"],"sourcesContent":["import { Content } from \"./items/content\";\nimport { Context } from \"./items/context\";\nimport { Instruction } from \"./items/instruction\";\nimport { Section } from \"./items/section\";\n\nexport interface Prompt {\n persona?: Section<Instruction>;\n instructions: Section<Instruction>;\n contents?: Section<Content>;\n contexts?: Section<Context>;\n}\n\nexport const create = ({\n persona,\n instructions,\n contents,\n contexts,\n}: {\n persona?: Section<Instruction>,\n instructions: Section<Instruction>,\n contents?: Section<Content>,\n contexts?: Section<Context>\n}): Prompt => {\n\n return {\n persona,\n instructions,\n contents,\n contexts,\n }\n}"],"names":["create","persona","instructions","contents","contexts"],"mappings":";;;;AAYO,MAAMA,MAAS,GAAA,CAAC,EACnBC,OAAO,EACPC,YAAY,EACZC,QAAQ,EACRC,QAAQ,EAMX,GAAA;IAEG,OAAO;AACHH,QAAAA,OAAAA;AACAC,QAAAA,YAAAA;AACAC,QAAAA,QAAAA;AACAC,QAAAA;AACJ,KAAA;AACJ;;;;"}
|
package/dist/util/general.cjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const clean = (obj)=>{
|
|
6
|
-
return Object.fromEntries(Object.entries(obj).filter(([_, v])=>v !== undefined));
|
|
7
|
-
};
|
|
8
|
-
//Recursive implementation of jSON.stringify;
|
|
9
|
-
const stringifyJSON = function(obj, visited = new Set()) {
|
|
10
|
-
const arrOfKeyVals = [];
|
|
11
|
-
const arrVals = [];
|
|
12
|
-
let objKeys = [];
|
|
13
|
-
/*********CHECK FOR PRIMITIVE TYPES**********/ if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null) return '' + obj;
|
|
14
|
-
else if (typeof obj === 'string') return '"' + obj + '"';
|
|
15
|
-
/*********DETECT CIRCULAR REFERENCES**********/ if (obj instanceof Object && visited.has(obj)) {
|
|
16
|
-
return '"(circular)"';
|
|
17
|
-
} else if (Array.isArray(obj)) {
|
|
18
|
-
//check for empty array
|
|
19
|
-
if (obj[0] === undefined) return '[]';
|
|
20
|
-
else {
|
|
21
|
-
// Add array to visited before processing its elements
|
|
22
|
-
visited.add(obj);
|
|
23
|
-
obj.forEach(function(el) {
|
|
24
|
-
arrVals.push(stringifyJSON(el, visited));
|
|
25
|
-
});
|
|
26
|
-
return '[' + arrVals + ']';
|
|
27
|
-
}
|
|
28
|
-
} else if (obj instanceof Object) {
|
|
29
|
-
// Add object to visited before processing its properties
|
|
30
|
-
visited.add(obj);
|
|
31
|
-
//get object keys
|
|
32
|
-
objKeys = Object.keys(obj);
|
|
33
|
-
//set key output;
|
|
34
|
-
objKeys.forEach(function(key) {
|
|
35
|
-
const keyOut = '"' + key + '":';
|
|
36
|
-
const keyValOut = obj[key];
|
|
37
|
-
//skip functions and undefined properties
|
|
38
|
-
if (keyValOut instanceof Function || keyValOut === undefined) return; // Skip this entry entirely instead of pushing an empty string
|
|
39
|
-
else if (typeof keyValOut === 'string') arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
|
|
40
|
-
else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null) arrOfKeyVals.push(keyOut + keyValOut);
|
|
41
|
-
else if (keyValOut instanceof Object) {
|
|
42
|
-
arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return '{' + arrOfKeyVals + '}';
|
|
46
|
-
}
|
|
47
|
-
return '';
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
exports.clean = clean;
|
|
51
|
-
exports.stringifyJSON = stringifyJSON;
|
|
52
|
-
//# sourceMappingURL=general.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"general.cjs","sources":["../../src/util/general.ts"],"sourcesContent":["export const clean = (obj: any) => {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, v]) => v !== undefined)\n );\n}\n\n//Recursive implementation of jSON.stringify;\nexport const stringifyJSON = function (obj: any, visited: Set<any> = new Set()): string {\n const arrOfKeyVals: string[] = [];\n const arrVals: string[] = [];\n let objKeys: string[] = [];\n\n /*********CHECK FOR PRIMITIVE TYPES**********/\n if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null)\n return '' + obj;\n else if (typeof obj === 'string')\n return '\"' + obj + '\"';\n\n /*********DETECT CIRCULAR REFERENCES**********/\n if (obj instanceof Object && visited.has(obj)) {\n return '\"(circular)\"';\n }\n\n /*********CHECK FOR ARRAY**********/\n else if (Array.isArray(obj)) {\n //check for empty array\n if (obj[0] === undefined)\n return '[]';\n else {\n // Add array to visited before processing its elements\n visited.add(obj);\n obj.forEach(function (el) {\n arrVals.push(stringifyJSON(el, visited));\n });\n return '[' + arrVals + ']';\n }\n }\n /*********CHECK FOR OBJECT**********/\n else if (obj instanceof Object) {\n // Add object to visited before processing its properties\n visited.add(obj);\n //get object keys\n objKeys = Object.keys(obj);\n //set key output;\n objKeys.forEach(function (key) {\n const keyOut = '\"' + key + '\":';\n const keyValOut = obj[key];\n //skip functions and undefined properties\n if (keyValOut instanceof Function || keyValOut === undefined)\n return; // Skip this entry entirely instead of pushing an empty string\n else if (typeof keyValOut === 'string')\n arrOfKeyVals.push(keyOut + '\"' + keyValOut + '\"');\n else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null)\n arrOfKeyVals.push(keyOut + keyValOut);\n //check for nested objects, call recursively until no more objects\n else if (keyValOut instanceof Object) {\n arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));\n }\n });\n return '{' + arrOfKeyVals + '}';\n }\n return '';\n};"],"names":["clean","obj","Object","fromEntries","entries","filter","_","v","undefined","stringifyJSON","visited","Set","arrOfKeyVals","arrVals","objKeys","has","Array","isArray","add","forEach","el","push","keys","key","keyOut","keyValOut","Function"],"mappings":";;;;AAAO,MAAMA,QAAQ,CAACC,GAAAA,GAAAA;AAClB,IAAA,OAAOC,MAAOC,CAAAA,WAAW,CACrBD,MAAAA,CAAOE,OAAO,CAACH,GAAAA,CAAAA,CAAKI,MAAM,CAAC,CAAC,CAACC,CAAGC,EAAAA,CAAAA,CAAE,GAAKA,CAAMC,KAAAA,SAAAA,CAAAA,CAAAA;AAErD;AAEA;MACaC,aAAgB,GAAA,SAAUR,GAAQ,EAAES,OAAAA,GAAoB,IAAIC,GAAK,EAAA,EAAA;AAC1E,IAAA,MAAMC,eAAyB,EAAE;AACjC,IAAA,MAAMC,UAAoB,EAAE;AAC5B,IAAA,IAAIC,UAAoB,EAAE;mDAG1B,IAAI,OAAOb,GAAQ,KAAA,QAAA,IAAY,OAAOA,GAAAA,KAAQ,SAAaA,IAAAA,GAAAA,KAAQ,IAC/D,EAAA,OAAO,EAAKA,GAAAA,GAAAA;AACX,SAAA,IAAI,OAAOA,GAAAA,KAAQ,QACpB,EAAA,OAAO,MAAMA,GAAM,GAAA,GAAA;AAEvB,oDACA,IAAIA,GAAAA,YAAeC,UAAUQ,OAAQK,CAAAA,GAAG,CAACd,GAAM,CAAA,EAAA;QAC3C,OAAO,cAAA;AACX,KAAA,MAGK,IAAIe,KAAAA,CAAMC,OAAO,CAAChB,GAAM,CAAA,EAAA;;AAEzB,QAAA,IAAIA,GAAG,CAAC,CAAE,CAAA,KAAKO,WACX,OAAO,IAAA;AACN,aAAA;;AAEDE,YAAAA,OAAAA,CAAQQ,GAAG,CAACjB,GAAAA,CAAAA;YACZA,GAAIkB,CAAAA,OAAO,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Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const constants = require('../constants.cjs');
|
|
6
|
-
|
|
7
|
-
// Heuristic to check for Markdown syntax. This is not a full parser.
|
|
8
|
-
// It looks for common Markdown patterns.
|
|
9
|
-
const markdownRegex = /^(#+\s|\*\s|-\s|\+\s|>\s|\[.*\]\(.*\)|```|~~~|---\\s*$)/m;
|
|
10
|
-
/**
|
|
11
|
-
* Inspects a string to see if it likely contains Markdown syntax.
|
|
12
|
-
*
|
|
13
|
-
* @param input The string or Buffer content to inspect.
|
|
14
|
-
* @returns True if Markdown syntax is suspected, false otherwise.
|
|
15
|
-
*/ function isMarkdown(input) {
|
|
16
|
-
if (input == null) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
// Convert Buffer to string if necessary
|
|
20
|
-
const content = typeof input === 'string' ? input : input.toString(constants.DEFAULT_CHARACTER_ENCODING);
|
|
21
|
-
if (!content || content.trim() === '') {
|
|
22
|
-
return false; // Empty string is not considered Markdown
|
|
23
|
-
}
|
|
24
|
-
// Check for common Markdown patterns in the entire content
|
|
25
|
-
if (markdownRegex.test(content)) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
// Fallback: Check for a high prevalence of Markdown-like list/header starters
|
|
29
|
-
// or thematic breaks, or code blocks.
|
|
30
|
-
// We'll consider up to the first ~2000 characters, roughly equivalent to the byte check.
|
|
31
|
-
const effectiveContent = content.length > 2000 ? content.substring(0, 2000) : content;
|
|
32
|
-
const lines = effectiveContent.split('\n');
|
|
33
|
-
let markdownFeatureCount = 0;
|
|
34
|
-
const featurePatterns = [
|
|
35
|
-
/^#+\s+.+/,
|
|
36
|
-
/^\s*[*+-]\s+.+/,
|
|
37
|
-
/^\s*>\s+.+/,
|
|
38
|
-
/\[.+\]\(.+\)/,
|
|
39
|
-
/!\[.+\]\(.+\)/,
|
|
40
|
-
/`{1,3}[^`]+`{1,3}/,
|
|
41
|
-
/^\s*_{3,}\s*$/,
|
|
42
|
-
/^\s*-{3,}\s*$/,
|
|
43
|
-
/^\s*\*{3,}\s*$/
|
|
44
|
-
];
|
|
45
|
-
for (const line of lines){
|
|
46
|
-
// Stop checking if we have already found enough features to be confident.
|
|
47
|
-
// This is a small optimization for very long inputs that are clearly markdown early on.
|
|
48
|
-
if (markdownFeatureCount >= 2 && lines.length > 10) {
|
|
49
|
-
const significantLineCountEarly = Math.min(lines.indexOf(line) + 1, 20);
|
|
50
|
-
if (significantLineCountEarly > 0 && markdownFeatureCount / significantLineCountEarly > 0.1) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
for (const pattern of featurePatterns){
|
|
55
|
-
if (pattern.test(line.trim())) {
|
|
56
|
-
markdownFeatureCount++;
|
|
57
|
-
break; // Count each line only once
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// If more than 5% of the first few lines (up to 20 lines or all lines if fewer)
|
|
62
|
-
// show markdown features, or if there are at least 2 distinct features in short texts,
|
|
63
|
-
// consider it Markdown.
|
|
64
|
-
const significantLineCount = Math.min(lines.length, 20);
|
|
65
|
-
if (significantLineCount > 0) {
|
|
66
|
-
// Calculate the exact threshold percentage
|
|
67
|
-
const thresholdPercentage = markdownFeatureCount / significantLineCount;
|
|
68
|
-
// Check against the 5% threshold (0.05)
|
|
69
|
-
// Using >= 0.05 exactly matches 5%, > 0.05 requires more than 5%
|
|
70
|
-
if (thresholdPercentage >= 0.05 + 0.0001) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
// Other conditions for returning true
|
|
74
|
-
if (markdownFeatureCount >= 1 && significantLineCount <= 5 || markdownFeatureCount >= 2) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
} // Example usage (optional, for testing):
|
|
80
|
-
// function testIsMarkdownString() {
|
|
81
|
-
// console.log('--- Testing isMarkdownString ---');
|
|
82
|
-
// const markdown1 = '# Hello World\\nThis is a test.';
|
|
83
|
-
// console.log(`Test 1 (Header): "${markdown1.substring(0,10)}..." -> ${isMarkdownString(markdown1)}`); // true
|
|
84
|
-
// const markdown2 = '* Item 1\\n* Item 2';
|
|
85
|
-
// console.log(`Test 2 (List): "${markdown2.substring(0,10)}..." -> ${isMarkdownString(markdown2)}`); // true
|
|
86
|
-
// const markdown3 = '[Google](https://google.com)';
|
|
87
|
-
// console.log(`Test 3 (Link): "${markdown3.substring(0,15)}..." -> ${isMarkdownString(markdown3)}`); // true
|
|
88
|
-
// const markdown4 = '> This is a quote.';
|
|
89
|
-
// console.log(`Test 4 (Blockquote): "${markdown4.substring(0,10)}..." -> ${isMarkdownString(markdown4)}`); // true
|
|
90
|
-
// const markdown5 = '```javascript\\nconsole.log("hello");\\n```';
|
|
91
|
-
// console.log(`Test 5 (Code block): "${markdown5.substring(0,15)}..." -> ${isMarkdownString(markdown5)}`); // true
|
|
92
|
-
// const text1 = 'This is a plain text string.';
|
|
93
|
-
// console.log(`Test 6 (Plain text): "${text1.substring(0,10)}..." -> ${isMarkdownString(text1)}`); // false
|
|
94
|
-
// const text2 = 'hello_world.this_is_a_test_string_with_underscores_but_not_markdown_thematic_break';
|
|
95
|
-
// console.log(`Test 7 (Long non-markdown): "${text2.substring(0,10)}..." -> ${isMarkdownString(text2)}`); // false
|
|
96
|
-
// const text3 = '<xml><tag>value</tag></xml>';
|
|
97
|
-
// console.log(`Test 8 (XML): "${text3.substring(0,10)}..." -> ${isMarkdownString(text3)}`); // false
|
|
98
|
-
// const shortMarkdown = '# H';
|
|
99
|
-
// console.log(`Test 9 (Short Markdown): "${shortMarkdown}" -> ${isMarkdownString(shortMarkdown)}`); // true
|
|
100
|
-
// const shortNonMarkdown = 'Hello';
|
|
101
|
-
// console.log(`Test 10 (Short Non-Markdown): "${shortNonMarkdown}" -> ${isMarkdownString(shortNonMarkdown)}`); // false
|
|
102
|
-
// const emptyString = '';
|
|
103
|
-
// console.log(`Test 11 (Empty string): "" -> ${isMarkdownString(emptyString)}`); // false
|
|
104
|
-
// const whitespaceString = ' \t \n ';
|
|
105
|
-
// console.log(`Test 12 (Whitespace string): "${whitespaceString.substring(0,5)}..." -> ${isMarkdownString(whitespaceString)}`); // false
|
|
106
|
-
// const markdownWithManyFeatures = `# Title\\n\\n* list\\n* list2\\n\\n> quote here\\n\\n\`\`\`\\ncode\\n\`\`\`\\n\\nnormal text paragraph with a [link](url).\n---\nAnother paragraph.\nThis is just a test string to see how it performs with multiple markdown features present.\nHello world this is a very long line that does not contain any markdown syntax at all, it is just plain text that goes on and on.\n* Another list item\n* And another one\n# Another Header\n## Subheader\nThis is fun.\nOkay I think this is enough.\nFinal line.\nAnother final line.\nOne more for good measure.\nOkay that should be enough lines to test the early exit.\n`;
|
|
107
|
-
// console.log(`Test 13 (Many Features): "${markdownWithManyFeatures.substring(0,10)}..." -> ${isMarkdownString(markdownWithManyFeatures)}`); // true
|
|
108
|
-
// const htmlLike = '<div><p>Hello</p><ul><li>item</li></ul></div>';
|
|
109
|
-
// console.log(`Test 14 (HTML-like): "${htmlLike.substring(0,10)}..." -> ${isMarkdownString(htmlLike)}`); // false
|
|
110
|
-
// console.log('--- End Testing ---');
|
|
111
|
-
// }
|
|
112
|
-
// testIsMarkdownString();
|
|
113
|
-
|
|
114
|
-
exports.isMarkdown = isMarkdown;
|
|
115
|
-
//# sourceMappingURL=markdown.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.cjs","sources":["../../src/util/markdown.ts"],"sourcesContent":["import { DEFAULT_CHARACTER_ENCODING } from \"../constants\";\n\n// Heuristic to check for Markdown syntax. This is not a full parser.\n// It looks for common Markdown patterns.\nconst markdownRegex = /^(#+\\s|\\*\\s|-\\s|\\+\\s|>\\s|\\[.*\\]\\(.*\\)|```|~~~|---\\\\s*$)/m;\n\n/**\n * Inspects a string to see if it likely contains Markdown syntax.\n *\n * @param input The string or Buffer content to inspect.\n * @returns True if Markdown syntax is suspected, false otherwise.\n */\nexport function isMarkdown(input: string | Buffer): boolean {\n if (input == null) {\n return false;\n }\n // Convert Buffer to string if necessary\n const content = typeof input === 'string' ? input : input.toString(DEFAULT_CHARACTER_ENCODING);\n if (!content || content.trim() === '') {\n return false; // Empty string is not considered Markdown\n }\n\n // Check for common Markdown patterns in the entire content\n if (markdownRegex.test(content)) {\n return true;\n }\n\n // Fallback: Check for a high prevalence of Markdown-like list/header starters\n // or thematic breaks, or code blocks.\n // We'll consider up to the first ~2000 characters, roughly equivalent to the byte check.\n const effectiveContent = content.length > 2000 ? content.substring(0, 2000) : content;\n const lines = effectiveContent.split('\\n');\n let markdownFeatureCount = 0;\n const featurePatterns = [\n /^#+\\s+.+/, // Headers (e.g., # Heading)\n /^\\s*[*+-]\\s+.+/, // List items (e.g., * item, - item, + item)\n /^\\s*>\\s+.+/, // Blockquotes (e.g., > quote)\n /\\[.+\\]\\(.+\\)/, // Links (e.g., [text](url))\n /!\\[.+\\]\\(.+\\)/, // Images (e.g., )\n /`{1,3}[^`]+`{1,3}/, // Inline code (e.g., `code`) or code blocks (```code```)\n /^\\s*_{3,}\\s*$/, // Thematic breaks (e.g., ---, ***, ___)\n /^\\s*-{3,}\\s*$/,\n /^\\s*\\*{3,}\\s*$/\n ];\n\n for (const line of lines) {\n // Stop checking if we have already found enough features to be confident.\n // This is a small optimization for very long inputs that are clearly markdown early on.\n if (markdownFeatureCount >= 2 && lines.length > 10) { // Heuristic threshold\n const significantLineCountEarly = Math.min(lines.indexOf(line) + 1, 20);\n if (significantLineCountEarly > 0 && markdownFeatureCount / significantLineCountEarly > 0.1) {\n return true;\n }\n }\n\n for (const pattern of featurePatterns) {\n if (pattern.test(line.trim())) {\n markdownFeatureCount++;\n break; // Count each line only once\n }\n }\n }\n\n // If more than 5% of the first few lines (up to 20 lines or all lines if fewer)\n // show markdown features, or if there are at least 2 distinct features in short texts,\n // consider it Markdown.\n const significantLineCount = Math.min(lines.length, 20);\n if (significantLineCount > 0) {\n // Calculate the exact threshold percentage\n const thresholdPercentage = markdownFeatureCount / significantLineCount;\n\n // Check against the 5% threshold (0.05)\n // Using >= 0.05 exactly matches 5%, > 0.05 requires more than 5%\n if (thresholdPercentage >= 0.05 + 0.0001) { // Adding a small epsilon to ensure exactly 5% passes but just below fails\n return true;\n }\n\n // Other conditions for returning true\n if ((markdownFeatureCount >= 1 && significantLineCount <= 5) || markdownFeatureCount >= 2) {\n return true;\n }\n }\n\n return false;\n}\n\n// Example usage (optional, for testing):\n// function testIsMarkdownString() {\n// console.log('--- Testing isMarkdownString ---');\n// const markdown1 = '# Hello World\\\\nThis is a test.';\n// console.log(`Test 1 (Header): \"${markdown1.substring(0,10)}...\" -> ${isMarkdownString(markdown1)}`); // true\n\n// const markdown2 = '* Item 1\\\\n* Item 2';\n// console.log(`Test 2 (List): \"${markdown2.substring(0,10)}...\" -> ${isMarkdownString(markdown2)}`); // true\n\n// const markdown3 = '[Google](https://google.com)';\n// console.log(`Test 3 (Link): \"${markdown3.substring(0,15)}...\" -> ${isMarkdownString(markdown3)}`); // true\n\n// const markdown4 = '> This is a quote.';\n// console.log(`Test 4 (Blockquote): \"${markdown4.substring(0,10)}...\" -> ${isMarkdownString(markdown4)}`); // true\n\n// const markdown5 = '```javascript\\\\nconsole.log(\"hello\");\\\\n```';\n// console.log(`Test 5 (Code block): \"${markdown5.substring(0,15)}...\" -> ${isMarkdownString(markdown5)}`); // true\n\n// const text1 = 'This is a plain text string.';\n// console.log(`Test 6 (Plain text): \"${text1.substring(0,10)}...\" -> ${isMarkdownString(text1)}`); // false\n\n// const text2 = 'hello_world.this_is_a_test_string_with_underscores_but_not_markdown_thematic_break';\n// console.log(`Test 7 (Long non-markdown): \"${text2.substring(0,10)}...\" -> ${isMarkdownString(text2)}`); // false\n\n// const text3 = '<xml><tag>value</tag></xml>';\n// console.log(`Test 8 (XML): \"${text3.substring(0,10)}...\" -> ${isMarkdownString(text3)}`); // false\n\n// const shortMarkdown = '# H';\n// console.log(`Test 9 (Short Markdown): \"${shortMarkdown}\" -> ${isMarkdownString(shortMarkdown)}`); // true\n\n// const shortNonMarkdown = 'Hello';\n// console.log(`Test 10 (Short Non-Markdown): \"${shortNonMarkdown}\" -> ${isMarkdownString(shortNonMarkdown)}`); // false\n\n// const emptyString = '';\n// console.log(`Test 11 (Empty string): \"\" -> ${isMarkdownString(emptyString)}`); // false\n\n// const whitespaceString = ' \\t \\n ';\n// console.log(`Test 12 (Whitespace string): \"${whitespaceString.substring(0,5)}...\" -> ${isMarkdownString(whitespaceString)}`); // false\n\n// const markdownWithManyFeatures = `# Title\\\\n\\\\n* list\\\\n* list2\\\\n\\\\n> quote here\\\\n\\\\n\\`\\`\\`\\\\ncode\\\\n\\`\\`\\`\\\\n\\\\nnormal text paragraph with a [link](url).\\n---\\nAnother paragraph.\\nThis is just a test string to see how it performs with multiple markdown features present.\\nHello world this is a very long line that does not contain any markdown syntax at all, it is just plain text that goes on and on.\\n* Another list item\\n* And another one\\n# Another Header\\n## Subheader\\nThis is fun.\\nOkay I think this is enough.\\nFinal line.\\nAnother final line.\\nOne more for good measure.\\nOkay that should be enough lines to test the early exit.\\n`;\n// console.log(`Test 13 (Many Features): \"${markdownWithManyFeatures.substring(0,10)}...\" -> ${isMarkdownString(markdownWithManyFeatures)}`); // true\n\n// const htmlLike = '<div><p>Hello</p><ul><li>item</li></ul></div>';\n// console.log(`Test 14 (HTML-like): \"${htmlLike.substring(0,10)}...\" -> ${isMarkdownString(htmlLike)}`); // false\n\n// console.log('--- End Testing ---');\n// }\n\n// testIsMarkdownString();\n"],"names":["markdownRegex","isMarkdown","input","content","toString","DEFAULT_CHARACTER_ENCODING","trim","test","effectiveContent","length","substring","lines","split","markdownFeatureCount","featurePatterns","line","significantLineCountEarly","Math","min","indexOf","pattern","significantLineCount","thresholdPercentage"],"mappings":";;;;;;AAEA;AACA;AACA,MAAMA,aAAgB,GAAA,0DAAA;AAEtB;;;;;IAMO,SAASC,UAAAA,CAAWC,KAAsB,EAAA;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