@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.
Files changed (50) hide show
  1. package/dist/logger.js +4 -2
  2. package/dist/logger.js.map +1 -1
  3. package/dist/riotprompt.cjs +104 -102
  4. package/dist/riotprompt.cjs.map +1 -1
  5. package/package.json +16 -14
  6. package/vite.config.ts +2 -2
  7. package/dist/builder.cjs +0 -152
  8. package/dist/builder.cjs.map +0 -1
  9. package/dist/chat.cjs +0 -26
  10. package/dist/chat.cjs.map +0 -1
  11. package/dist/constants.cjs +0 -34
  12. package/dist/constants.cjs.map +0 -1
  13. package/dist/formatter.cjs +0 -139
  14. package/dist/formatter.cjs.map +0 -1
  15. package/dist/items/content.cjs +0 -14
  16. package/dist/items/content.cjs.map +0 -1
  17. package/dist/items/context.cjs +0 -13
  18. package/dist/items/context.cjs.map +0 -1
  19. package/dist/items/instruction.cjs +0 -13
  20. package/dist/items/instruction.cjs.map +0 -1
  21. package/dist/items/parameters.cjs +0 -53
  22. package/dist/items/parameters.cjs.map +0 -1
  23. package/dist/items/section.cjs +0 -120
  24. package/dist/items/section.cjs.map +0 -1
  25. package/dist/items/trait.cjs +0 -13
  26. package/dist/items/trait.cjs.map +0 -1
  27. package/dist/items/weighted.cjs +0 -27
  28. package/dist/items/weighted.cjs.map +0 -1
  29. package/dist/loader.cjs +0 -167
  30. package/dist/loader.cjs.map +0 -1
  31. package/dist/logger.cjs +0 -51
  32. package/dist/logger.cjs.map +0 -1
  33. package/dist/override.cjs +0 -109
  34. package/dist/override.cjs.map +0 -1
  35. package/dist/parse/markdown.cjs +0 -114
  36. package/dist/parse/markdown.cjs.map +0 -1
  37. package/dist/parse/text.cjs +0 -33
  38. package/dist/parse/text.cjs.map +0 -1
  39. package/dist/parser.cjs +0 -99
  40. package/dist/parser.cjs.map +0 -1
  41. package/dist/prompt.cjs +0 -15
  42. package/dist/prompt.cjs.map +0 -1
  43. package/dist/util/general.cjs +0 -52
  44. package/dist/util/general.cjs.map +0 -1
  45. package/dist/util/markdown.cjs +0 -115
  46. package/dist/util/markdown.cjs.map +0 -1
  47. package/dist/util/storage.cjs +0 -155
  48. package/dist/util/storage.cjs.map +0 -1
  49. package/dist/util/text.cjs +0 -42
  50. package/dist/util/text.cjs.map +0 -1
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@riotprompt/riotprompt",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Get it together, and organize your prompts.",
5
5
  "type": "module",
6
- "module": "./dist/main.js",
7
- "types": "./dist/main.d.ts",
6
+ "main": "./dist/riotprompt.cjs",
7
+ "module": "./dist/riotprompt.js",
8
+ "types": "./dist/riotprompt.d.ts",
8
9
  "repository": {
9
10
  "type": "git",
10
11
  "url": "git+https://github.com/StJustReckoning/riotprompt"
11
12
  },
12
13
  "exports": {
13
14
  ".": {
15
+ "types": "./dist/riotprompt.d.ts",
14
16
  "import": "./dist/riotprompt.js",
15
- "types": "./dist/riotprompt.d.ts"
17
+ "require": "./dist/riotprompt.cjs"
16
18
  }
17
19
  },
18
20
  "keywords": [
@@ -24,26 +26,26 @@
24
26
  "author": "St. Just Reckoning <StJustReckoning@proton.me>",
25
27
  "license": "Apache-2.0",
26
28
  "devDependencies": {
27
- "@babel/core": "^7.27.1",
29
+ "@babel/core": "^7.27.3",
28
30
  "@babel/plugin-transform-modules-commonjs": "^7.27.1",
29
- "@babel/plugin-transform-runtime": "^7.27.1",
31
+ "@babel/plugin-transform-runtime": "^7.27.3",
30
32
  "@babel/plugin-transform-typescript": "^7.27.1",
31
33
  "@babel/preset-typescript": "^7.27.1",
32
- "@babel/runtime": "^7.27.1",
34
+ "@babel/runtime": "^7.27.3",
33
35
  "@doccident/doccident": "^0.0.1",
34
36
  "@eslint/eslintrc": "^3.3.1",
35
37
  "@eslint/js": "^9.27.0",
36
38
  "@rollup/plugin-replace": "^6.0.2",
37
39
  "@swc/core": "^1.11.29",
38
- "@types/node": "^22.15.21",
39
- "@typescript-eslint/eslint-plugin": "^8.32.1",
40
- "@typescript-eslint/parser": "^8.32.1",
40
+ "@types/node": "^22.15.24",
41
+ "@typescript-eslint/eslint-plugin": "^8.33.0",
42
+ "@typescript-eslint/parser": "^8.33.0",
41
43
  "@vitest/coverage-v8": "^3.1.4",
42
- "ajv": "^8.13.0",
44
+ "ajv": "^8.17.1",
43
45
  "eslint": "^9.27.0",
44
46
  "eslint-plugin-import": "^2.31.0",
45
- "globals": "^16.1.0",
46
- "minimatch": "^3.1.2",
47
+ "globals": "^16.2.0",
48
+ "minimatch": "^10.0.1",
47
49
  "rollup-plugin-preserve-shebang": "^1.0.1",
48
50
  "typescript": "^5.8.3",
49
51
  "vite": "^6.3.5",
@@ -54,7 +56,7 @@
54
56
  "dependencies": {
55
57
  "glob": "^11.0.2",
56
58
  "marked": "^15.0.12",
57
- "zod": "^3.25.27"
59
+ "zod": "^3.25.34"
58
60
  },
59
61
  "scripts": {
60
62
  "build": "vite build",
package/vite.config.ts CHANGED
@@ -96,8 +96,8 @@ export default defineConfig({
96
96
  },
97
97
  {
98
98
  format: 'cjs',
99
- entryFileNames: '[name].cjs',
100
- preserveModules: true,
99
+ entryFileNames: 'riotprompt.cjs',
100
+ preserveModules: false,
101
101
  exports: 'named',
102
102
  }
103
103
  ],
package/dist/builder.cjs DELETED
@@ -1,152 +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 prompt = require('./prompt.cjs');
12
- require('./formatter.cjs');
13
- const parser = require('./parser.cjs');
14
- const loader = require('./loader.cjs');
15
- const override = require('./override.cjs');
16
-
17
- const OptionSchema = zod.z.object({
18
- logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
19
- basePath: zod.z.string(),
20
- overridePath: zod.z.string().optional().default("./"),
21
- overrides: zod.z.boolean().optional().default(false),
22
- parameters: parameters.ParametersSchema.optional().default({})
23
- });
24
- const create = (builderOptions)=>{
25
- const options = OptionSchema.parse(builderOptions);
26
- const logger$1 = logger.wrapLogger(options.logger, 'Builder');
27
- const parser$1 = parser.create({
28
- logger: logger$1
29
- });
30
- const override$1 = override.create({
31
- logger: logger$1,
32
- configDir: options.overridePath || "./",
33
- overrides: options.overrides || false
34
- });
35
- const loader$1 = loader.create({
36
- logger: logger$1
37
- });
38
- const personaSection = section.create({
39
- title: "Persona"
40
- });
41
- const contextSection = section.create({
42
- title: "Context"
43
- });
44
- const instructionSection = section.create({
45
- title: "Instruction"
46
- });
47
- const contentSection = section.create({
48
- title: "Content"
49
- });
50
- const parameters = options.parameters;
51
- const instance = {};
52
- const loadOptions = (sectionOptions = {})=>{
53
- const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
54
- return {
55
- ...currentOptions,
56
- parameters: {
57
- ...parameters,
58
- ...currentOptions.parameters
59
- }
60
- };
61
- };
62
- const loadDirectories = async (directories, sectionOptions = {})=>{
63
- const currentOptions = loadOptions(sectionOptions);
64
- logger$1.debug("Loading directories", directories);
65
- const sections = await loader$1.load(directories, currentOptions);
66
- return sections;
67
- };
68
- const loadContext = async (contextDirectories, sectionOptions = {})=>{
69
- const currentOptions = loadOptions(sectionOptions);
70
- logger$1.debug('Loading context', contextDirectories);
71
- const context = await loadDirectories(contextDirectories, currentOptions);
72
- contextSection.add(context);
73
- return instance;
74
- };
75
- instance.loadContext = loadContext;
76
- const loadContent = async (contentDirectories, sectionOptions = {})=>{
77
- const currentOptions = loadOptions(sectionOptions);
78
- const content = await loadDirectories(contentDirectories, currentOptions);
79
- contentSection.add(content);
80
- return instance;
81
- };
82
- instance.loadContent = loadContent;
83
- const loadPath = async (contentPath, sectionOptions = {})=>{
84
- const currentOptions = loadOptions(sectionOptions);
85
- const defaultPath = path.join(options.basePath, contentPath);
86
- const section = await parser$1.parseFile(defaultPath, currentOptions);
87
- const overrideSection = await override$1.customize(contentPath, section, currentOptions);
88
- return overrideSection;
89
- };
90
- const addPersonaPath = async (contentPath, sectionOptions = {})=>{
91
- const currentOptions = loadOptions(sectionOptions);
92
- const persona = await loadPath(contentPath, currentOptions);
93
- personaSection.add(persona);
94
- return instance;
95
- };
96
- instance.addPersonaPath = addPersonaPath;
97
- const addContextPath = async (contentPath, sectionOptions = {})=>{
98
- logger$1.debug("Adding context path", contentPath);
99
- const currentOptions = loadOptions(sectionOptions);
100
- const context = await loadPath(contentPath, currentOptions);
101
- contextSection.add(context);
102
- return instance;
103
- };
104
- instance.addContextPath = addContextPath;
105
- const addInstructionPath = async (contentPath, sectionOptions = {})=>{
106
- logger$1.debug("Adding instruction path", contentPath);
107
- const currentOptions = loadOptions(sectionOptions);
108
- const instruction = await loadPath(contentPath, currentOptions);
109
- instructionSection.add(instruction);
110
- return instance;
111
- };
112
- instance.addInstructionPath = addInstructionPath;
113
- const addContentPath = async (contentPath, sectionOptions = {})=>{
114
- logger$1.debug("Adding content path", contentPath);
115
- const currentOptions = loadOptions(sectionOptions);
116
- const content = await loadPath(contentPath, currentOptions);
117
- contentSection.add(content);
118
- return instance;
119
- };
120
- instance.addContentPath = addContentPath;
121
- const addContent = async (content, sectionOptions = {})=>{
122
- logger$1.debug("Adding content", typeof content);
123
- const currentOptions = loadOptions(sectionOptions);
124
- const parsedContentSection = parser$1.parse(content, currentOptions);
125
- contentSection.add(parsedContentSection);
126
- return instance;
127
- };
128
- instance.addContent = addContent;
129
- const addContext = async (context, sectionOptions = {})=>{
130
- logger$1.debug("Adding context", typeof context);
131
- const currentOptions = loadOptions(sectionOptions);
132
- const parsedContextSection = parser$1.parse(context, currentOptions);
133
- contextSection.add(parsedContextSection);
134
- return instance;
135
- };
136
- instance.addContext = addContext;
137
- const build = async ()=>{
138
- logger$1.debug("Building prompt", {});
139
- const prompt$1 = prompt.create({
140
- persona: personaSection,
141
- contexts: contextSection,
142
- instructions: instructionSection,
143
- contents: contentSection
144
- });
145
- return prompt$1;
146
- };
147
- instance.build = build;
148
- return instance;
149
- };
150
-
151
- exports.create = create;
152
- //# sourceMappingURL=builder.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builder.cjs","sources":["../src/builder.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 { Content, Context, createPrompt, createSection, Instruction, Loader, Override, Parser, Prompt, Section, Weighted } from \"./riotprompt\";\n\nconst OptionSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n basePath: z.string(),\n overridePath: z.string().optional().default(\"./\"),\n overrides: z.boolean().optional().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionSchema>;\n\nexport type OptionsParam = Required<Pick<Options, 'basePath'>> & Partial<Omit<Options, 'basePath'>>;\n\nexport interface Instance {\n addPersonaPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContextPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addInstructionPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContentPath(contentPath: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContent(content: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n addContext(context: string, sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n loadContext(contextDirectories: string[], sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n loadContent(contentDirectories: string[], sectionOptions?: Partial<SectionOptions>): Promise<Instance>;\n build(): Promise<Prompt>;\n}\n\nexport const create = (builderOptions: OptionsParam): Instance => {\n const options: Required<Options> = OptionSchema.parse(builderOptions) as Required<Options>;\n\n const logger = wrapLogger(options.logger, 'Builder');\n const parser = Parser.create({ logger });\n const override = Override.create({\n logger, configDir: options.overridePath || \"./\",\n overrides: options.overrides || false\n });\n const loader = Loader.create({ logger });\n\n const personaSection: Section<Instruction> = createSection({ title: \"Persona\" });\n const contextSection: Section<Context> = createSection({ title: \"Context\" });\n const instructionSection: Section<Instruction> = createSection({ title: \"Instruction\" });\n const contentSection: Section<Content> = createSection({ title: \"Content\" });\n const parameters = options.parameters;\n\n\n const instance: Partial<Instance> = {}\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 loadDirectories = async <T extends Weighted>(\n directories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const currentOptions = loadOptions(sectionOptions);\n logger.debug(\"Loading directories\", directories);\n const sections: Section<T>[] = await loader.load<T>(directories, currentOptions);\n return sections;\n }\n\n const loadContext = async (\n contextDirectories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n logger.debug('Loading context', contextDirectories);\n const context: Section<Context>[] = await loadDirectories<Context>(contextDirectories, currentOptions);\n contextSection.add(context);\n return instance as Instance;\n }\n instance.loadContext = loadContext;\n\n const loadContent = async (\n contentDirectories: string[],\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n const content: Section<Content>[] = await loadDirectories<Content>(contentDirectories, currentOptions);\n contentSection.add(content);\n return instance as Instance;\n }\n instance.loadContent = loadContent;\n\n const loadPath = async <T extends Weighted>(\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(sectionOptions);\n const defaultPath = path.join(options.basePath as string, contentPath);\n const section: Section<T> = await parser.parseFile<T>(defaultPath, currentOptions);\n const overrideSection = await override.customize<T>(contentPath, section, currentOptions);\n return overrideSection;\n }\n\n const addPersonaPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n const currentOptions = loadOptions(sectionOptions);\n const persona: Section<Instruction> = await loadPath<Instruction>(contentPath, currentOptions);\n personaSection.add(persona);\n return instance as Instance;\n }\n instance.addPersonaPath = addPersonaPath;\n\n const addContextPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding context path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const context: Section<Context> = await loadPath<Context>(contentPath, currentOptions);\n contextSection.add(context);\n return instance as Instance;\n }\n instance.addContextPath = addContextPath;\n\n const addInstructionPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding instruction path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const instruction: Section<Instruction> = await loadPath<Instruction>(contentPath, currentOptions);\n instructionSection.add(instruction);\n return instance as Instance;\n }\n instance.addInstructionPath = addInstructionPath;\n\n const addContentPath = async (\n contentPath: string,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding content path\", contentPath);\n const currentOptions = loadOptions(sectionOptions);\n const content: Section<Content> = await loadPath<Content>(contentPath, currentOptions);\n contentSection.add(content);\n return instance as Instance;\n }\n instance.addContentPath = addContentPath;\n\n const addContent = async (\n content: string | Buffer,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding content\", typeof content);\n const currentOptions = loadOptions(sectionOptions);\n const parsedContentSection: Section<Content> = parser.parse<Content>(content, currentOptions);\n contentSection.add(parsedContentSection);\n return instance as Instance;\n }\n instance.addContent = addContent;\n\n const addContext = async (\n context: string | Buffer,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Instance> => {\n logger.debug(\"Adding context\", typeof context);\n const currentOptions = loadOptions(sectionOptions);\n const parsedContextSection: Section<Context> = parser.parse<Context>(context, currentOptions);\n contextSection.add(parsedContextSection);\n return instance as Instance;\n }\n instance.addContext = addContext;\n\n const build = async () => {\n logger.debug(\"Building prompt\", {});\n const prompt = createPrompt({ persona: personaSection, contexts: contextSection, instructions: instructionSection, contents: contentSection });\n return prompt;\n }\n instance.build = build;\n\n return instance as Instance;\n}\n"],"names":["OptionSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","basePath","string","overridePath","overrides","boolean","parameters","ParametersSchema","create","builderOptions","options","parse","wrapLogger","parser","Parser","override","Override","configDir","loader","Loader","personaSection","createSection","title","contextSection","instructionSection","contentSection","instance","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","loadDirectories","directories","debug","sections","load","loadContext","contextDirectories","context","add","loadContent","contentDirectories","content","loadPath","contentPath","defaultPath","path","join","section","parseFile","overrideSection","customize","addPersonaPath","persona","addContextPath","addInstructionPath","instruction","addContentPath","addContent","parsedContentSection","addContext","parsedContextSection","build","prompt","createPrompt","contexts","instructions","contents"],"mappings":";;;;;;;;;;;;;;;;AAOA,MAAMA,YAAAA,GAAeC,KAAEC,CAAAA,MAAM,CAAC;AAC1BC,IAAAA,MAAAA,EAAQF,MAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,qBAAAA,CAAAA;AACnCC,IAAAA,QAAAA,EAAUP,MAAEQ,MAAM,EAAA;AAClBC,IAAAA,YAAAA,EAAcT,MAAEQ,MAAM,EAAA,CAAGJ,QAAQ,EAAA,CAAGC,OAAO,CAAC,IAAA,CAAA;AAC5CK,IAAAA,SAAAA,EAAWV,MAAEW,OAAO,EAAA,CAAGP,QAAQ,EAAA,CAAGC,OAAO,CAAC,KAAA,CAAA;AAC1CO,IAAAA,UAAAA,EAAYC,2BAAiBT,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAkBO,MAAMS,SAAS,CAACC,cAAAA,GAA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ChC,QAAOqC,CAAAA,KAAK,CAAC,gBAAA,EAAkB,OAAOK,OAAAA,CAAAA;AACtC,QAAA,MAAMT,iBAAiBF,WAAYC,CAAAA,cAAAA,CAAAA;AACnC,QAAA,MAAMiC,oBAAyChD,GAAAA,QAAAA,CAAOF,KAAK,CAAU2B,OAAST,EAAAA,cAAAA,CAAAA;AAC9EN,QAAAA,cAAAA,CAAegB,GAAG,CAACsB,oBAAAA,CAAAA;QACnB,OAAOnC,QAAAA;AACX,KAAA;AACAA,IAAAA,QAAAA,CAASkC,UAAU,GAAGA,UAAAA;AAEtB,IAAA,MAAME,KAAQ,GAAA,UAAA;QACVlE,QAAOqC,CAAAA,KAAK,CAAC,iBAAA,EAAmB,EAAC,CAAA;AACjC,QAAA,MAAM8B,WAASC,aAAa,CAAA;YAAEX,OAASjC,EAAAA,cAAAA;YAAgB6C,QAAU1C,EAAAA,cAAAA;YAAgB2C,YAAc1C,EAAAA,kBAAAA;YAAoB2C,QAAU1C,EAAAA;AAAe,SAAA,CAAA;QAC5I,OAAOsC,QAAAA;AACX,KAAA;AACArC,IAAAA,QAAAA,CAASoC,KAAK,GAAGA,KAAAA;IAEjB,OAAOpC,QAAAA;AACX;;;;"}
package/dist/chat.cjs DELETED
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const constants = require('./constants.cjs');
6
-
7
- const getPersonaRole = (model)=>{
8
- if (model === "gpt-4o" || model === "gpt-4o-mini") {
9
- return "system";
10
- }
11
- return constants.DEFAULT_PERSONA_ROLE;
12
- };
13
- const createRequest = (model)=>{
14
- const messages = [];
15
- return {
16
- model,
17
- messages,
18
- addMessage: (message)=>{
19
- messages.push(message);
20
- }
21
- };
22
- };
23
-
24
- exports.createRequest = createRequest;
25
- exports.getPersonaRole = getPersonaRole;
26
- //# sourceMappingURL=chat.cjs.map
package/dist/chat.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat.cjs","sources":["../src/chat.ts"],"sourcesContent":["import { DEFAULT_PERSONA_ROLE } from \"./constants\";\n\nexport type Role = \"user\" | \"assistant\" | \"system\" | \"developer\";\n\nexport type Model = \"gpt-4o\" | \"gpt-4o-mini\" | \"o1-preview\" | \"o1-mini\" | \"o1\" | \"o3-mini\" | \"o1-pro\";\n\nexport interface Message {\n role: Role;\n content: string | string[];\n name?: string;\n}\n\nexport interface Request {\n messages: Message[];\n model: Model;\n\n addMessage(message: Message): void;\n}\n\nexport const getPersonaRole = (model: Model): Role => {\n if (model === \"gpt-4o\" || model === \"gpt-4o-mini\") {\n return \"system\";\n }\n return DEFAULT_PERSONA_ROLE;\n}\n\nexport const createRequest = (model: Model): Request => {\n const messages: Message[] = [];\n\n return {\n model,\n messages,\n addMessage: (message: Message) => {\n messages.push(message);\n }\n }\n}\n"],"names":["getPersonaRole","model","DEFAULT_PERSONA_ROLE","createRequest","messages","addMessage","message","push"],"mappings":";;;;;;AAmBO,MAAMA,iBAAiB,CAACC,KAAAA,GAAAA;IAC3B,IAAIA,KAAAA,KAAU,QAAYA,IAAAA,KAAAA,KAAU,aAAe,EAAA;QAC/C,OAAO,QAAA;AACX;IACA,OAAOC,8BAAAA;AACX;AAEO,MAAMC,gBAAgB,CAACF,KAAAA,GAAAA;AAC1B,IAAA,MAAMG,WAAsB,EAAE;IAE9B,OAAO;AACHH,QAAAA,KAAAA;AACAG,QAAAA,QAAAA;AACAC,QAAAA,UAAAA,EAAY,CAACC,OAAAA,GAAAA;AACTF,YAAAA,QAAAA,CAASG,IAAI,CAACD,OAAAA,CAAAA;AAClB;AACJ,KAAA;AACJ;;;;;"}
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const DEFAULT_CHARACTER_ENCODING = "utf8";
6
- const LIBRARY_NAME = "riotprompt";
7
- const DEFAULT_PERSONA_ROLE = "developer";
8
- const DEFAULT_IGNORE_PATTERNS = [
9
- "^\\..*",
10
- "\\.(jpg|jpeg|png|gif|bmp|svg|webp|ico)$",
11
- "\\.(mp3|wav|ogg|aac|flac)$",
12
- "\\.(mp4|mov|avi|mkv|webm)$",
13
- "\\.(pdf|doc|docx|xls|xlsx|ppt|pptx)$",
14
- "\\.(zip|tar|gz|rar|7z)$" // Compressed files
15
- ];
16
- const DEFAULT_SECTION_SEPARATOR = "tag";
17
- const DEFAULT_SECTION_INDENTATION = true;
18
- const DEFAULT_SECTION_TITLE_PROPERTY = "title";
19
- const DEFAULT_FORMAT_OPTIONS = {
20
- sectionSeparator: DEFAULT_SECTION_SEPARATOR,
21
- sectionIndentation: DEFAULT_SECTION_INDENTATION,
22
- sectionTitleProperty: DEFAULT_SECTION_TITLE_PROPERTY,
23
- sectionDepth: 0
24
- };
25
-
26
- exports.DEFAULT_CHARACTER_ENCODING = DEFAULT_CHARACTER_ENCODING;
27
- exports.DEFAULT_FORMAT_OPTIONS = DEFAULT_FORMAT_OPTIONS;
28
- exports.DEFAULT_IGNORE_PATTERNS = DEFAULT_IGNORE_PATTERNS;
29
- exports.DEFAULT_PERSONA_ROLE = DEFAULT_PERSONA_ROLE;
30
- exports.DEFAULT_SECTION_INDENTATION = DEFAULT_SECTION_INDENTATION;
31
- exports.DEFAULT_SECTION_SEPARATOR = DEFAULT_SECTION_SEPARATOR;
32
- exports.DEFAULT_SECTION_TITLE_PROPERTY = DEFAULT_SECTION_TITLE_PROPERTY;
33
- exports.LIBRARY_NAME = LIBRARY_NAME;
34
- //# sourceMappingURL=constants.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.cjs","sources":["../src/constants.ts"],"sourcesContent":["import { SectionSeparator } from \"formatter\";\n\nimport { FormatOptions } from \"formatter\";\n\nexport const DEFAULT_CHARACTER_ENCODING = \"utf8\";\nexport const LIBRARY_NAME = \"riotprompt\";\n\nexport const DEFAULT_PERSONA_ROLE = \"developer\";\n\nexport const DEFAULT_INSTRUCTIONS_AREA_TITLE = \"Instructions\";\nexport const DEFAULT_CONTENTS_AREA_TITLE = \"Contents\";\nexport const DEFAULT_CONTEXT_AREA_TITLE = \"Context\";\n\nexport const DEFAULT_IGNORE_PATTERNS: string[] = [\n \"^\\\\..*\", // Hidden files (e.g., .git, .DS_Store)\n \"\\\\.(jpg|jpeg|png|gif|bmp|svg|webp|ico)$\", // Image files\n \"\\\\.(mp3|wav|ogg|aac|flac)$\", // Audio files\n \"\\\\.(mp4|mov|avi|mkv|webm)$\", // Video files\n \"\\\\.(pdf|doc|docx|xls|xlsx|ppt|pptx)$\", // Document files\n \"\\\\.(zip|tar|gz|rar|7z)$\" // Compressed files\n];\n\nexport const DEFAULT_SECTION_SEPARATOR: SectionSeparator = \"tag\";\nexport const DEFAULT_SECTION_INDENTATION = true;\nexport const DEFAULT_SECTION_TAG = \"section\";\nexport const DEFAULT_SECTION_TITLE_PROPERTY = \"title\";\n\nexport const DEFAULT_FORMAT_OPTIONS: FormatOptions = {\n sectionSeparator: DEFAULT_SECTION_SEPARATOR,\n sectionIndentation: DEFAULT_SECTION_INDENTATION,\n sectionTitleProperty: DEFAULT_SECTION_TITLE_PROPERTY,\n sectionDepth: 0,\n}\n"],"names":["DEFAULT_CHARACTER_ENCODING","LIBRARY_NAME","DEFAULT_PERSONA_ROLE","DEFAULT_IGNORE_PATTERNS","DEFAULT_SECTION_SEPARATOR","DEFAULT_SECTION_INDENTATION","DEFAULT_SECTION_TITLE_PROPERTY","DEFAULT_FORMAT_OPTIONS","sectionSeparator","sectionIndentation","sectionTitleProperty","sectionDepth"],"mappings":";;;;AAIO,MAAMA,6BAA6B;AACnC,MAAMC,eAAe;AAErB,MAAMC,uBAAuB;MAMvBC,uBAAoC,GAAA;AAC7C,IAAA,QAAA;AACA,IAAA,yCAAA;AACA,IAAA,4BAAA;AACA,IAAA,4BAAA;AACA,IAAA,sCAAA;AACA,IAAA,yBAAA;;AAGG,MAAMC,4BAA8C;AACpD,MAAMC,8BAA8B;AAEpC,MAAMC,iCAAiC;MAEjCC,sBAAwC,GAAA;IACjDC,gBAAkBJ,EAAAA,yBAAAA;IAClBK,kBAAoBJ,EAAAA,2BAAAA;IACpBK,oBAAsBJ,EAAAA,8BAAAA;IACtBK,YAAc,EAAA;AAClB;;;;;;;;;;;"}
@@ -1,139 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const zod = require('zod');
6
- const chat = require('./chat.cjs');
7
- const constants = require('./constants.cjs');
8
- const logger = require('./logger.cjs');
9
- const general = require('./util/general.cjs');
10
-
11
- const SectionSeparatorSchema = zod.z.enum([
12
- "tag",
13
- "markdown"
14
- ]);
15
- const SectionTitlePropertySchema = zod.z.enum([
16
- "title",
17
- "name"
18
- ]);
19
- const FormatOptionsSchema = zod.z.object({
20
- sectionSeparator: SectionSeparatorSchema,
21
- sectionIndentation: zod.z.boolean(),
22
- sectionTitleProperty: SectionTitlePropertySchema,
23
- sectionTitlePrefix: zod.z.string().optional(),
24
- sectionTitleSeparator: zod.z.string().optional(),
25
- sectionDepth: zod.z.number().default(1)
26
- });
27
- const OptionSchema = zod.z.object({
28
- logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
29
- formatOptions: FormatOptionsSchema.partial().optional().default(constants.DEFAULT_FORMAT_OPTIONS)
30
- });
31
- // Type guard to check if an object is a Section
32
- function isSection(obj) {
33
- return obj && typeof obj === 'object' && 'items' in obj && Array.isArray(obj.items);
34
- }
35
- // Type guard to check if an object is a Section
36
- function isWeighted(obj) {
37
- return obj && typeof obj === 'object' && 'text' in obj;
38
- }
39
- const create = (formatterOptions)=>{
40
- const options = OptionSchema.parse(formatterOptions || {});
41
- const logger$1 = logger.wrapLogger(options.logger, 'Formatter');
42
- let formatOptions = constants.DEFAULT_FORMAT_OPTIONS;
43
- if (options === null || options === void 0 ? void 0 : options.formatOptions) {
44
- formatOptions = {
45
- ...formatOptions,
46
- ...general.clean(options.formatOptions)
47
- };
48
- }
49
- const formatPersona = (model, persona)=>{
50
- logger$1.silly(`Formatting persona`);
51
- if (persona) {
52
- const formattedPersona = formatSection(persona);
53
- return {
54
- role: chat.getPersonaRole(model),
55
- content: `${formattedPersona}`
56
- };
57
- } else {
58
- throw new Error("Persona is required");
59
- }
60
- };
61
- const format = (item, sectionDepth)=>{
62
- logger$1.silly(`Formatting ${isSection(item) ? "section" : "item"} Item: %s`, general.stringifyJSON(item));
63
- const currentSectionDepth = sectionDepth !== null && sectionDepth !== void 0 ? sectionDepth : formatOptions.sectionDepth;
64
- logger$1.silly(`\t\tCurrent section depth: ${currentSectionDepth}`);
65
- let result = "";
66
- if (isSection(item)) {
67
- result = formatSection(item, currentSectionDepth + 1);
68
- } else if (isWeighted(item)) {
69
- result = item.text;
70
- } else {
71
- //If the item is neither a section nor a weighted item, it is empty.
72
- result = '';
73
- }
74
- return result;
75
- };
76
- const formatSection = (section, sectionDepth)=>{
77
- logger$1.silly(`Formatting section`);
78
- const currentSectionDepth = sectionDepth !== null && sectionDepth !== void 0 ? sectionDepth : formatOptions.sectionDepth;
79
- logger$1.silly(`\t\tCurrent section depth: ${currentSectionDepth}`);
80
- if (section) {
81
- const formattedItems = section.items.map((item)=>format(item, currentSectionDepth)).join("\n\n");
82
- if (formatOptions.sectionSeparator === "tag") {
83
- var _section_title, _section_title1;
84
- return `<${(_section_title = section.title) !== null && _section_title !== void 0 ? _section_title : "section"}>\n${formattedItems}\n</${(_section_title1 = section.title) !== null && _section_title1 !== void 0 ? _section_title1 : "section"}>`;
85
- } else {
86
- // Default depth to 1 if not provided, resulting in H2 (##) matching the test case.
87
- const headingLevel = currentSectionDepth;
88
- const hashes = '#'.repeat(headingLevel);
89
- logger$1.silly(`\t\tHeading level: ${headingLevel}`);
90
- logger$1.silly(`\t\tSection title: ${section.title}`);
91
- return `${hashes} ${formatOptions.sectionTitlePrefix ? `${formatOptions.sectionTitlePrefix} ${formatOptions.sectionTitleSeparator} ` : ""}${section.title}\n\n${formattedItems}`;
92
- }
93
- } else {
94
- return '';
95
- }
96
- };
97
- // Helper function to format arrays of items or sections
98
- const formatArray = (items, sectionDepth)=>{
99
- logger$1.silly(`Formatting array`);
100
- const currentSectionDepth = sectionDepth !== null && sectionDepth !== void 0 ? sectionDepth : formatOptions.sectionDepth;
101
- return items.map((item)=>format(item, currentSectionDepth)).join("\n\n");
102
- };
103
- const formatPrompt = (model, prompt)=>{
104
- logger$1.silly('Formatting prompt');
105
- const chatRequest = chat.createRequest(model);
106
- if (prompt.persona) {
107
- [
108
- prompt.persona
109
- ].forEach((persona)=>{
110
- chatRequest.addMessage(formatPersona(model, persona));
111
- });
112
- }
113
- let formattedAreas = formatSection(prompt.instructions) + '\n\n';
114
- if (prompt.contents) {
115
- formattedAreas += formatSection(prompt.contents) + '\n\n';
116
- }
117
- if (prompt.contexts) {
118
- formattedAreas += formatSection(prompt.contexts) + '\n\n';
119
- }
120
- chatRequest.addMessage({
121
- role: "user",
122
- content: formattedAreas
123
- });
124
- return chatRequest;
125
- };
126
- return {
127
- formatPersona,
128
- format,
129
- formatPrompt,
130
- formatArray
131
- };
132
- };
133
-
134
- exports.FormatOptionsSchema = FormatOptionsSchema;
135
- exports.OptionSchema = OptionSchema;
136
- exports.SectionSeparatorSchema = SectionSeparatorSchema;
137
- exports.SectionTitlePropertySchema = SectionTitlePropertySchema;
138
- exports.create = create;
139
- //# sourceMappingURL=formatter.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatter.cjs","sources":["../src/formatter.ts"],"sourcesContent":["import { Instruction } from \"riotprompt\";\nimport { z } from \"zod\";\nimport * as Chat from \"./chat\";\nimport { getPersonaRole, Message, Model } from \"./chat\";\nimport { DEFAULT_FORMAT_OPTIONS } from \"./constants\";\nimport { Section } from \"./items/section\";\nimport { Weighted } from \"./items/weighted\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Prompt } from \"./prompt\";\nimport { clean, stringifyJSON } from \"./util/general\";\n\nexport const SectionSeparatorSchema = z.enum([\"tag\", \"markdown\"]);\nexport const SectionTitlePropertySchema = z.enum([\"title\", \"name\"]);\n\nexport type SectionSeparator = z.infer<typeof SectionSeparatorSchema>;\nexport type SectionTitleProperty = z.infer<typeof SectionTitlePropertySchema>;\n\n\nexport const FormatOptionsSchema = z.object({\n sectionSeparator: SectionSeparatorSchema,\n sectionIndentation: z.boolean(),\n sectionTitleProperty: SectionTitlePropertySchema,\n sectionTitlePrefix: z.string().optional(),\n sectionTitleSeparator: z.string().optional(),\n sectionDepth: z.number().default(1),\n});\n\nexport type FormatOptions = z.infer<typeof FormatOptionsSchema>;\n\n\nexport const OptionSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n formatOptions: FormatOptionsSchema.partial().optional().default(DEFAULT_FORMAT_OPTIONS),\n});\n\nexport type Options = z.infer<typeof OptionSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n formatPersona: (model: Model, persona: Section<Instruction>) => Message;\n format: <T extends Weighted>(weightedText: T | Section<T>, sectionDepth?: number) => string;\n formatArray: <T extends Weighted>(items: (T | Section<T>)[], sectionDepth?: number) => string;\n formatPrompt: (model: Model, prompt: Prompt) => Chat.Request;\n}\n\n// Type guard to check if an object is a Section\nfunction isSection<T extends Weighted>(obj: T | Section<T>): obj is Section<T> {\n return obj && typeof obj === 'object' && 'items' in obj && Array.isArray((obj as Section<T>).items);\n}\n\n// Type guard to check if an object is a Section\nfunction isWeighted<T extends Weighted>(obj: T | Section<T>): obj is T {\n return obj && typeof obj === 'object' && 'text' in obj;\n}\n\n\nexport const create = (formatterOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionSchema.parse(formatterOptions || {}) as Required<Options>;\n\n const logger = wrapLogger(options.logger, 'Formatter');\n\n let formatOptions: FormatOptions = DEFAULT_FORMAT_OPTIONS;\n if (options?.formatOptions) {\n formatOptions = {\n ...formatOptions,\n ...clean(options.formatOptions),\n };\n }\n\n const formatPersona = (model: Model, persona: Section<Instruction>): Message => {\n logger.silly(`Formatting persona`);\n if (persona) {\n const formattedPersona = formatSection(persona);\n\n return {\n role: getPersonaRole(model),\n content: `${formattedPersona}`,\n }\n } else {\n throw new Error(\"Persona is required\");\n }\n }\n\n const format = <T extends Weighted>(\n item: T | Section<T>,\n sectionDepth?: number,\n ): string => {\n logger.silly(`Formatting ${isSection(item) ? \"section\" : \"item\"} Item: %s`, stringifyJSON(item));\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n logger.silly(`\\t\\tCurrent section depth: ${currentSectionDepth}`);\n\n let result: string = \"\";\n if (isSection(item)) {\n result = formatSection(item, currentSectionDepth + 1);\n } else if (isWeighted(item)) {\n result = item.text;\n } else {\n //If the item is neither a section nor a weighted item, it is empty.\n result = '';\n }\n return result;\n }\n\n const formatSection = <T extends Weighted>(section: Section<T>, sectionDepth?: number): string => {\n logger.silly(`Formatting section`);\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n logger.silly(`\\t\\tCurrent section depth: ${currentSectionDepth}`);\n\n if (section) {\n const formattedItems = section.items.map(item => format(item, currentSectionDepth)).join(\"\\n\\n\");\n\n if (formatOptions.sectionSeparator === \"tag\") {\n return `<${section.title ?? \"section\"}>\\n${formattedItems}\\n</${section.title ?? \"section\"}>`;\n } else {\n // Default depth to 1 if not provided, resulting in H2 (##) matching the test case.\n const headingLevel = currentSectionDepth;\n const hashes = '#'.repeat(headingLevel);\n logger.silly(`\\t\\tHeading level: ${headingLevel}`);\n logger.silly(`\\t\\tSection title: ${section.title}`);\n return `${hashes} ${formatOptions.sectionTitlePrefix ? `${formatOptions.sectionTitlePrefix} ${formatOptions.sectionTitleSeparator} ` : \"\"}${section.title}\\n\\n${formattedItems}`;\n }\n } else {\n return '';\n }\n }\n\n // Helper function to format arrays of items or sections\n const formatArray = <T extends Weighted>(\n items: (T | Section<T>)[],\n sectionDepth?: number\n ): string => {\n logger.silly(`Formatting array`);\n const currentSectionDepth = sectionDepth ?? formatOptions.sectionDepth;\n return items.map(item => format(item, currentSectionDepth)).join(\"\\n\\n\");\n }\n\n const formatPrompt = (model: Model, prompt: Prompt): Chat.Request => {\n logger.silly('Formatting prompt');\n const chatRequest: Chat.Request = Chat.createRequest(model);\n\n if (prompt.persona) {\n [prompt.persona].forEach((persona: Section<Instruction>) => {\n chatRequest.addMessage(formatPersona(model, persona));\n });\n }\n\n let formattedAreas: string = formatSection(prompt.instructions) + '\\n\\n';\n\n if (prompt.contents) {\n formattedAreas += formatSection(prompt.contents) + '\\n\\n';\n }\n\n if (prompt.contexts) {\n formattedAreas += formatSection(prompt.contexts) + '\\n\\n';\n }\n\n chatRequest.addMessage({\n role: \"user\",\n content: formattedAreas,\n });\n\n return chatRequest;\n }\n\n return {\n formatPersona,\n format,\n formatPrompt,\n formatArray,\n }\n}\n"],"names":["SectionSeparatorSchema","z","enum","SectionTitlePropertySchema","FormatOptionsSchema","object","sectionSeparator","sectionIndentation","boolean","sectionTitleProperty","sectionTitlePrefix","string","optional","sectionTitleSeparator","sectionDepth","number","default","OptionSchema","logger","any","DEFAULT_LOGGER","formatOptions","partial","DEFAULT_FORMAT_OPTIONS","isSection","obj","Array","isArray","items","isWeighted","create","formatterOptions","options","parse","wrapLogger","clean","formatPersona","model","persona","silly","formattedPersona","formatSection","role","getPersonaRole","content","Error","format","item","stringifyJSON","currentSectionDepth","result","text","section","formattedItems","map","join","title","headingLevel","hashes","repeat","formatArray","formatPrompt","prompt","chatRequest","Chat","forEach","addMessage","formattedAreas","instructions","contents","contexts"],"mappings":";;;;;;;;;;AAWaA,MAAAA,sBAAAA,GAAyBC,KAAEC,CAAAA,IAAI,CAAC;AAAC,IAAA,KAAA;AAAO,IAAA;CAAW;AACnDC,MAAAA,0BAAAA,GAA6BF,KAAEC,CAAAA,IAAI,CAAC;AAAC,IAAA,OAAA;AAAS,IAAA;CAAO;AAMrDE,MAAAA,mBAAAA,GAAsBH,KAAEI,CAAAA,MAAM,CAAC;IACxCC,gBAAkBN,EAAAA,sBAAAA;AAClBO,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AAYG,CAAAA,UAAU,CAAC9B,aAAAA,CAAcC,KAAOC,EAAAA,OAAAA,CAAAA,CAAAA;AAChD,aAAA,CAAA;AACJ;AAEA,QAAA,IAAI6B,cAAyB1B,GAAAA,aAAAA,CAAcqB,MAAOM,CAAAA,YAAY,CAAI,GAAA,MAAA;QAElE,IAAIN,MAAAA,CAAOO,QAAQ,EAAE;YACjBF,cAAkB1B,IAAAA,aAAAA,CAAcqB,MAAOO,CAAAA,QAAQ,CAAI,GAAA,MAAA;AACvD;QAEA,IAAIP,MAAAA,CAAOQ,QAAQ,EAAE;YACjBH,cAAkB1B,IAAAA,aAAAA,CAAcqB,MAAOQ,CAAAA,QAAQ,CAAI,GAAA,MAAA;AACvD;AAEAP,QAAAA,WAAAA,CAAYG,UAAU,CAAC;YACnBxB,IAAM,EAAA,MAAA;YACNE,OAASuB,EAAAA;AACb,SAAA,CAAA;QAEA,OAAOJ,WAAAA;AACX,KAAA;IAEA,OAAO;AACH3B,QAAAA,aAAAA;AACAU,QAAAA,MAAAA;AACAe,QAAAA,YAAAA;AACAD,QAAAA;AACJ,KAAA;AACJ;;;;;;;;"}
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const weighted = require('./weighted.cjs');
6
-
7
- // Export create function
8
- const create = (text, options = {})=>{
9
- const weightedOptions = weighted.WeightedOptionsSchema.parse(options);
10
- return weighted.create(text, weightedOptions);
11
- };
12
-
13
- exports.create = create;
14
- //# sourceMappingURL=content.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"content.cjs","sources":["../../src/items/content.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\n// Define Content as a type alias for Weighted\nexport type Content = Weighted;\n\n// Export create function\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Content => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Content>(text, weightedOptions);\n}\n\n"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;;;;;AAKA;MACaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,8BAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,gBAAwBL,IAAME,EAAAA,eAAAA,CAAAA;AACzC;;;;"}
@@ -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=context.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.cjs","sources":["../../src/items/context.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Context = Weighted;\n\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Context => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Context>(text, weightedOptions);\n}\n\n"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;;;;;MAIaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,8BAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,gBAAwBL,IAAME,EAAAA,eAAAA,CAAAA;AACzC;;;;"}
@@ -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=instruction.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instruction.cjs","sources":["../../src/items/instruction.ts"],"sourcesContent":["import { Weighted, WeightedOptions, WeightedOptionsSchema, create as createWeighted } from \"./weighted\";\n\nexport type Instruction = Weighted;\n\nexport const create = (text: string, options: Partial<WeightedOptions> = {}): Instruction => {\n const weightedOptions = WeightedOptionsSchema.parse(options);\n return createWeighted<Instruction>(text, weightedOptions);\n}"],"names":["create","text","options","weightedOptions","WeightedOptionsSchema","parse","createWeighted"],"mappings":";;;;;;MAIaA,MAAS,GAAA,CAACC,IAAcC,EAAAA,OAAAA,GAAoC,EAAE,GAAA;IACvE,MAAMC,eAAAA,GAAkBC,8BAAsBC,CAAAA,KAAK,CAACH,OAAAA,CAAAA;AACpD,IAAA,OAAOI,gBAA4BL,IAAME,EAAAA,eAAAA,CAAAA;AAC7C;;;;"}
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const zod = require('zod');
6
-
7
- const ParametersSchema = zod.z.record(zod.z.string(), zod.z.union([
8
- zod.z.string(),
9
- zod.z.number(),
10
- zod.z.boolean(),
11
- zod.z.array(zod.z.union([
12
- zod.z.string(),
13
- zod.z.number(),
14
- zod.z.boolean()
15
- ]))
16
- ]));
17
- const create = (parameters)=>{
18
- return parameters;
19
- };
20
- const apply = (text, parameters)=>{
21
- if (!parameters) {
22
- return text;
23
- }
24
- // First, trim parameters keys to handle whitespace in placeholder names
25
- const trimmedParams = {};
26
- Object.keys(parameters).forEach((key)=>{
27
- trimmedParams[key.trim()] = parameters[key];
28
- });
29
- // Process all placeholders, preserving ones that don't have matching parameters
30
- return text.replace(/\{\{([^{}]+)\}\}/g, (match, p1)=>{
31
- const paramKey = p1.trim();
32
- const parameter = trimmedParams[paramKey];
33
- if (parameter === undefined) {
34
- // Preserve the original placeholder if parameter doesn't exist
35
- return match;
36
- } else if (typeof parameter === 'string') {
37
- return parameter;
38
- } else if (typeof parameter === 'number') {
39
- return parameter.toString();
40
- } else if (typeof parameter === 'boolean') {
41
- return parameter.toString();
42
- } else if (Array.isArray(parameter)) {
43
- return parameter.join(', ');
44
- } else {
45
- return match;
46
- }
47
- });
48
- };
49
-
50
- exports.ParametersSchema = ParametersSchema;
51
- exports.apply = apply;
52
- exports.create = create;
53
- //# sourceMappingURL=parameters.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parameters.cjs","sources":["../../src/items/parameters.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const ParametersSchema = z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.union([z.string(), z.number(), z.boolean()]))]));\n\nexport type Parameters = z.infer<typeof ParametersSchema>;\n\nexport const create = (parameters: Parameters): Parameters => {\n return parameters;\n}\n\nexport const apply = (text: string, parameters?: Parameters): string => {\n if (!parameters) {\n return text;\n }\n\n // First, trim parameters keys to handle whitespace in placeholder names\n const trimmedParams: Record<string, any> = {};\n Object.keys(parameters).forEach(key => {\n trimmedParams[key.trim()] = parameters[key];\n });\n\n // Process all placeholders, preserving ones that don't have matching parameters\n return text.replace(/\\{\\{([^{}]+)\\}\\}/g, (match, p1) => {\n const paramKey = p1.trim();\n const parameter = trimmedParams[paramKey];\n\n if (parameter === undefined) {\n // Preserve the original placeholder if parameter doesn't exist\n return match;\n } else if (typeof parameter === 'string') {\n return parameter;\n } else if (typeof parameter === 'number') {\n return parameter.toString();\n } else if (typeof parameter === 'boolean') {\n return parameter.toString();\n } else if (Array.isArray(parameter)) {\n return parameter.join(', ');\n } else {\n return match;\n }\n });\n}"],"names":["ParametersSchema","z","record","string","union","number","boolean","array","create","parameters","apply","text","trimmedParams","Object","keys","forEach","key","trim","replace","match","p1","paramKey","parameter","undefined","toString","Array","isArray","join"],"mappings":";;;;;;AAEO,MAAMA,gBAAmBC,GAAAA,KAAAA,CAAEC,MA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