@riotprompt/riotprompt 0.0.21 → 1.0.1-dev.0

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 (69) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/MIGRATION.md +235 -0
  3. package/README.md +2 -0
  4. package/SECURITY.md +132 -0
  5. package/dist/builder.js +6 -0
  6. package/dist/builder.js.map +1 -1
  7. package/dist/cli.js +481 -22
  8. package/dist/context-manager.js +1 -1
  9. package/dist/conversation-logger.d.ts +17 -1
  10. package/dist/conversation-logger.js +21 -17
  11. package/dist/conversation-logger.js.map +1 -1
  12. package/dist/conversation.js +1 -1
  13. package/dist/error-handling.d.ts +52 -0
  14. package/dist/error-handling.js +132 -0
  15. package/dist/error-handling.js.map +1 -0
  16. package/dist/formatter.js +1 -1
  17. package/dist/iteration-strategy.js +1 -1
  18. package/dist/loader.js +60 -12
  19. package/dist/loader.js.map +1 -1
  20. package/dist/logger.d.ts +52 -0
  21. package/dist/logger.js +114 -14
  22. package/dist/logger.js.map +1 -1
  23. package/dist/logging-config.d.ts +84 -0
  24. package/dist/logging-config.js +116 -0
  25. package/dist/logging-config.js.map +1 -0
  26. package/dist/message-builder.js +1 -1
  27. package/dist/model-config.js +1 -1
  28. package/dist/override.js +10 -4
  29. package/dist/override.js.map +1 -1
  30. package/dist/recipes.js +6 -0
  31. package/dist/recipes.js.map +1 -1
  32. package/dist/reflection.js +1 -1
  33. package/dist/riotprompt.d.ts +9 -0
  34. package/dist/riotprompt.js +8 -0
  35. package/dist/riotprompt.js.map +1 -1
  36. package/dist/security/audit-logger.d.ts +61 -0
  37. package/dist/security/audit-logger.js +281 -0
  38. package/dist/security/audit-logger.js.map +1 -0
  39. package/dist/security/cli-security.d.ts +143 -0
  40. package/dist/security/cli-security.js +302 -0
  41. package/dist/security/cli-security.js.map +1 -0
  42. package/dist/security/defaults.d.ts +31 -0
  43. package/dist/security/defaults.js +72 -0
  44. package/dist/security/defaults.js.map +1 -0
  45. package/dist/security/events.d.ts +8 -0
  46. package/dist/security/index.d.ts +27 -0
  47. package/dist/security/index.js +22 -0
  48. package/dist/security/index.js.map +1 -0
  49. package/dist/security/path-guard.d.ts +161 -0
  50. package/dist/security/path-guard.js +327 -0
  51. package/dist/security/path-guard.js.map +1 -0
  52. package/dist/security/rate-limiter.d.ts +117 -0
  53. package/dist/security/rate-limiter.js +165 -0
  54. package/dist/security/rate-limiter.js.map +1 -0
  55. package/dist/security/serialization-schemas.d.ts +183 -0
  56. package/dist/security/serialization-schemas.js +174 -0
  57. package/dist/security/serialization-schemas.js.map +1 -0
  58. package/dist/security/timeout-guard.d.ts +123 -0
  59. package/dist/security/timeout-guard.js +223 -0
  60. package/dist/security/timeout-guard.js.map +1 -0
  61. package/dist/security/types.d.ts +86 -0
  62. package/dist/security/types.js +80 -0
  63. package/dist/security/types.js.map +1 -0
  64. package/dist/token-budget.js +1 -1
  65. package/dist/tools.js +1 -1
  66. package/guide/index.md +2 -0
  67. package/guide/integration.md +1109 -0
  68. package/guide/security.md +237 -0
  69. package/package.json +18 -11
package/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Security
11
+
12
+ This release includes comprehensive security enhancements. See the [Security Guide](./guide/security.md) for details.
13
+
14
+ #### New Security Features
15
+
16
+ - **ToolGuard**: Schema-based validation of tool parameters with Zod integration
17
+ - **ToolSandbox**: Execution timeout and resource limits for tools
18
+ - **PathGuard**: Path traversal prevention with base directory restrictions
19
+ - **SecretGuard**: Automatic redaction of sensitive data in logs and errors via `@fjell/logging`
20
+ - **TimeoutGuard**: Request timeout enforcement for LLM and tool calls
21
+ - **SafeRegex**: ReDoS protection for user-provided regex patterns via `@theunwalked/pressurelid`
22
+ - **CLIValidator**: Input validation for command-line arguments
23
+ - **ErrorSanitizer**: Production-safe error messages with correlation IDs via `@theunwalked/spotclean`
24
+ - **SecurityAuditLogger**: Security event logging and monitoring
25
+ - **RateLimiter**: Rate limiting interfaces and in-memory implementation
26
+
27
+ #### Breaking Changes
28
+
29
+ - `ConversationLogger` now defaults to `redactSensitive: true`
30
+ - Migration: Set `redactSensitive: false` explicitly if needed
31
+ - Library logging is now silent by default
32
+ - Migration: Set `RIOTPROMPT_LOGGING=true` or `NODE_ENV=development` to enable
33
+
34
+ #### Security Fixes
35
+
36
+ - Tool parameters are now validated before execution
37
+ - Path traversal attacks are blocked in file operations
38
+ - API keys are validated and never logged
39
+ - Regex patterns are analyzed for ReDoS vulnerabilities
40
+ - Error messages are sanitized in production mode
41
+ - Hash truncation increased from 16 to 32 characters (128 bits)
42
+ - Glob patterns are sanitized to prevent injection
43
+
44
+ ### Added
45
+
46
+ - Security configuration via `SecurityConfig` type
47
+ - Global security guards: `getPathGuard()`, `getTimeoutGuard()`, `getAuditLogger()`, etc.
48
+ - Security test utilities and attack vector fixtures
49
+ - Security documentation (`SECURITY.md`) and threat model
50
+ - Security guide (`guide/security.md`)
51
+ - Rate limiter interfaces (`RateLimiter`, `MemoryRateLimiter`, `NoOpRateLimiter`)
52
+ - Glob pattern sanitization (`sanitizeGlobPattern`, `isGlobSafe`, `validateGlobPattern`)
53
+ - Error handling utilities (`sanitize`, `createSafeError`, `handleError`)
54
+ - Silent logger (`SILENT_LOGGER`) for production use
55
+
56
+ ### Changed
57
+
58
+ - Default logger is now silent unless explicitly enabled
59
+ - `ConversationLogger` redacts sensitive data by default
60
+ - Hash content uses 32 characters (128 bits) instead of 16
61
+
62
+ ### Dependencies
63
+
64
+ Added the following security-focused dependencies:
65
+
66
+ - `@theunwalked/offrecord` - API key security and redaction
67
+ - `@theunwalked/pressurelid` - Safe regex handling
68
+ - `@theunwalked/spotclean` - Error message sanitization
69
+ - `@fjell/logging` - Secure logging with masking
70
+
71
+ ## [0.0.20] - Previous Release
72
+
73
+ Initial public release with core prompt engineering features.
74
+
package/MIGRATION.md ADDED
@@ -0,0 +1,235 @@
1
+ # Migration Guide
2
+
3
+ ## Upgrading to Security-Enhanced Version
4
+
5
+ This guide helps you migrate to the security-enhanced version of RiotPrompt.
6
+
7
+ ### Breaking Changes
8
+
9
+ #### 1. Logging Redaction Default
10
+
11
+ `ConversationLogger` now redacts sensitive data by default.
12
+
13
+ **Before:**
14
+ ```typescript
15
+ // Logs included API keys, passwords, etc.
16
+ const logger = new ConversationLogger({ enabled: true });
17
+ ```
18
+
19
+ **After:**
20
+ ```typescript
21
+ // Logs are now redacted by default
22
+ const logger = new ConversationLogger({ enabled: true });
23
+
24
+ // To opt-out (development only):
25
+ const logger = new ConversationLogger({
26
+ enabled: true,
27
+ redactSensitive: false
28
+ });
29
+ ```
30
+
31
+ #### 2. Silent Library Logging
32
+
33
+ Library logging is now silent by default to prevent information disclosure.
34
+
35
+ **Before:**
36
+ ```typescript
37
+ // Library logged to console by default
38
+ import { DEFAULT_LOGGER } from '@theunwalked/riotprompt';
39
+ ```
40
+
41
+ **After:**
42
+ ```typescript
43
+ // Library is silent by default
44
+ // Enable logging via environment variable:
45
+ // RIOTPROMPT_LOGGING=true
46
+ // or
47
+ // NODE_ENV=development
48
+ // or
49
+ // DEBUG=*riotprompt*
50
+ ```
51
+
52
+ ### New Features (Opt-In)
53
+
54
+ Most security features are opt-in to maintain backward compatibility:
55
+
56
+ #### Tool Validation
57
+
58
+ ```typescript
59
+ import { ToolGuard } from '@theunwalked/agentic';
60
+ import { z } from 'zod';
61
+
62
+ // Create a guard with schemas
63
+ const guard = new ToolGuard({
64
+ enabled: true,
65
+ validateParams: true,
66
+ });
67
+
68
+ // Register schemas for your tools
69
+ guard.registerSchema('read_file', z.object({
70
+ path: z.string().max(1000),
71
+ }));
72
+
73
+ // Use with ToolRegistry
74
+ const registry = ToolRegistry.create()
75
+ .withSecurity(guard);
76
+ ```
77
+
78
+ #### Path Validation
79
+
80
+ ```typescript
81
+ import { PathGuard, configurePathGuard } from '@theunwalked/riotprompt';
82
+
83
+ // Configure globally
84
+ configurePathGuard({
85
+ enabled: true,
86
+ basePaths: ['./prompts', './context'],
87
+ allowAbsolute: false,
88
+ });
89
+
90
+ // Or use directly
91
+ const guard = new PathGuard({
92
+ basePaths: [process.cwd()],
93
+ });
94
+
95
+ const result = guard.validate(userPath);
96
+ if (!result.valid) {
97
+ throw new Error(result.error);
98
+ }
99
+ ```
100
+
101
+ #### Timeout Enforcement
102
+
103
+ ```typescript
104
+ import { TimeoutGuard } from '@theunwalked/riotprompt';
105
+
106
+ const guard = new TimeoutGuard({
107
+ enabled: true,
108
+ llmTimeout: 120000, // 2 minutes
109
+ toolTimeout: 30000, // 30 seconds
110
+ });
111
+
112
+ // Wrap async operations
113
+ const result = await guard.withLLMTimeout(
114
+ provider.execute(request),
115
+ 'openai-call'
116
+ );
117
+ ```
118
+
119
+ #### Error Sanitization
120
+
121
+ ```typescript
122
+ import { initializeErrorHandling, sanitize } from '@theunwalked/riotprompt';
123
+
124
+ // Initialize at startup
125
+ initializeErrorHandling({
126
+ environment: process.env.NODE_ENV === 'production' ? 'production' : 'development',
127
+ });
128
+
129
+ // Use in error handling
130
+ try {
131
+ await riskyOperation();
132
+ } catch (error) {
133
+ const { external, internal } = sanitize(error);
134
+
135
+ // Log internal details
136
+ console.error('Error:', internal.correlationId, internal.originalMessage);
137
+
138
+ // Return safe error to user
139
+ throw new Error(external.message);
140
+ }
141
+ ```
142
+
143
+ ### Recommended Configuration
144
+
145
+ For production use, we recommend enabling all security features:
146
+
147
+ ```typescript
148
+ import {
149
+ configurePathGuard,
150
+ configureTimeoutGuard,
151
+ configureAuditLogger,
152
+ initializeErrorHandling,
153
+ } from '@theunwalked/riotprompt';
154
+
155
+ // Initialize error handling first
156
+ initializeErrorHandling({
157
+ environment: 'production',
158
+ basePaths: [process.cwd()],
159
+ });
160
+
161
+ // Configure path security
162
+ configurePathGuard({
163
+ enabled: true,
164
+ basePaths: [process.cwd()],
165
+ allowAbsolute: false,
166
+ });
167
+
168
+ // Configure timeout protection
169
+ configureTimeoutGuard({
170
+ enabled: true,
171
+ llmTimeout: 120000,
172
+ toolTimeout: 30000,
173
+ });
174
+
175
+ // Configure audit logging
176
+ configureAuditLogger({
177
+ enabled: true,
178
+ logLevel: 'warning',
179
+ onEvent: (event) => {
180
+ // Send to your monitoring system
181
+ if (event.severity === 'error') {
182
+ alertOps(event);
183
+ }
184
+ },
185
+ });
186
+ ```
187
+
188
+ ### Environment Variables
189
+
190
+ The following environment variables control security behavior:
191
+
192
+ | Variable | Description | Default |
193
+ |----------|-------------|---------|
194
+ | `RIOTPROMPT_LOGGING` | Enable library logging | `false` |
195
+ | `NODE_ENV` | Environment mode (`development` enables logging) | - |
196
+ | `DEBUG` | Debug patterns (include `riotprompt` to enable) | - |
197
+
198
+ ### Dependency Changes
199
+
200
+ This version adds the following dependencies:
201
+
202
+ - `@theunwalked/offrecord` - API key security
203
+ - `@theunwalked/pressurelid` - Safe regex
204
+ - `@theunwalked/spotclean` - Error sanitization
205
+ - `@fjell/logging` - Secure logging
206
+
207
+ These are production dependencies and will be installed automatically.
208
+
209
+ ### Testing Your Migration
210
+
211
+ After upgrading, verify security features work correctly:
212
+
213
+ ```typescript
214
+ import { PathGuard, sanitize } from '@theunwalked/riotprompt';
215
+
216
+ // Test path validation
217
+ const guard = new PathGuard({ basePaths: ['/app'] });
218
+ console.assert(!guard.validate('../etc/passwd').valid, 'Path traversal should be blocked');
219
+
220
+ // Test error sanitization
221
+ const error = new Error('Key: sk-secret123456789012345');
222
+ const { external } = sanitize(error);
223
+ console.assert(!external.message.includes('sk-secret'), 'Secrets should be redacted');
224
+
225
+ console.log('Security migration verified!');
226
+ ```
227
+
228
+ ### Getting Help
229
+
230
+ If you encounter issues during migration:
231
+
232
+ 1. Check the [Security Guide](./guide/security.md) for detailed configuration
233
+ 2. Review the [CHANGELOG](./CHANGELOG.md) for all changes
234
+ 3. Open an issue on GitHub with the `migration` label
235
+
package/README.md CHANGED
@@ -187,3 +187,5 @@ Apache-2.0 License - see [LICENSE](LICENSE) for details.
187
187
  ---
188
188
 
189
189
  *Build better prompts, faster.*
190
+
191
+ <!-- v1.0.0 -->
package/SECURITY.md ADDED
@@ -0,0 +1,132 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 0.x.x | :white_check_mark: |
8
+
9
+ ## Reporting a Vulnerability
10
+
11
+ If you discover a security vulnerability, please report it responsibly.
12
+
13
+ **Do not open a public GitHub issue for security vulnerabilities.**
14
+
15
+ You can expect:
16
+ - Acknowledgment within 48 hours
17
+ - Status update within 7 days
18
+ - Resolution timeline based on severity
19
+
20
+ ## Security Features
21
+
22
+ RiotPrompt includes comprehensive security features to protect your AI workflows:
23
+
24
+ ### Tool Execution Security
25
+ - **Parameter Validation**: All tool parameters validated against Zod schemas via `ToolGuard`
26
+ - **Execution Sandboxing**: Tools run with configurable restrictions via `ToolSandbox`
27
+ - **Timeout Protection**: Automatic timeout for long-running tools
28
+ - **Prototype Pollution Prevention**: Blocks `__proto__`, `constructor`, `prototype` in parameters
29
+
30
+ ### Path Security
31
+ - **Path Validation**: Prevents directory traversal attacks via `PathGuard`
32
+ - **Base Path Restriction**: Limit file access to specific directories
33
+ - **Pattern Blocking**: Blocks dangerous path patterns (`..\`, `~`, `${`, etc.)
34
+ - **Glob Sanitization**: Safe handling of glob patterns
35
+
36
+ ### Secret Protection
37
+ - **Automatic Redaction**: Sensitive data redacted in logs via `@fjell/logging`
38
+ - **API Key Security**: Keys validated and never logged via `@theunwalked/offrecord`
39
+ - **Error Sanitization**: Production errors don't leak secrets via `@theunwalked/spotclean`
40
+ - **Pattern Detection**: Built-in patterns for OpenAI, Anthropic, Gemini, and common secrets
41
+
42
+ ### Request Security
43
+ - **Timeout Enforcement**: All external requests have configurable timeouts via `TimeoutGuard`
44
+ - **Rate Limiting Interfaces**: Built-in interfaces for rate limiting
45
+ - **Safe Regex**: ReDoS protection via `@theunwalked/pressurelid`
46
+
47
+ ### Logging Security
48
+ - **Silent by Default**: Library logging disabled unless explicitly enabled
49
+ - **Sensitive Data Masking**: Automatic masking of API keys, passwords, emails, etc.
50
+ - **Audit Logging**: Security events tracked via `SecurityAuditLogger`
51
+
52
+ ## Secure Configuration
53
+
54
+ ### Recommended Defaults
55
+
56
+ ```typescript
57
+ import { Security } from '@theunwalked/riotprompt';
58
+
59
+ // Configure path security
60
+ Security.configurePathGuard({
61
+ enabled: true,
62
+ basePaths: ['./prompts', './context'],
63
+ allowAbsolute: false,
64
+ allowSymlinks: false,
65
+ });
66
+
67
+ // Configure timeout protection
68
+ Security.configureTimeoutGuard({
69
+ enabled: true,
70
+ llmTimeout: 120000, // 2 minutes for LLM calls
71
+ toolTimeout: 30000, // 30 seconds for tools
72
+ fileTimeout: 5000, // 5 seconds for file ops
73
+ });
74
+
75
+ // Configure audit logging
76
+ Security.configureAuditLogger({
77
+ enabled: true,
78
+ logLevel: 'warning',
79
+ onEvent: (event) => {
80
+ // Send to your monitoring system
81
+ },
82
+ });
83
+ ```
84
+
85
+ ### Environment Variables
86
+
87
+ Enable logging only when needed:
88
+
89
+ ```bash
90
+ # Enable riotprompt logging
91
+ RIOTPROMPT_LOGGING=true
92
+
93
+ # Or use DEBUG pattern
94
+ DEBUG=*riotprompt*
95
+
96
+ # Development mode enables logging
97
+ NODE_ENV=development
98
+ ```
99
+
100
+ ## Known Limitations
101
+
102
+ 1. **Tool Sandboxing**: Not true process isolation; tools share the Node.js process
103
+ 2. **Regex Analysis**: Static analysis may not catch all ReDoS patterns
104
+ 3. **Rate Limiting**: Interfaces provided; implementation is user responsibility
105
+ 4. **Memory Safety**: JavaScript limitations apply to secure string handling
106
+
107
+ ## Security Checklist
108
+
109
+ - [ ] Use environment variables for API keys, not CLI flags
110
+ - [ ] Configure base paths for file operations
111
+ - [ ] Enable parameter validation for tools
112
+ - [ ] Set appropriate timeouts
113
+ - [ ] Enable log redaction in production
114
+ - [ ] Review tool definitions for security
115
+ - [ ] Monitor audit logs for security events
116
+ - [ ] Use `NODE_ENV=production` in production
117
+
118
+ ## Dependencies
119
+
120
+ Security features rely on these packages:
121
+
122
+ | Package | Purpose |
123
+ |---------|---------|
124
+ | `@theunwalked/offrecord` | API key security and redaction |
125
+ | `@theunwalked/pressurelid` | Safe regex handling |
126
+ | `@theunwalked/spotclean` | Error message sanitization |
127
+ | `@fjell/logging` | Secure logging with masking |
128
+
129
+ ## Security Updates
130
+
131
+ Security updates will be released as patch versions. Subscribe to releases to stay informed.
132
+
package/dist/builder.js CHANGED
@@ -12,10 +12,16 @@ import { create as create$2 } from './override.js';
12
12
  import './recipes.js';
13
13
  import './conversation.js';
14
14
  import 'tiktoken';
15
+ import './logging-config.js';
15
16
  import './tools.js';
16
17
  import 'openai';
17
18
  import '@anthropic-ai/sdk';
18
19
  import '@google/generative-ai';
20
+ import './security/types.js';
21
+ import './security/defaults.js';
22
+ import './security/serialization-schemas.js';
23
+ import '@theunwalked/pressurelid';
24
+ import '@theunwalked/spotclean';
19
25
 
20
26
  const OptionSchema = z.object({
21
27
  logger: z.any().optional().default(DEFAULT_LOGGER),
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","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 overridePaths: z.array(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, configDirs: options.overridePaths || [\"./\"],\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> = await 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> = await 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","overridePaths","array","overrides","boolean","parameters","ParametersSchema","create","builderOptions","options","parse","wrapLogger","parser","Parser","override","Override","configDirs","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,CAAAA,CAAEC,MAAM,CAAC;AAC1BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,QAAAA,EAAUP,EAAEQ,MAAM,EAAA;IAClBC,aAAAA,EAAeT,CAAAA,CAAEU,KAAK,CAACV,CAAAA,CAAEQ,MAAM,EAAA,CAAA,CAAIJ,QAAQ,EAAA,CAAGC,OAAO,CAAC;AAAC,QAAA;AAAK,KAAA,CAAA;AAC5DM,IAAAA,SAAAA,EAAWX,EAAEY,OAAO,EAAA,CAAGR,QAAQ,EAAA,CAAGC,OAAO,CAAC,KAAA,CAAA;AAC1CQ,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBV,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAkBO,MAAMU,SAAS,CAACC,cAAAA,GAAAA;IACnB,MAAMC,OAAAA,GAA6BlB,YAAAA,CAAamB,KAAK,CAACF,cAAAA,CAAAA;AAEtD,IAAA,MAAMd,MAAAA,GAASiB,UAAAA,CAAWF,OAAAA,CAAQf,MAAM,EAAE,SAAA,CAAA;IAC1C,MAAMkB,QAAAA,GAASC,QAAa,CAAC;AAAEnB,QAAAA;AAAO,KAAA,CAAA;IACtC,MAAMoB,UAAAA,GAAWC,QAAe,CAAC;AAC7BrB,QAAAA,MAAAA;QAAQsB,UAAAA,EAAYP,OAAAA,CAAQR,aAAa,IAAI;AAAC,YAAA;AAAK,SAAA;QACnDE,SAAAA,EAAWM,OAAAA,CAAQN,SAAS,IAAI;AACpC,KAAA,CAAA;IACA,MAAMc,QAAAA,GAASC,QAAa,CAAC;AAAExB,QAAAA;AAAO,KAAA,CAAA;AAEtC,IAAA,MAAMyB,iBAAuCC,QA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C,iBAAA,EAAmB,EAAC,CAAA;AACjC,QAAA,MAAM8B,SAASC,QAAAA,CAAa;YAAEX,OAAAA,EAASjC,cAAAA;YAAgB6C,QAAAA,EAAU1C,cAAAA;YAAgB2C,YAAAA,EAAc1C,kBAAAA;YAAoB2C,QAAAA,EAAU1C;AAAe,SAAA,CAAA;QAC5I,OAAOsC,MAAAA;AACX,IAAA,CAAA;AACArC,IAAAA,QAAAA,CAASoC,KAAK,GAAGA,KAAAA;IAEjB,OAAOpC,QAAAA;AACX;;;;"}
1
+ {"version":3,"file":"builder.js","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 overridePaths: z.array(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, configDirs: options.overridePaths || [\"./\"],\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> = await 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> = await 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","overridePaths","array","overrides","boolean","parameters","ParametersSchema","create","builderOptions","options","parse","wrapLogger","parser","Parser","override","Override","configDirs","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,CAAAA,CAAEC,MAAM,CAAC;AAC1BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,QAAAA,EAAUP,EAAEQ,MAAM,EAAA;IAClBC,aAAAA,EAAeT,CAAAA,CAAEU,KAAK,CAACV,CAAAA,CAAEQ,MAAM,EAAA,CAAA,CAAIJ,QAAQ,EAAA,CAAGC,OAAO,CAAC;AAAC,QAAA;AAAK,KAAA,CAAA;AAC5DM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