@riotprompt/riotprompt 0.0.7 → 0.0.9

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 (52) hide show
  1. package/.kodrdriv-test-cache.json +6 -0
  2. package/README.md +2 -2
  3. package/dist/builder.d.ts +3 -15
  4. package/dist/builder.js +3 -0
  5. package/dist/builder.js.map +1 -1
  6. package/dist/context-manager.d.ts +135 -0
  7. package/dist/context-manager.js +220 -0
  8. package/dist/context-manager.js.map +1 -0
  9. package/dist/conversation-logger.d.ts +283 -0
  10. package/dist/conversation-logger.js +454 -0
  11. package/dist/conversation-logger.js.map +1 -0
  12. package/dist/conversation.d.ts +271 -0
  13. package/dist/conversation.js +622 -0
  14. package/dist/conversation.js.map +1 -0
  15. package/dist/formatter.d.ts +27 -57
  16. package/dist/formatter.js +2 -2
  17. package/dist/formatter.js.map +1 -1
  18. package/dist/items/parameters.d.ts +1 -1
  19. package/dist/items/section.d.ts +2 -12
  20. package/dist/items/weighted.d.ts +3 -15
  21. package/dist/iteration-strategy.d.ts +231 -0
  22. package/dist/iteration-strategy.js +486 -0
  23. package/dist/iteration-strategy.js.map +1 -0
  24. package/dist/loader.d.ts +3 -11
  25. package/dist/loader.js +3 -0
  26. package/dist/loader.js.map +1 -1
  27. package/dist/message-builder.d.ts +156 -0
  28. package/dist/message-builder.js +254 -0
  29. package/dist/message-builder.js.map +1 -0
  30. package/dist/override.d.ts +3 -13
  31. package/dist/override.js +3 -0
  32. package/dist/override.js.map +1 -1
  33. package/dist/parser.d.ts +2 -8
  34. package/dist/recipes.d.ts +70 -268
  35. package/dist/recipes.js +189 -4
  36. package/dist/recipes.js.map +1 -1
  37. package/dist/reflection.d.ts +250 -0
  38. package/dist/reflection.js +416 -0
  39. package/dist/reflection.js.map +1 -0
  40. package/dist/riotprompt.cjs +3551 -220
  41. package/dist/riotprompt.cjs.map +1 -1
  42. package/dist/riotprompt.d.ts +18 -2
  43. package/dist/riotprompt.js +9 -1
  44. package/dist/riotprompt.js.map +1 -1
  45. package/dist/token-budget.d.ts +177 -0
  46. package/dist/token-budget.js +404 -0
  47. package/dist/token-budget.js.map +1 -0
  48. package/dist/tools.d.ts +239 -0
  49. package/dist/tools.js +324 -0
  50. package/dist/tools.js.map +1 -0
  51. package/package.json +35 -36
  52. package/.cursor/rules/focus-on-prompt.mdc +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sources":["../src/loader.ts"],"sourcesContent":["import path from \"path\";\nimport { z } from \"zod\";\nimport { DEFAULT_IGNORE_PATTERNS } from \"./constants\";\nimport { ParametersSchema } from \"./items/parameters\";\nimport { SectionOptions, SectionOptionsSchema } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Section, Weighted, createSection } from \"./riotprompt\";\nimport * as Storage from \"./util/storage\";\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n load: <T extends Weighted>(contextDirectories?: string[], options?: SectionOptions) => Promise<Section<T>[]>;\n}\n\n/**\n * Extracts the first header from Markdown text\n * @param markdownText The Markdown text to parse\n * @returns The first header found in the Markdown or null if none is found\n */\nexport function extractFirstHeader(markdownText: string): string | null {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match && match[2]) {\n return match[2].trim();\n }\n\n return null;\n}\n\n/**\n * Removes the first header from Markdown text\n * @param markdownText The Markdown text to process\n * @returns The Markdown text without the first header\n */\nexport function removeFirstHeader(markdownText: string): string {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match) {\n return markdownText.replace(headerRegex, '').trim();\n }\n\n return markdownText;\n}\n\nexport const create = (loaderOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(loaderOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Loader');\n const ignorePatterns = options.ignorePatterns;\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n /**\n * Loads context from the provided directories and returns instruction sections\n * \n * @param contextDirectories Directories containing context files\n * @returns Array of instruction sections loaded from context directories\n */\n const load = async<T extends Weighted>(\n contextDirectories: string[] = [],\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const sectionOptions = loadOptions(options);\n\n logger.debug(`Loading context from ${contextDirectories}`);\n const contextSections: Section<T>[] = [];\n\n if (!contextDirectories || contextDirectories.length === 0) {\n logger.debug(`No context directories provided, returning empty context`);\n return contextSections;\n }\n\n const storage = Storage.create({ log: logger.debug });\n\n // Add context sections from each directory\n for (const contextDir of contextDirectories) {\n try {\n const dirName = path.basename(contextDir);\n logger.debug(`Processing context directory ${dirName}`);\n let mainContextSection: Section<T>;\n\n // First check if there's a context.md file\n const contextFile = path.join(contextDir, 'context.md');\n\n if (await storage.exists(contextFile)) {\n logger.debug(`Found context.md file in ${contextDir}`);\n const mainContextContent = await storage.readFile(contextFile, 'utf8');\n // Extract the first header from the Markdown content\n const firstHeader = extractFirstHeader(mainContextContent);\n\n // Use the header from context.md as the section title, or fallback to directory name\n const sectionTitle = firstHeader || dirName;\n mainContextSection = createSection<T>({ ...sectionOptions, title: sectionTitle });\n\n // Add content without the header\n if (firstHeader) {\n mainContextSection.add(removeFirstHeader(mainContextContent), { ...sectionOptions });\n } else {\n mainContextSection.add(mainContextContent, { ...sectionOptions });\n }\n } else {\n // If no context.md exists, use directory name as title\n mainContextSection = createSection<T>({ ...sectionOptions, title: dirName });\n }\n\n // Get all other files in the directory\n const files = await storage.listFiles(contextDir);\n const ignorePatternsRegex = ignorePatterns.map(pattern => new RegExp(pattern, 'i'));\n\n const filteredFiles = files.filter(file =>\n !ignorePatternsRegex.some(regex => regex.test(file))\n );\n\n for (const file of filteredFiles) {\n // Skip the context.md file as it's already processed\n if (file === 'context.md') continue;\n\n logger.debug(`Processing file ${file} in ${contextDir}`);\n const filePath = path.join(contextDir, file);\n if (await storage.isFile(filePath)) {\n const fileContent = await storage.readFile(filePath, 'utf8');\n let sectionName = file;\n let contentToAdd = fileContent;\n\n // Extract header if it exists\n if (file.endsWith('.md')) {\n const fileHeader = extractFirstHeader(fileContent);\n if (fileHeader) {\n sectionName = fileHeader;\n // Remove the header from the content\n contentToAdd = removeFirstHeader(fileContent);\n }\n }\n\n // Create a subsection with the extracted name\n const fileSection = createSection<T>({ ...sectionOptions, title: sectionName });\n fileSection.add(contentToAdd, { ...sectionOptions });\n\n // Add this file section to the main context section\n mainContextSection.add(fileSection as unknown as T, { ...sectionOptions });\n }\n }\n\n contextSections.push(mainContextSection);\n } catch (error) {\n logger.error(`Error processing context directory ${contextDir}: ${error}`);\n }\n }\n\n return contextSections;\n }\n\n\n return {\n load\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","ignorePatterns","array","string","DEFAULT_IGNORE_PATTERNS","parameters","ParametersSchema","extractFirstHeader","markdownText","headerRegex","match","trim","removeFirstHeader","replace","create","loaderOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","load","contextDirectories","debug","contextSections","length","storage","Storage","log","contextDir","dirName","path","basename","mainContextSection","contextFile","join","exists","mainContextContent","readFile","firstHeader","sectionTitle","createSection","title","add","files","listFiles","ignorePatternsRegex","map","pattern","RegExp","filteredFiles","filter","file","some","regex","test","filePath","isFile","fileContent","sectionName","content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;wBAGlDe,kBAAAA,CAAmBU,GAAG,CAACoB,WAAAA,EAA6B;AAAE,4BAAA,GAAG7C;AAAe,yBAAA,CAAA;AAC5E,oBAAA;AACJ,gBAAA;AAEAM,gBAAAA,eAAAA,CAAgBwC,IAAI,CAAC/B,kBAAAA,CAAAA;AACzB,YAAA,CAAA,CAAE,OAAOgC,KAAAA,EAAO;gBACZvE,MAAAA,CAAOuE,KAAK,CAAC,CAAC,mCAAmC,EAAEpC,UAAAA,CAAW,EAAE,EAAEoC,KAAAA,CAAAA,CAAO,CAAA;AAC7E,YAAA;AACJ,QAAA;QAEA,OAAOzC,eAAAA;AACX,IAAA,CAAA;IAGA,OAAO;AACHH,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"loader.js","sources":["../src/loader.ts"],"sourcesContent":["import path from \"path\";\nimport { z } from \"zod\";\nimport { DEFAULT_IGNORE_PATTERNS } from \"./constants\";\nimport { ParametersSchema } from \"./items/parameters\";\nimport { SectionOptions, SectionOptionsSchema } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Section, Weighted, createSection } from \"./riotprompt\";\nimport * as Storage from \"./util/storage\";\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n load: <T extends Weighted>(contextDirectories?: string[], options?: SectionOptions) => Promise<Section<T>[]>;\n}\n\n/**\n * Extracts the first header from Markdown text\n * @param markdownText The Markdown text to parse\n * @returns The first header found in the Markdown or null if none is found\n */\nexport function extractFirstHeader(markdownText: string): string | null {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match && match[2]) {\n return match[2].trim();\n }\n\n return null;\n}\n\n/**\n * Removes the first header from Markdown text\n * @param markdownText The Markdown text to process\n * @returns The Markdown text without the first header\n */\nexport function removeFirstHeader(markdownText: string): string {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match) {\n return markdownText.replace(headerRegex, '').trim();\n }\n\n return markdownText;\n}\n\nexport const create = (loaderOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(loaderOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Loader');\n const ignorePatterns = options.ignorePatterns;\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n /**\n * Loads context from the provided directories and returns instruction sections\n * \n * @param contextDirectories Directories containing context files\n * @returns Array of instruction sections loaded from context directories\n */\n const load = async<T extends Weighted>(\n contextDirectories: string[] = [],\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const sectionOptions = loadOptions(options);\n\n logger.debug(`Loading context from ${contextDirectories}`);\n const contextSections: Section<T>[] = [];\n\n if (!contextDirectories || contextDirectories.length === 0) {\n logger.debug(`No context directories provided, returning empty context`);\n return contextSections;\n }\n\n const storage = Storage.create({ log: logger.debug });\n\n // Add context sections from each directory\n for (const contextDir of contextDirectories) {\n try {\n const dirName = path.basename(contextDir);\n logger.debug(`Processing context directory ${dirName}`);\n let mainContextSection: Section<T>;\n\n // First check if there's a context.md file\n const contextFile = path.join(contextDir, 'context.md');\n\n if (await storage.exists(contextFile)) {\n logger.debug(`Found context.md file in ${contextDir}`);\n const mainContextContent = await storage.readFile(contextFile, 'utf8');\n // Extract the first header from the Markdown content\n const firstHeader = extractFirstHeader(mainContextContent);\n\n // Use the header from context.md as the section title, or fallback to directory name\n const sectionTitle = firstHeader || dirName;\n mainContextSection = createSection<T>({ ...sectionOptions, title: sectionTitle });\n\n // Add content without the header\n if (firstHeader) {\n mainContextSection.add(removeFirstHeader(mainContextContent), { ...sectionOptions });\n } else {\n mainContextSection.add(mainContextContent, { ...sectionOptions });\n }\n } else {\n // If no context.md exists, use directory name as title\n mainContextSection = createSection<T>({ ...sectionOptions, title: dirName });\n }\n\n // Get all other files in the directory\n const files = await storage.listFiles(contextDir);\n const ignorePatternsRegex = ignorePatterns.map(pattern => new RegExp(pattern, 'i'));\n\n const filteredFiles = files.filter(file =>\n !ignorePatternsRegex.some(regex => regex.test(file))\n );\n\n for (const file of filteredFiles) {\n // Skip the context.md file as it's already processed\n if (file === 'context.md') continue;\n\n logger.debug(`Processing file ${file} in ${contextDir}`);\n const filePath = path.join(contextDir, file);\n if (await storage.isFile(filePath)) {\n const fileContent = await storage.readFile(filePath, 'utf8');\n let sectionName = file;\n let contentToAdd = fileContent;\n\n // Extract header if it exists\n if (file.endsWith('.md')) {\n const fileHeader = extractFirstHeader(fileContent);\n if (fileHeader) {\n sectionName = fileHeader;\n // Remove the header from the content\n contentToAdd = removeFirstHeader(fileContent);\n }\n }\n\n // Create a subsection with the extracted name\n const fileSection = createSection<T>({ ...sectionOptions, title: sectionName });\n fileSection.add(contentToAdd, { ...sectionOptions });\n\n // Add this file section to the main context section\n mainContextSection.add(fileSection as unknown as T, { ...sectionOptions });\n }\n }\n\n contextSections.push(mainContextSection);\n } catch (error) {\n logger.error(`Error processing context directory ${contextDir}: ${error}`);\n }\n }\n\n return contextSections;\n }\n\n\n return {\n load\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","ignorePatterns","array","string","DEFAULT_IGNORE_PATTERNS","parameters","ParametersSchema","extractFirstHeader","markdownText","headerRegex","match","trim","removeFirstHeader","replace","create","loaderOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","load","contextDirectories","debug","contextSections","length","storage","Storage","log","contextDir","dirName","path","basename","mainContextSection","contextFile","join","exists","mainContextContent","readFile","firstHeader","sectionTitle","createSection","title","add","files","listFiles","ignorePatternsRegex","map","pattern","RegExp","filteredFiles","filter","file","some","regex","test","filePath","isFile","fileContent","sectionName","contentToAdd","endsWith","fileHeader","fileSection","push","error"],"mappings":";;;;;;;;;;;;;;;;;AASA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;IACnCC,cAAAA,EAAgBP,CAAAA,CAAEQ,KAAK,CAACR,CAAAA,CAAES,MAAM,EAAA,CAAA,CAAIL,QAAQ,EAAA,CAAGC,OAAO,CAACK,uBAAAA,CAAAA;AACvDC,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBR,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAUA;;;;IAKO,SAASQ,kBAAAA,CAAmBC,YAAoB,EAAA;;AAEnD,IAAA,MAAMC,WAAAA,GAAc,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAAA,CAAaE,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAAAA,IAASA,KAAK,CAAC,CAAA,CAAE,EAAE;AACnB,QAAA,OAAOA,KAAK,CAAC,CAAA,CAAE,CAACC,IAAI,EAAA;AACxB,IAAA;IAEA,OAAO,IAAA;AACX;AAEA;;;;IAKO,SAASC,iBAAAA,CAAkBJ,YAAoB,EAAA;;AAElD,IAAA,MAAMC,WAAAA,GAAc,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAAA,CAAaE,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAAAA,EAAO;AACP,QAAA,OAAOF,YAAAA,CAAaK,OAAO,CAACJ,W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wBAAA;;AAGA,wBAAA,MAAMK,cAActB,QAAAA,CAAiB;AAAE,4BAAA,GAAGvB,cAAc;4BAAEwB,KAAAA,EAAOiB;AAAY,yBAAA,CAAA;wBAC7EI,WAAAA,CAAYpB,GAAG,CAACiB,YAAAA,EAAc;AAAE,4BAAA,GAAG1C;AAAe,yBAAA,CAAA;;wBAGlDe,kBAAAA,CAAmBU,GAAG,CAACoB,WAAAA,EAA6B;AAAE,4BAAA,GAAG7C;AAAe,yBAAA,CAAA;AAC5E,oBAAA;AACJ,gBAAA;AAEAM,gBAAAA,eAAAA,CAAgBwC,IAAI,CAAC/B,kBAAAA,CAAAA;AACzB,YAAA,CAAA,CAAE,OAAOgC,KAAAA,EAAO;gBACZvE,MAAAA,CAAOuE,KAAK,CAAC,CAAC,mCAAmC,EAAEpC,UAAAA,CAAW,EAAE,EAAEoC,KAAAA,CAAAA,CAAO,CAAA;AAC7E,YAAA;AACJ,QAAA;QAEA,OAAOzC,eAAAA;AACX,IAAA,CAAA;IAGA,OAAO;AACHH,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,156 @@
1
+ import { Model } from './chat';
2
+ import { Context } from './items/context';
3
+ import { Instruction } from './items/instruction';
4
+ import { Section } from './items/section';
5
+ import { ConversationMessage, ToolCall } from './conversation';
6
+ import * as Formatter from "./formatter";
7
+ /**
8
+ * Semantic message role
9
+ */
10
+ export type SemanticRole = 'system' | 'user' | 'assistant' | 'tool' | 'developer';
11
+ /**
12
+ * Message metadata
13
+ */
14
+ export interface MessageMetadata {
15
+ priority?: 'high' | 'medium' | 'low';
16
+ timestamp?: Date;
17
+ source?: string;
18
+ [key: string]: any;
19
+ }
20
+ /**
21
+ * MessageBuilder provides semantic, type-safe message construction.
22
+ *
23
+ * Features:
24
+ * - Semantic message types (system, user, assistant, tool)
25
+ * - Model-specific role handling (system vs developer)
26
+ * - Structured content composition
27
+ * - Metadata attachment
28
+ * - Format-aware building
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const message = MessageBuilder.system()
33
+ * .withContent('You are a helpful assistant')
34
+ * .withInstructions(instructionSection)
35
+ * .buildForModel('gpt-4o');
36
+ *
37
+ * const toolMessage = MessageBuilder.tool('call_123')
38
+ * .withResult(result)
39
+ * .withMetadata({ duration: 45 })
40
+ * .build();
41
+ * ```
42
+ */
43
+ export declare class MessageBuilder {
44
+ private semanticRole;
45
+ private contentParts;
46
+ private metadata;
47
+ private formatter?;
48
+ private toolCallId?;
49
+ private toolCalls?;
50
+ private logger;
51
+ private constructor();
52
+ /**
53
+ * Create system message builder
54
+ */
55
+ static system(logger?: any): MessageBuilder;
56
+ /**
57
+ * Create user message builder
58
+ */
59
+ static user(logger?: any): MessageBuilder;
60
+ /**
61
+ * Create assistant message builder
62
+ */
63
+ static assistant(logger?: any): MessageBuilder;
64
+ /**
65
+ * Create tool message builder
66
+ */
67
+ static tool(callId: string, logger?: any): MessageBuilder;
68
+ /**
69
+ * Create developer message builder (for o1 models)
70
+ */
71
+ static developer(logger?: any): MessageBuilder;
72
+ /**
73
+ * Add content to message
74
+ */
75
+ withContent(content: string | Section<any>): this;
76
+ /**
77
+ * Add persona section (typically for system messages)
78
+ */
79
+ withPersona(persona: Section<Instruction>): this;
80
+ /**
81
+ * Add instructions section
82
+ */
83
+ withInstructions(instructions: Section<Instruction> | string[]): this;
84
+ /**
85
+ * Add context section
86
+ */
87
+ withContext(context: Section<Context> | Array<{
88
+ content: string;
89
+ title?: string;
90
+ }>): this;
91
+ /**
92
+ * Set tool call ID (for tool messages)
93
+ */
94
+ withCallId(id: string): this;
95
+ /**
96
+ * Set tool result (for tool messages)
97
+ */
98
+ withResult(result: any): this;
99
+ /**
100
+ * Add tool calls (for assistant messages)
101
+ */
102
+ withToolCalls(calls: ToolCall[]): this;
103
+ /**
104
+ * Add metadata
105
+ */
106
+ withMetadata(metadata: Record<string, any>): this;
107
+ /**
108
+ * Add timestamp to metadata
109
+ */
110
+ withTimestamp(): this;
111
+ /**
112
+ * Set priority in metadata
113
+ */
114
+ withPriority(priority: 'high' | 'medium' | 'low'): this;
115
+ /**
116
+ * Set formatter for section rendering
117
+ */
118
+ withFormatter(formatter: Formatter.Instance): this;
119
+ /**
120
+ * Build message with semantic role
121
+ */
122
+ build(): ConversationMessage;
123
+ /**
124
+ * Build message with model-specific role
125
+ */
126
+ buildForModel(model: Model): ConversationMessage;
127
+ }
128
+ /**
129
+ * Message template functions for common patterns
130
+ */
131
+ export declare const MessageTemplates: {
132
+ /**
133
+ * System message for agentic tasks
134
+ */
135
+ agenticSystem: (persona?: string, instructions?: string[]) => MessageBuilder;
136
+ /**
137
+ * User query with optional context
138
+ */
139
+ userQuery: (query: string, context?: Array<{
140
+ content: string;
141
+ title?: string;
142
+ }>) => MessageBuilder;
143
+ /**
144
+ * Tool result with metadata
145
+ */
146
+ toolResult: (callId: string, result: any, metadata?: Record<string, any>) => MessageBuilder;
147
+ /**
148
+ * Tool success result
149
+ */
150
+ toolSuccess: (callId: string, result: any, duration?: number) => MessageBuilder;
151
+ /**
152
+ * Tool failure result
153
+ */
154
+ toolFailure: (callId: string, error: Error) => MessageBuilder;
155
+ };
156
+ export default MessageBuilder;
@@ -0,0 +1,254 @@
1
+ import { wrapLogger, DEFAULT_LOGGER } from './logger.js';
2
+ import { create } from './formatter.js';
3
+
4
+ function _define_property(obj, key, value) {
5
+ if (key in obj) {
6
+ Object.defineProperty(obj, key, {
7
+ value: value,
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true
11
+ });
12
+ } else {
13
+ obj[key] = value;
14
+ }
15
+ return obj;
16
+ }
17
+ /**
18
+ * MessageBuilder provides semantic, type-safe message construction.
19
+ *
20
+ * Features:
21
+ * - Semantic message types (system, user, assistant, tool)
22
+ * - Model-specific role handling (system vs developer)
23
+ * - Structured content composition
24
+ * - Metadata attachment
25
+ * - Format-aware building
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const message = MessageBuilder.system()
30
+ * .withContent('You are a helpful assistant')
31
+ * .withInstructions(instructionSection)
32
+ * .buildForModel('gpt-4o');
33
+ *
34
+ * const toolMessage = MessageBuilder.tool('call_123')
35
+ * .withResult(result)
36
+ * .withMetadata({ duration: 45 })
37
+ * .build();
38
+ * ```
39
+ */ class MessageBuilder {
40
+ /**
41
+ * Create system message builder
42
+ */ static system(logger) {
43
+ return new MessageBuilder('system', logger);
44
+ }
45
+ /**
46
+ * Create user message builder
47
+ */ static user(logger) {
48
+ return new MessageBuilder('user', logger);
49
+ }
50
+ /**
51
+ * Create assistant message builder
52
+ */ static assistant(logger) {
53
+ return new MessageBuilder('assistant', logger);
54
+ }
55
+ /**
56
+ * Create tool message builder
57
+ */ static tool(callId, logger) {
58
+ const builder = new MessageBuilder('tool', logger);
59
+ builder.toolCallId = callId;
60
+ return builder;
61
+ }
62
+ /**
63
+ * Create developer message builder (for o1 models)
64
+ */ static developer(logger) {
65
+ return new MessageBuilder('developer', logger);
66
+ }
67
+ /**
68
+ * Add content to message
69
+ */ withContent(content) {
70
+ if (typeof content === 'string') {
71
+ this.contentParts.push(content);
72
+ } else {
73
+ // Format section
74
+ const formatter$1 = this.formatter || create();
75
+ this.contentParts.push(formatter$1.format(content));
76
+ }
77
+ return this;
78
+ }
79
+ /**
80
+ * Add persona section (typically for system messages)
81
+ */ withPersona(persona) {
82
+ const formatter$1 = this.formatter || create();
83
+ this.contentParts.push(formatter$1.format(persona));
84
+ return this;
85
+ }
86
+ /**
87
+ * Add instructions section
88
+ */ withInstructions(instructions) {
89
+ if (Array.isArray(instructions)) {
90
+ this.contentParts.push(instructions.join('\n'));
91
+ } else {
92
+ const formatter$1 = this.formatter || create();
93
+ this.contentParts.push(formatter$1.format(instructions));
94
+ }
95
+ return this;
96
+ }
97
+ /**
98
+ * Add context section
99
+ */ withContext(context) {
100
+ if (Array.isArray(context)) {
101
+ const contextStr = context.map((c)=>c.title ? `## ${c.title}\n\n${c.content}` : c.content).join('\n\n');
102
+ this.contentParts.push(contextStr);
103
+ } else {
104
+ const formatter$1 = this.formatter || create();
105
+ this.contentParts.push(formatter$1.format(context));
106
+ }
107
+ return this;
108
+ }
109
+ /**
110
+ * Set tool call ID (for tool messages)
111
+ */ withCallId(id) {
112
+ this.toolCallId = id;
113
+ return this;
114
+ }
115
+ /**
116
+ * Set tool result (for tool messages)
117
+ */ withResult(result) {
118
+ const resultStr = typeof result === 'string' ? result : JSON.stringify(result, null, 2);
119
+ this.contentParts.push(resultStr);
120
+ return this;
121
+ }
122
+ /**
123
+ * Add tool calls (for assistant messages)
124
+ */ withToolCalls(calls) {
125
+ this.toolCalls = calls;
126
+ return this;
127
+ }
128
+ /**
129
+ * Add metadata
130
+ */ withMetadata(metadata) {
131
+ this.metadata = {
132
+ ...this.metadata,
133
+ ...metadata
134
+ };
135
+ return this;
136
+ }
137
+ /**
138
+ * Add timestamp to metadata
139
+ */ withTimestamp() {
140
+ this.metadata.timestamp = new Date();
141
+ return this;
142
+ }
143
+ /**
144
+ * Set priority in metadata
145
+ */ withPriority(priority) {
146
+ this.metadata.priority = priority;
147
+ return this;
148
+ }
149
+ /**
150
+ * Set formatter for section rendering
151
+ */ withFormatter(formatter) {
152
+ this.formatter = formatter;
153
+ return this;
154
+ }
155
+ /**
156
+ * Build message with semantic role
157
+ */ build() {
158
+ const content = this.contentParts.join('\n\n');
159
+ const message = {
160
+ role: this.semanticRole,
161
+ content: content || null
162
+ };
163
+ // Add tool-specific fields
164
+ if (this.semanticRole === 'tool' && this.toolCallId) {
165
+ message.tool_call_id = this.toolCallId;
166
+ }
167
+ if (this.toolCalls) {
168
+ message.tool_calls = this.toolCalls;
169
+ }
170
+ return message;
171
+ }
172
+ /**
173
+ * Build message with model-specific role
174
+ */ buildForModel(model) {
175
+ const message = this.build();
176
+ // Handle model-specific role requirements
177
+ if (this.semanticRole === 'system') {
178
+ // O1 models use 'developer' instead of 'system'
179
+ if (model.startsWith('o1') || model.startsWith('o3') || model === 'o1-pro') {
180
+ message.role = 'developer';
181
+ }
182
+ }
183
+ return message;
184
+ }
185
+ constructor(role, logger){
186
+ _define_property(this, "semanticRole", void 0);
187
+ _define_property(this, "contentParts", void 0);
188
+ _define_property(this, "metadata", void 0);
189
+ _define_property(this, "formatter", void 0);
190
+ _define_property(this, "toolCallId", void 0);
191
+ _define_property(this, "toolCalls", void 0);
192
+ _define_property(this, "logger", void 0);
193
+ this.semanticRole = role;
194
+ this.contentParts = [];
195
+ this.metadata = {};
196
+ this.logger = wrapLogger(logger || DEFAULT_LOGGER, 'MessageBuilder');
197
+ }
198
+ }
199
+ /**
200
+ * Message template functions for common patterns
201
+ */ const MessageTemplates = {
202
+ /**
203
+ * System message for agentic tasks
204
+ */ agenticSystem: (persona, instructions)=>{
205
+ const builder = MessageBuilder.system();
206
+ if (persona) {
207
+ builder.withContent(persona);
208
+ }
209
+ if (instructions) {
210
+ builder.withInstructions(instructions);
211
+ }
212
+ return builder;
213
+ },
214
+ /**
215
+ * User query with optional context
216
+ */ userQuery: (query, context)=>{
217
+ const builder = MessageBuilder.user().withContent(query);
218
+ if (context) {
219
+ builder.withContext(context);
220
+ }
221
+ return builder;
222
+ },
223
+ /**
224
+ * Tool result with metadata
225
+ */ toolResult: (callId, result, metadata)=>{
226
+ const builder = MessageBuilder.tool(callId).withResult(result).withTimestamp();
227
+ if (metadata) {
228
+ builder.withMetadata(metadata);
229
+ }
230
+ return builder;
231
+ },
232
+ /**
233
+ * Tool success result
234
+ */ toolSuccess: (callId, result, duration)=>{
235
+ return MessageBuilder.tool(callId).withResult(result).withMetadata({
236
+ success: true,
237
+ duration
238
+ }).withTimestamp();
239
+ },
240
+ /**
241
+ * Tool failure result
242
+ */ toolFailure: (callId, error)=>{
243
+ return MessageBuilder.tool(callId).withResult({
244
+ error: error.message,
245
+ stack: error.stack
246
+ }).withMetadata({
247
+ success: false,
248
+ errorName: error.name
249
+ }).withTimestamp();
250
+ }
251
+ };
252
+
253
+ export { MessageBuilder, MessageTemplates, MessageBuilder as default };
254
+ //# sourceMappingURL=message-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { Model } from \"./chat\";\nimport { Context } from \"./items/context\";\nimport { Instruction } from \"./items/instruction\";\nimport { Section } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport type { ConversationMessage, ToolCall } from \"./conversation\";\nimport * as Formatter from \"./formatter\";\n\n// ===== TYPE DEFINITIONS =====\n\n/**\n * Semantic message role\n */\nexport type SemanticRole = 'system' | 'user' | 'assistant' | 'tool' | 'developer';\n\n/**\n * Message metadata\n */\nexport interface MessageMetadata {\n priority?: 'high' | 'medium' | 'low';\n timestamp?: Date;\n source?: string;\n [key: string]: any;\n}\n\n/**\n * MessageBuilder provides semantic, type-safe message construction.\n *\n * Features:\n * - Semantic message types (system, user, assistant, tool)\n * - Model-specific role handling (system vs developer)\n * - Structured content composition\n * - Metadata attachment\n * - Format-aware building\n *\n * @example\n * ```typescript\n * const message = MessageBuilder.system()\n * .withContent('You are a helpful assistant')\n * .withInstructions(instructionSection)\n * .buildForModel('gpt-4o');\n *\n * const toolMessage = MessageBuilder.tool('call_123')\n * .withResult(result)\n * .withMetadata({ duration: 45 })\n * .build();\n * ```\n */\nexport class MessageBuilder {\n private semanticRole: SemanticRole;\n private contentParts: string[];\n private metadata: MessageMetadata;\n private formatter?: Formatter.Instance;\n private toolCallId?: string;\n private toolCalls?: ToolCall[];\n private logger: any;\n\n private constructor(role: SemanticRole, logger?: any) {\n this.semanticRole = role;\n this.contentParts = [];\n this.metadata = {};\n this.logger = wrapLogger(logger || DEFAULT_LOGGER, 'MessageBuilder');\n }\n\n /**\n * Create system message builder\n */\n static system(logger?: any): MessageBuilder {\n return new MessageBuilder('system', logger);\n }\n\n /**\n * Create user message builder\n */\n static user(logger?: any): MessageBuilder {\n return new MessageBuilder('user', logger);\n }\n\n /**\n * Create assistant message builder\n */\n static assistant(logger?: any): MessageBuilder {\n return new MessageBuilder('assistant', logger);\n }\n\n /**\n * Create tool message builder\n */\n static tool(callId: string, logger?: any): MessageBuilder {\n const builder = new MessageBuilder('tool', logger);\n builder.toolCallId = callId;\n return builder;\n }\n\n /**\n * Create developer message builder (for o1 models)\n */\n static developer(logger?: any): MessageBuilder {\n return new MessageBuilder('developer', logger);\n }\n\n /**\n * Add content to message\n */\n withContent(content: string | Section<any>): this {\n if (typeof content === 'string') {\n this.contentParts.push(content);\n } else {\n // Format section\n const formatter = this.formatter || Formatter.create();\n this.contentParts.push(formatter.format(content));\n }\n return this;\n }\n\n /**\n * Add persona section (typically for system messages)\n */\n withPersona(persona: Section<Instruction>): this {\n const formatter = this.formatter || Formatter.create();\n this.contentParts.push(formatter.format(persona));\n return this;\n }\n\n /**\n * Add instructions section\n */\n withInstructions(instructions: Section<Instruction> | string[]): this {\n if (Array.isArray(instructions)) {\n this.contentParts.push(instructions.join('\\n'));\n } else {\n const formatter = this.formatter || Formatter.create();\n this.contentParts.push(formatter.format(instructions));\n }\n return this;\n }\n\n /**\n * Add context section\n */\n withContext(context: Section<Context> | Array<{ content: string; title?: string }>): this {\n if (Array.isArray(context)) {\n const contextStr = context.map(c =>\n c.title ? `## ${c.title}\\n\\n${c.content}` : c.content\n ).join('\\n\\n');\n this.contentParts.push(contextStr);\n } else {\n const formatter = this.formatter || Formatter.create();\n this.contentParts.push(formatter.format(context));\n }\n return this;\n }\n\n /**\n * Set tool call ID (for tool messages)\n */\n withCallId(id: string): this {\n this.toolCallId = id;\n return this;\n }\n\n /**\n * Set tool result (for tool messages)\n */\n withResult(result: any): this {\n const resultStr = typeof result === 'string' ? result : JSON.stringify(result, null, 2);\n this.contentParts.push(resultStr);\n return this;\n }\n\n /**\n * Add tool calls (for assistant messages)\n */\n withToolCalls(calls: ToolCall[]): this {\n this.toolCalls = calls;\n return this;\n }\n\n /**\n * Add metadata\n */\n withMetadata(metadata: Record<string, any>): this {\n this.metadata = { ...this.metadata, ...metadata };\n return this;\n }\n\n /**\n * Add timestamp to metadata\n */\n withTimestamp(): this {\n this.metadata.timestamp = new Date();\n return this;\n }\n\n /**\n * Set priority in metadata\n */\n withPriority(priority: 'high' | 'medium' | 'low'): this {\n this.metadata.priority = priority;\n return this;\n }\n\n /**\n * Set formatter for section rendering\n */\n withFormatter(formatter: Formatter.Instance): this {\n this.formatter = formatter;\n return this;\n }\n\n /**\n * Build message with semantic role\n */\n build(): ConversationMessage {\n const content = this.contentParts.join('\\n\\n');\n\n const message: ConversationMessage = {\n role: this.semanticRole as any,\n content: content || null,\n };\n\n // Add tool-specific fields\n if (this.semanticRole === 'tool' && this.toolCallId) {\n message.tool_call_id = this.toolCallId;\n }\n\n if (this.toolCalls) {\n message.tool_calls = this.toolCalls;\n }\n\n return message;\n }\n\n /**\n * Build message with model-specific role\n */\n buildForModel(model: Model): ConversationMessage {\n const message = this.build();\n\n // Handle model-specific role requirements\n if (this.semanticRole === 'system') {\n // O1 models use 'developer' instead of 'system'\n if (model.startsWith('o1') || model.startsWith('o3') || model === 'o1-pro') {\n message.role = 'developer' as any;\n }\n }\n\n return message;\n }\n}\n\n/**\n * Message template functions for common patterns\n */\nexport const MessageTemplates = {\n /**\n * System message for agentic tasks\n */\n agenticSystem: (persona?: string, instructions?: string[]) => {\n const builder = MessageBuilder.system();\n\n if (persona) {\n builder.withContent(persona);\n }\n\n if (instructions) {\n builder.withInstructions(instructions);\n }\n\n return builder;\n },\n\n /**\n * User query with optional context\n */\n userQuery: (query: string, context?: Array<{ content: string; title?: string }>) => {\n const builder = MessageBuilder.user().withContent(query);\n\n if (context) {\n builder.withContext(context);\n }\n\n return builder;\n },\n\n /**\n * Tool result with metadata\n */\n toolResult: (callId: string, result: any, metadata?: Record<string, any>) => {\n const builder = MessageBuilder.tool(callId)\n .withResult(result)\n .withTimestamp();\n\n if (metadata) {\n builder.withMetadata(metadata);\n }\n\n return builder;\n },\n\n /**\n * Tool success result\n */\n toolSuccess: (callId: string, result: any, duration?: number) => {\n return MessageBuilder.tool(callId)\n .withResult(result)\n .withMetadata({ success: true, duration })\n .withTimestamp();\n },\n\n /**\n * Tool failure result\n */\n toolFailure: (callId: string, error: Error) => {\n return MessageBuilder.tool(callId)\n .withResult({ error: error.message, stack: error.stack })\n .withMetadata({ success: false, errorName: error.name })\n .withTimestamp();\n },\n};\n\nexport default MessageBuilder;\n\n"],"names":["MessageBuilder","system","logger","user","assistant","tool","callId","builder","toolCallId","developer","withContent","content","contentParts","push","formatter","Formatter","format","withPersona","persona","withInstructions","instructions","Array","isArray","join","withContext","context","contextStr","map","c","title","withCallId","id","withResult","result","resultStr","JSON","stringify","withToolCalls","calls","toolCalls","withMetadata","metadata","withTimestamp","timestamp","Date","withPriority","priority","withFormatter","build","message","role","semanticRole","tool_call_id","tool_calls","buildForModel","model","startsWith","wrapLogger","DEFAULT_LOGGER","MessageTemplates","agenticSystem","userQuery","query","toolResult","toolSuccess","duration","success","toolFailure","error","stack","errorName","name"],"mappings":";;;;;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;;;;;;;;;;AAsBC,IACM,MAAMA,cAAAA,CAAAA;AAgBT;;QAGA,OAAOC,MAAAA,CAAOC,MAAY,EAAkB;QACxC,OAAO,IAAIF,eAAe,QAAA,EAAUE,MAAAA,CAAAA;AACxC,IAAA;AAEA;;QAGA,OAAOC,IAAAA,CAAKD,MAAY,EAAkB;QACtC,OAAO,IAAIF,eAAe,MAAA,EAAQE,MAAAA,CAAAA;AACtC,IAAA;AAEA;;QAGA,OAAOE,SAAAA,CAAUF,MAAY,EAAkB;QAC3C,OAAO,IAAIF,eAAe,WAAA,EAAaE,MAAAA,CAAAA;AAC3C,IAAA;AAEA;;AAEC,QACD,OAAOG,IAAAA,CAAKC,MAAc,EAAEJ,MAAY,EAAkB;QACtD,MAAMK,OAAAA,GAAU,IAAIP,cAAAA,CAAe,MAAA,EAAQE,MAAAA,CAAAA;AAC3CK,QAAAA,OAAAA,CAAQC,UAAU,GAAGF,MAAAA;QACrB,OAAOC,OAAAA;AACX,IAAA;AAEA;;QAGA,OAAOE,SAAA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{ Section, Weighted } from './riotprompt';
4
4
  declare const OptionsSchema: z.ZodObject<{
5
5
  logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
6
- configDirs: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
6
+ configDirs: z.ZodDefault<z.ZodArray<z.ZodString>>;
7
7
  overrides: z.ZodDefault<z.ZodBoolean>;
8
- parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">]>>>>;
9
- }, "strip", z.ZodTypeAny, {
10
- parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
11
- configDirs: string[];
12
- overrides: boolean;
13
- logger?: any;
14
- }, {
15
- parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
16
- logger?: any;
17
- configDirs?: string[] | undefined;
18
- overrides?: boolean | undefined;
19
- }>;
8
+ parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>>>;
9
+ }, z.core.$strip>;
20
10
  export type Options = z.infer<typeof OptionsSchema>;
21
11
  export type OptionsParam = Partial<Options>;
22
12
  export interface Instance {
package/dist/override.js CHANGED
@@ -9,6 +9,9 @@ import { create as create$3 } from './parser.js';
9
9
  import './loader.js';
10
10
  import './builder.js';
11
11
  import './recipes.js';
12
+ import './conversation.js';
13
+ import 'tiktoken';
14
+ import './tools.js';
12
15
  import { create as create$2 } from './util/storage.js';
13
16
 
14
17
  const OptionsSchema = z.object({
@@ -1 +1 @@
1
- {"version":3,"file":"override.js","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDirs: z.array(z.string()).default(['./overrides']),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const response: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = {\n prepends: [],\n appends: []\n };\n\n // Process directories in order (closest to furthest)\n for (let i = 0; i < options.configDirs.length; i++) {\n const configDir = options.configDirs[i];\n const baseFile = path.join(configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n // Check for prepend files (-pre.md)\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s (layer %d)', preFile, i + 1);\n const parser = Parser.create({ logger });\n const prependSection = await parser.parseFile<T>(preFile, currentSectionOptions);\n response.prepends.push(prependSection);\n }\n\n // Check for append files (-post.md)\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s (layer %d)', postFile, i + 1);\n const parser = Parser.create({ logger });\n const appendSection = await parser.parseFile<T>(postFile, currentSectionOptions);\n response.appends.push(appendSection);\n }\n\n // Check for complete override files - use the first (closest) one found\n if (!response.override && await storage.exists(baseFile)) {\n logger.silly('Found base file %s (layer %d)', baseFile, i + 1);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { override: overrideContent, prepends, appends }: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n // Apply prepends in order (closest layer first)\n for (const prepend of prepends) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n // Apply appends in reverse order (furthest layers first, then closest)\n for (const append of appends.reverse()) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDirs","array","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","response","prepends","appends","i","length","configDir","baseFile","path","join","preFile","replace","postFile","exists","silly","parser","Parser","prependSection","parseFile","push","appendSection","warn","error","Error","customize","overrideContent","finalSection","prepend","append","reverse","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYP,EAAEQ,KAAK,CAACR,EAAES,MAAM,EAAA,CAAA,CAAIJ,OAAO,CAAC;AAAC,QAAA;AAAc,KAAA,CAAA;AACvDK,IAAAA,SAAAA,EAAWV,CAAAA,CAAEW,OAAO,EAAA,CAAGN,OAAO,CAAC,KAAA,CAAA;AAC/BO,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBT,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAYO,MAAMS,MAAAA,GAAS,CAACC,eAAAA,GAAgC,EAAE,GAAA;IACrD,MAAMC,OAAAA,GAA6BjB,aAAAA,CAAckB,KAAK,CAACF,eAAAA,CAAAA;IAEvD,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAMV,SAASgB,UAAAA,CAAWF,OAAAA,KAAAA,IAAAA,IAAAA,OAAAA,KAAAA,MAAAA,GAAAA,MAAAA,GAAAA,OAAAA,CAASd,MAAM,EAAE,UAAA,CAAA;IAC3C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;AACvC,QAAA;QAEA,MAAME,WAAAA,GAAYC,QAAgB,CAAC;AAAE3D,YAAAA;AAAO,SAAA,CAAA;QAC5CA,MAAAA,CAAO0C,KAAK,CAAC,6BAAA,EAA+B1C,MAAAA,CAAO4D,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACP,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACH7B,QAAAA,QAAAA;AACA2B,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"override.js","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDirs: z.array(z.string()).default(['./overrides']),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const response: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = {\n prepends: [],\n appends: []\n };\n\n // Process directories in order (closest to furthest)\n for (let i = 0; i < options.configDirs.length; i++) {\n const configDir = options.configDirs[i];\n const baseFile = path.join(configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n // Check for prepend files (-pre.md)\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s (layer %d)', preFile, i + 1);\n const parser = Parser.create({ logger });\n const prependSection = await parser.parseFile<T>(preFile, currentSectionOptions);\n response.prepends.push(prependSection);\n }\n\n // Check for append files (-post.md)\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s (layer %d)', postFile, i + 1);\n const parser = Parser.create({ logger });\n const appendSection = await parser.parseFile<T>(postFile, currentSectionOptions);\n response.appends.push(appendSection);\n }\n\n // Check for complete override files - use the first (closest) one found\n if (!response.override && await storage.exists(baseFile)) {\n logger.silly('Found base file %s (layer %d)', baseFile, i + 1);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { override: overrideContent, prepends, appends }: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n // Apply prepends in order (closest layer first)\n for (const prepend of prepends) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n // Apply appends in reverse order (furthest layers first, then closest)\n for (const append of appends.reverse()) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDirs","array","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","response","prepends","appends","i","length","configDir","baseFile","path","join","preFile","replace","postFile","exists","silly","parser","Parser","prependSection","parseFile","push","appendSection","warn","error","Error","customize","overrideContent","finalSection","prepend","append","reverse","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYP,EAAEQ,KAAK,CAACR,EAAES,MAAM,EAAA,CAAA,CAAIJ,OAAO,CAAC;AAAC,QAAA;AAAc,KAAA,CAAA;AACvDK,IAAAA,SAAAA,EAAWV,CAAAA,CAAEW,OAAO,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AA;AACb,gBAAA,MAAM,IAAIC,KAAAA,CAAM,+IAAA,CAAA;AACpB,YAAA;AACJ,QAAA;;QAGA,KAAK,MAAMI,WAAWzB,QAAAA,CAAU;YAC5B9B,MAAAA,CAAO0C,KAAK,CAAC,+CAAA,EAAiDa,OAAAA,CAAAA;YAC9DD,YAAAA,GAAeA,YAAAA,CAAaC,OAAO,CAACA,OAAAA,CAAAA;AACxC,QAAA;;AAGA,QAAA,KAAK,MAAMC,MAAAA,IAAUzB,OAAAA,CAAQ0B,OAAO,EAAA,CAAI;YACpCzD,MAAAA,CAAO0C,KAAK,CAAC,8CAAA,EAAgDc,MAAAA,CAAAA;YAC7DF,YAAAA,GAAeA,YAAAA,CAAaE,MAAM,CAACA,MAAAA,CAAAA;AACvC,QAAA;QAEA,MAAME,WAAAA,GAAYC,QAAgB,CAAC;AAAE3D,YAAAA;AAAO,SAAA,CAAA;QAC5CA,MAAAA,CAAO0C,KAAK,CAAC,6BAAA,EAA+B1C,MAAAA,CAAO4D,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACP,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACH7B,QAAAA,QAAAA;AACA2B,QAAAA;AACJ,KAAA;AACJ;;;;"}
package/dist/parser.d.ts CHANGED
@@ -3,14 +3,8 @@ import { Section, SectionOptions } from './items/section';
3
3
  import { Weighted } from './items/weighted';
4
4
  declare const OptionsSchema: z.ZodObject<{
5
5
  logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
6
- parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">]>>>>;
7
- }, "strip", z.ZodTypeAny, {
8
- parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
9
- logger?: any;
10
- }, {
11
- parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
12
- logger?: any;
13
- }>;
6
+ parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>>>;
7
+ }, z.core.$strip>;
14
8
  export type Options = z.infer<typeof OptionsSchema>;
15
9
  export type OptionsParam = Partial<Options>;
16
10
  export interface Instance {