@riotprompt/riotprompt 0.0.20 → 1.0.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.
- package/CHANGELOG.md +74 -0
- package/MIGRATION.md +235 -0
- package/README.md +2 -0
- package/SECURITY.md +132 -0
- package/dist/builder.js +6 -0
- package/dist/builder.js.map +1 -1
- package/dist/{cli.cjs → cli.js} +658 -216
- package/dist/context-manager.js +1 -1
- package/dist/conversation-logger.d.ts +17 -1
- package/dist/conversation-logger.js +21 -17
- package/dist/conversation-logger.js.map +1 -1
- package/dist/conversation.js +1 -1
- package/dist/error-handling.d.ts +52 -0
- package/dist/error-handling.js +132 -0
- package/dist/error-handling.js.map +1 -0
- package/dist/formatter.js +1 -1
- package/dist/iteration-strategy.js +1 -1
- package/dist/loader.js +60 -12
- package/dist/loader.js.map +1 -1
- package/dist/logger.d.ts +52 -0
- package/dist/logger.js +114 -14
- package/dist/logger.js.map +1 -1
- package/dist/logging-config.d.ts +84 -0
- package/dist/logging-config.js +116 -0
- package/dist/logging-config.js.map +1 -0
- package/dist/message-builder.js +1 -1
- package/dist/model-config.js +1 -1
- package/dist/override.js +10 -4
- package/dist/override.js.map +1 -1
- package/dist/recipes.js +6 -0
- package/dist/recipes.js.map +1 -1
- package/dist/reflection.js +1 -1
- package/dist/riotprompt.d.ts +9 -0
- package/dist/riotprompt.js +8 -0
- package/dist/riotprompt.js.map +1 -1
- package/dist/security/audit-logger.d.ts +61 -0
- package/dist/security/audit-logger.js +281 -0
- package/dist/security/audit-logger.js.map +1 -0
- package/dist/security/cli-security.d.ts +143 -0
- package/dist/security/cli-security.js +302 -0
- package/dist/security/cli-security.js.map +1 -0
- package/dist/security/defaults.d.ts +31 -0
- package/dist/security/defaults.js +72 -0
- package/dist/security/defaults.js.map +1 -0
- package/dist/security/events.d.ts +8 -0
- package/dist/security/index.d.ts +27 -0
- package/dist/security/index.js +22 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/path-guard.d.ts +161 -0
- package/dist/security/path-guard.js +327 -0
- package/dist/security/path-guard.js.map +1 -0
- package/dist/security/rate-limiter.d.ts +117 -0
- package/dist/security/rate-limiter.js +165 -0
- package/dist/security/rate-limiter.js.map +1 -0
- package/dist/security/serialization-schemas.d.ts +183 -0
- package/dist/security/serialization-schemas.js +174 -0
- package/dist/security/serialization-schemas.js.map +1 -0
- package/dist/security/timeout-guard.d.ts +123 -0
- package/dist/security/timeout-guard.js +223 -0
- package/dist/security/timeout-guard.js.map +1 -0
- package/dist/security/types.d.ts +86 -0
- package/dist/security/types.js +80 -0
- package/dist/security/types.js.map +1 -0
- package/dist/token-budget.js +1 -1
- package/dist/tools.js +1 -1
- package/dist/util/storage.js.map +1 -1
- package/guide/index.md +2 -0
- package/guide/integration.md +1109 -0
- package/guide/security.md +237 -0
- package/package.json +23 -17
- package/vite.config.cli.ts +9 -18
- package/dist/riotprompt.cjs +0 -6169
- package/dist/riotprompt.cjs.map +0 -1
package/dist/loader.js.map
CHANGED
|
@@ -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 => {\n try {\n return new RegExp(pattern, 'i');\n } catch (error) {\n logger.error(`Invalid ignore pattern: ${pattern}`, { error });\n // Return a pattern that matches nothing\n return /(?!)/; // Negative lookahead that always fails\n }\n });\n\n const filteredFiles = files.filter(file => {\n const fullPath = path.join(contextDir, file);\n // Test against both filename and full path for flexibility\n return !ignorePatternsRegex.some(regex => regex.test(file) || regex.test(fullPath));\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 // Type is correct - Section.add() accepts Section<T>\n mainContextSection.add(fileSection, { ...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","error","filteredFiles","filter","file","fullPath","some","regex","test","filePath","isFile","fileContent","sectionName","contentToAdd","endsWith","fileHeader","fileSection","push"],"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,I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AA,CAAA,CAAE,OAAOiB,KAAAA,EAAO;gBACZxD,MAAAA,CAAOwD,KAAK,CAAC,CAAC,mCAAmC,EAAErB,UAAAA,CAAW,EAAE,EAAEqB,KAAAA,CAAAA,CAAO,CAAA;AAC7E,YAAA;AACJ,QAAA;QAEA,OAAO1B,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 { SafeRegex } from \"@theunwalked/pressurelid\";\nimport { DEFAULT_IGNORE_PATTERNS } from \"./constants\";\nimport { ParametersSchema } from \"./items/parameters\";\nimport { SectionOptions, SectionOptionsSchema } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger, type Logger } from \"./logger\";\nimport { Section, Weighted, createSection } from \"./riotprompt\";\nimport * as Storage from \"./util/storage\";\nimport { getAuditLogger } from \"./security/audit-logger\";\nimport { createSafeError } from \"./error-handling\";\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\n/**\n * Create safe regex patterns from ignore patterns using pressurelid\n * to prevent ReDoS attacks from malicious patterns.\n *\n * @param patterns - Array of ignore patterns (can be regex or glob-like)\n * @param logger - Logger instance for warnings\n * @returns Array of safe RegExp objects\n */\nfunction createSafeIgnorePatterns(patterns: string[], logger: Logger): RegExp[] {\n const auditLogger = getAuditLogger();\n\n // Create SafeRegex instance with security callbacks\n const safeRegex = new SafeRegex({\n maxLength: 500,\n timeoutMs: 1000,\n onBlock: (message, pattern) => {\n logger.warn(`Blocked unsafe ignore pattern: ${message}`, { patternLength: pattern.length });\n auditLogger.log({\n type: 'regex_blocked',\n severity: 'warning',\n message: `Blocked unsafe regex pattern: ${message}`,\n context: { patternLength: pattern.length },\n });\n },\n onWarning: (message, _pattern) => {\n logger.debug(`Regex warning: ${message}`);\n },\n });\n\n return patterns\n .map(pattern => {\n // Try to create a safe regex from the pattern\n const result = safeRegex.create(pattern, 'i');\n\n if (result.safe && result.regex) {\n return result.regex;\n }\n\n // If direct regex fails, try as glob pattern\n const globResult = safeRegex.globToRegex(pattern);\n if (globResult.safe && globResult.regex) {\n return globResult.regex;\n }\n\n // Log the failure and return a pattern that matches nothing\n logger.warn(`Invalid or unsafe ignore pattern \"${pattern}\": ${result.error || globResult.error}`);\n return null;\n })\n .filter((regex): regex is RegExp => regex !== null);\n}\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 = createSafeIgnorePatterns(ignorePatterns, logger);\n\n const filteredFiles = files.filter(file => {\n const fullPath = path.join(contextDir, file);\n // Test against both filename and full path for flexibility\n return !ignorePatternsRegex.some(regex => regex.test(file) || regex.test(fullPath));\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 // Type is correct - Section.add() accepts Section<T>\n mainContextSection.add(fileSection, { ...sectionOptions });\n }\n }\n\n contextSections.push(mainContextSection);\n } catch (error) {\n // Create a safe error that doesn't leak path information\n const safeError = createSafeError(error, { operation: 'load', directory: path.basename(contextDir) });\n logger.error(`Error processing context directory: ${safeError.message}`);\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","createSafeIgnorePatterns","patterns","auditLogger","getAuditLogger","safeRegex","SafeRegex","maxLength","timeoutMs","onBlock","message","pattern","warn","patternLength","length","log","type","severity","context","onWarning","_pattern","debug","map","result","create","safe","regex","globResult","globToRegex","error","filter","extractFirstHeader","markdownText","headerRegex","match","trim","removeFirstHeader","replace","loaderOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","load","contextDirectories","contextSections","storage","Storage","contextDir","dirName","path","basename","mainContextSection","contextFile","join","exists","mainContextContent","readFile","firstHeader","sectionTitle","createSection","title","add","files","listFiles","ignorePatternsRegex","filteredFiles","file","fullPath","some","test","filePath","isFile","fileContent","sectionName","contentToAdd","endsWith","fileHeader","fileSection","push","safe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ger
|
|
3
|
+
*
|
|
4
|
+
* Provides logging infrastructure backed by @fjell/logging for
|
|
5
|
+
* comprehensive sensitive data masking and structured logging.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Logger interface compatible with @fjell/logging
|
|
9
|
+
*/
|
|
1
10
|
export interface Logger {
|
|
2
11
|
name: string;
|
|
3
12
|
debug: (message: string, ...args: any[]) => void;
|
|
@@ -6,6 +15,49 @@ export interface Logger {
|
|
|
6
15
|
error: (message: string, ...args: any[]) => void;
|
|
7
16
|
verbose: (message: string, ...args: any[]) => void;
|
|
8
17
|
silly: (message: string, ...args: any[]) => void;
|
|
18
|
+
/** Get a child logger for a component */
|
|
19
|
+
get?: (...components: string[]) => Logger;
|
|
9
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Silent logger that discards all output
|
|
23
|
+
* Use this as default to prevent accidental information disclosure
|
|
24
|
+
*/
|
|
25
|
+
export declare const SILENT_LOGGER: Logger;
|
|
26
|
+
/**
|
|
27
|
+
* Default logger - silent by default to prevent information disclosure
|
|
28
|
+
*
|
|
29
|
+
* Enable logging by setting one of:
|
|
30
|
+
* - RIOTPROMPT_LOGGING=true
|
|
31
|
+
* - DEBUG=*riotprompt*
|
|
32
|
+
* - NODE_ENV=development
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { DEFAULT_LOGGER } from '@theunwalked/riotprompt';
|
|
37
|
+
*
|
|
38
|
+
* const logger = DEFAULT_LOGGER.get?.('MyComponent') ?? DEFAULT_LOGGER;
|
|
39
|
+
* logger.info('Processing request', { userId: 123 });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
10
42
|
export declare const DEFAULT_LOGGER: Logger;
|
|
43
|
+
/**
|
|
44
|
+
* Wrap an existing logger with library prefix
|
|
45
|
+
*
|
|
46
|
+
* @param toWrap - Logger to wrap
|
|
47
|
+
* @param name - Optional component name
|
|
48
|
+
* @returns Wrapped logger with library prefix
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const myLogger = wrapLogger(customLogger, 'MyComponent');
|
|
53
|
+
* myLogger.info('Hello'); // [riotprompt] [MyComponent]: Hello
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
11
56
|
export declare const wrapLogger: (toWrap: Logger, name?: string) => Logger;
|
|
57
|
+
/**
|
|
58
|
+
* Create a console-based fallback logger (for environments without Fjell config)
|
|
59
|
+
*
|
|
60
|
+
* @param name - Logger name
|
|
61
|
+
* @returns Console-based logger
|
|
62
|
+
*/
|
|
63
|
+
export declare function createConsoleLogger(name?: string): Logger;
|
package/dist/logger.js
CHANGED
|
@@ -1,17 +1,99 @@
|
|
|
1
|
+
import Logging from '@fjell/logging';
|
|
1
2
|
import { LIBRARY_NAME } from './constants.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
// Get the library-level logger from Fjell
|
|
5
|
+
const LibLogger = Logging.getLogger('@theunwalked/riotprompt');
|
|
6
|
+
/**
|
|
7
|
+
* Create a silent logger with the given name
|
|
8
|
+
*/ function createSilentLogger(name) {
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
debug: ()=>{},
|
|
12
|
+
info: ()=>{},
|
|
13
|
+
warn: ()=>{},
|
|
14
|
+
error: ()=>{},
|
|
15
|
+
verbose: ()=>{},
|
|
16
|
+
silly: ()=>{},
|
|
17
|
+
get: (...components)=>createSilentLogger(`${name}:${components.join(':')}`)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Silent logger that discards all output
|
|
22
|
+
* Use this as default to prevent accidental information disclosure
|
|
23
|
+
*/ const SILENT_LOGGER = createSilentLogger('silent');
|
|
24
|
+
/**
|
|
25
|
+
* Check if logging is explicitly enabled via environment variable
|
|
26
|
+
*/ const isLoggingEnabled = ()=>{
|
|
27
|
+
var _process_env_DEBUG;
|
|
28
|
+
return process.env.RIOTPROMPT_LOGGING === 'true' || ((_process_env_DEBUG = process.env.DEBUG) === null || _process_env_DEBUG === void 0 ? void 0 : _process_env_DEBUG.includes('riotprompt')) || process.env.NODE_ENV === 'development';
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Create a Logger from a Fjell logger instance
|
|
32
|
+
*/ function createLoggerFromFjell(fjellLogger, name) {
|
|
33
|
+
return {
|
|
34
|
+
name,
|
|
35
|
+
debug: (message, ...args)=>fjellLogger.debug(message, ...args),
|
|
36
|
+
info: (message, ...args)=>fjellLogger.info(message, ...args),
|
|
37
|
+
warn: (message, ...args)=>fjellLogger.warning(message, ...args),
|
|
38
|
+
error: (message, ...args)=>fjellLogger.error(message, ...args),
|
|
39
|
+
verbose: (message, ...args)=>fjellLogger.debug(message, ...args),
|
|
40
|
+
silly: (message, ...args)=>fjellLogger.debug(message, ...args),
|
|
41
|
+
get: (...components)=>{
|
|
42
|
+
const childLogger = fjellLogger.get(...components);
|
|
43
|
+
return createLoggerFromFjell(childLogger, `${name}:${components.join(':')}`);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fjell-backed logger with sensitive data masking
|
|
49
|
+
*
|
|
50
|
+
* Features:
|
|
51
|
+
* - Automatic sensitive data masking (API keys, passwords, etc.)
|
|
52
|
+
* - Circular reference protection
|
|
53
|
+
* - Hierarchical component logging
|
|
54
|
+
* - Correlation ID support
|
|
55
|
+
*/ const FJELL_LOGGER = {
|
|
56
|
+
name: 'fjell',
|
|
57
|
+
debug: (message, ...args)=>LibLogger.debug(message, ...args),
|
|
58
|
+
info: (message, ...args)=>LibLogger.info(message, ...args),
|
|
59
|
+
warn: (message, ...args)=>LibLogger.warning(message, ...args),
|
|
60
|
+
error: (message, ...args)=>LibLogger.error(message, ...args),
|
|
61
|
+
verbose: (message, ...args)=>LibLogger.debug(message, ...args),
|
|
62
|
+
silly: (message, ...args)=>LibLogger.debug(message, ...args),
|
|
63
|
+
get: (...components)=>{
|
|
64
|
+
const childLogger = LibLogger.get(...components);
|
|
65
|
+
return createLoggerFromFjell(childLogger, components.join(':'));
|
|
66
|
+
}
|
|
13
67
|
};
|
|
14
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Default logger - silent by default to prevent information disclosure
|
|
70
|
+
*
|
|
71
|
+
* Enable logging by setting one of:
|
|
72
|
+
* - RIOTPROMPT_LOGGING=true
|
|
73
|
+
* - DEBUG=*riotprompt*
|
|
74
|
+
* - NODE_ENV=development
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* import { DEFAULT_LOGGER } from '@theunwalked/riotprompt';
|
|
79
|
+
*
|
|
80
|
+
* const logger = DEFAULT_LOGGER.get?.('MyComponent') ?? DEFAULT_LOGGER;
|
|
81
|
+
* logger.info('Processing request', { userId: 123 });
|
|
82
|
+
* ```
|
|
83
|
+
*/ const DEFAULT_LOGGER = isLoggingEnabled() ? FJELL_LOGGER : SILENT_LOGGER;
|
|
84
|
+
/**
|
|
85
|
+
* Wrap an existing logger with library prefix
|
|
86
|
+
*
|
|
87
|
+
* @param toWrap - Logger to wrap
|
|
88
|
+
* @param name - Optional component name
|
|
89
|
+
* @returns Wrapped logger with library prefix
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const myLogger = wrapLogger(customLogger, 'MyComponent');
|
|
94
|
+
* myLogger.info('Hello'); // [riotprompt] [MyComponent]: Hello
|
|
95
|
+
* ```
|
|
96
|
+
*/ const wrapLogger = (toWrap, name)=>{
|
|
15
97
|
const requiredMethods = [
|
|
16
98
|
'debug',
|
|
17
99
|
'info',
|
|
@@ -34,15 +116,33 @@ const wrapLogger = (toWrap, name)=>{
|
|
|
34
116
|
else if (level === 'silly') toWrap.silly(message, ...args);
|
|
35
117
|
};
|
|
36
118
|
return {
|
|
37
|
-
name: 'wrapped',
|
|
119
|
+
name: name || 'wrapped',
|
|
38
120
|
debug: (message, ...args)=>log('debug', message, ...args),
|
|
39
121
|
info: (message, ...args)=>log('info', message, ...args),
|
|
40
122
|
warn: (message, ...args)=>log('warn', message, ...args),
|
|
41
123
|
error: (message, ...args)=>log('error', message, ...args),
|
|
42
124
|
verbose: (message, ...args)=>log('verbose', message, ...args),
|
|
43
|
-
silly: (message, ...args)=>log('silly', message, ...args)
|
|
125
|
+
silly: (message, ...args)=>log('silly', message, ...args),
|
|
126
|
+
get: (...components)=>wrapLogger(toWrap, name ? `${name}:${components.join(':')}` : components.join(':'))
|
|
44
127
|
};
|
|
45
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Create a console-based fallback logger (for environments without Fjell config)
|
|
131
|
+
*
|
|
132
|
+
* @param name - Logger name
|
|
133
|
+
* @returns Console-based logger
|
|
134
|
+
*/ function createConsoleLogger(name = 'console') {
|
|
135
|
+
return {
|
|
136
|
+
name,
|
|
137
|
+
debug: (message, ...args)=>console.debug(`[DEBUG] [${name}]`, message, ...args),
|
|
138
|
+
info: (message, ...args)=>console.info(`[INFO] [${name}]`, message, ...args),
|
|
139
|
+
warn: (message, ...args)=>console.warn(`[WARN] [${name}]`, message, ...args),
|
|
140
|
+
error: (message, ...args)=>console.error(`[ERROR] [${name}]`, message, ...args),
|
|
141
|
+
verbose: ()=>{},
|
|
142
|
+
silly: ()=>{},
|
|
143
|
+
get: (...components)=>createConsoleLogger(`${name}:${components.join(':')}`)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
46
146
|
|
|
47
|
-
export { DEFAULT_LOGGER, wrapLogger };
|
|
147
|
+
export { DEFAULT_LOGGER, SILENT_LOGGER, createConsoleLogger, wrapLogger };
|
|
48
148
|
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { LIBRARY_NAME } from \"./constants\";\n\nexport interface Logger {\n name: string;\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n}\n\nexport const DEFAULT_LOGGER: Logger = {\n name: 'default',\n debug: (message: string, ...args: any[]) => console.debug(message, ...args),\n info: (message: string, ...args: any[]) => console.info(message, ...args),\n warn: (message: string, ...args: any[]) => console.warn(message, ...args),\n error: (message: string, ...args: any[]) => console.error(message, ...args),\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n verbose: (message: string, ...args: any[]) => { },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n silly: (message: string, ...args: any[]) => { },\n}\n\nexport const wrapLogger = (toWrap: Logger, name?: string): Logger => {\n\n const requiredMethods: (keyof Logger)[] = ['debug', 'info', 'warn', 'error', 'verbose', 'silly'];\n const missingMethods = requiredMethods.filter(method => typeof toWrap[method] !== 'function');\n\n if (missingMethods.length > 0) {\n throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);\n }\n\n const log = (level: keyof Logger, message: string, ...args: any[]) => {\n message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;\n\n if (level === 'debug') toWrap.debug(message, ...args);\n else if (level === 'info') toWrap.info(message, ...args);\n else if (level === 'warn') toWrap.warn(message, ...args);\n else if (level === 'error') toWrap.error(message, ...args);\n else if (level === 'verbose') toWrap.verbose(message, ...args);\n else if (level === 'silly') toWrap.silly(message, ...args);\n }\n\n return {\n name: 'wrapped',\n debug: (message: string, ...args: any[]) => log('debug', message, ...args),\n info: (message: string, ...args: any[]) => log('info', message, ...args),\n warn: (message: string, ...args: any[]) => log('warn', message, ...args),\n error: (message: string, ...args: any[]) => log('error', message, ...args),\n verbose: (message: string, ...args: any[]) => log('verbose', message, ...args),\n silly: (message: string, ...args: any[]) => log('silly', message, ...args),\n }\n}"],"names":["DEFAULT_LOGGER","name","debug","message","args","console","info","warn","error","verbose","silly","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","join","log","level","LIBRARY_NAME"],"mappings":";;MAaaA,cAAAA,GAAyB;IAClCC,IAAAA,EAAM,SAAA;AACNC,IAAAA,KAAAA,EAAO,CAACC,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQH,KAAK,CAACC,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACtEE,IAAAA,IAAAA,EAAM,CAACH,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQC,IAAI,CAACH,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACpEG,IAAAA,IAAAA,EAAM,CAACJ,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQE,IAAI,CAACJ,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACpEI,IAAAA,KAAAA,EAAO,CAACL,OAAAA,EAAiB,GAAGC,OAAgBC,OAAAA,CAAQG,KAAK,CAACL,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;;IAEtEK,OAAAA,EAAS,CAACN,OAAAA,EAAiB,GAAGC,IAAAA,GAAAA,CAAkB,CAAA;;IAEhDM,KAAAA,EAAO,CAACP,OAAAA,EAAiB,GAAGC,IAAAA,GAAAA,CAAkB;AAClD;AAEO,MAAMO,UAAAA,GAAa,CAACC,MAAAA,EAAgBX,IAAAA,GAAAA;AAEvC,IAAA,MAAMY,eAAAA,GAAoC;AAAC,QAAA,OAAA;AAAS,QAAA,MAAA;AAAQ,QAAA,MAAA;AAAQ,QAAA,OAAA;AAAS,QAAA,SAAA;AAAW,QAAA;AAAQ,KAAA;IAChG,MAAMC,cAAAA,GAAiBD,eAAAA,CAAgBE,MAAM,CAACC,CAAAA,SAAU,OAAOJ,MAAM,CAACI,MAAAA,CAAO,KAAK,UAAA,CAAA;IAElF,IAAIF,cAAAA,C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AAA,GAAYC,IAAAA,CAAAA;AACrEE,QAAAA,IAAAA,EAAM,CAACH,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,QAAQjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACnEG,QAAAA,IAAAA,EAAM,CAACJ,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,QAAQjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACnEI,QAAAA,KAAAA,EAAO,CAACL,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,SAASjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACrEK,QAAAA,OAAAA,EAAS,CAACN,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,WAAWjB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACzEM,QAAAA,KAAAA,EAAO,CAACP,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBgB,GAAAA,CAAI,SAASjB,OAAAA,EAAAA,GAAYC,IAAAA;AACzE,KAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\n/**\n * RiotPrompt - Logger\n * \n * Provides logging infrastructure backed by @fjell/logging for\n * comprehensive sensitive data masking and structured logging.\n */\n\nimport Logging from '@fjell/logging';\nimport { LIBRARY_NAME } from \"./constants\";\n\n/**\n * Logger interface compatible with @fjell/logging\n */\nexport interface Logger {\n name: string;\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n /** Get a child logger for a component */\n get?: (...components: string[]) => Logger;\n}\n\n// Get the library-level logger from Fjell\nconst LibLogger = Logging.getLogger('@theunwalked/riotprompt');\n\n/**\n * Create a silent logger with the given name\n */\nfunction createSilentLogger(name: string): Logger {\n return {\n name,\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n verbose: () => {},\n silly: () => {},\n get: (...components: string[]) => createSilentLogger(`${name}:${components.join(':')}`),\n };\n}\n\n/**\n * Silent logger that discards all output\n * Use this as default to prevent accidental information disclosure\n */\nexport const SILENT_LOGGER: Logger = createSilentLogger('silent');\n\n/**\n * Check if logging is explicitly enabled via environment variable\n */\nconst isLoggingEnabled = (): boolean => {\n return process.env.RIOTPROMPT_LOGGING === 'true' ||\n process.env.DEBUG?.includes('riotprompt') ||\n process.env.NODE_ENV === 'development';\n};\n\n/**\n * Create a Logger from a Fjell logger instance\n */\nfunction createLoggerFromFjell(fjellLogger: ReturnType<typeof LibLogger.get>, name: string): Logger {\n return {\n name,\n debug: (message: string, ...args: any[]) => fjellLogger.debug(message, ...args),\n info: (message: string, ...args: any[]) => fjellLogger.info(message, ...args),\n warn: (message: string, ...args: any[]) => fjellLogger.warning(message, ...args),\n error: (message: string, ...args: any[]) => fjellLogger.error(message, ...args),\n verbose: (message: string, ...args: any[]) => fjellLogger.debug(message, ...args), // Map to debug\n silly: (message: string, ...args: any[]) => fjellLogger.debug(message, ...args), // Map to debug\n get: (...components: string[]) => {\n const childLogger = fjellLogger.get(...components);\n return createLoggerFromFjell(childLogger, `${name}:${components.join(':')}`);\n },\n };\n}\n\n/**\n * Fjell-backed logger with sensitive data masking\n * \n * Features:\n * - Automatic sensitive data masking (API keys, passwords, etc.)\n * - Circular reference protection\n * - Hierarchical component logging\n * - Correlation ID support\n */\nconst FJELL_LOGGER: Logger = {\n name: 'fjell',\n debug: (message: string, ...args: any[]) => LibLogger.debug(message, ...args),\n info: (message: string, ...args: any[]) => LibLogger.info(message, ...args),\n warn: (message: string, ...args: any[]) => LibLogger.warning(message, ...args),\n error: (message: string, ...args: any[]) => LibLogger.error(message, ...args),\n verbose: (message: string, ...args: any[]) => LibLogger.debug(message, ...args),\n silly: (message: string, ...args: any[]) => LibLogger.debug(message, ...args),\n get: (...components: string[]) => {\n const childLogger = LibLogger.get(...components);\n return createLoggerFromFjell(childLogger, components.join(':'));\n },\n};\n\n/**\n * Default logger - silent by default to prevent information disclosure\n * \n * Enable logging by setting one of:\n * - RIOTPROMPT_LOGGING=true\n * - DEBUG=*riotprompt*\n * - NODE_ENV=development\n * \n * @example\n * ```typescript\n * import { DEFAULT_LOGGER } from '@theunwalked/riotprompt';\n * \n * const logger = DEFAULT_LOGGER.get?.('MyComponent') ?? DEFAULT_LOGGER;\n * logger.info('Processing request', { userId: 123 });\n * ```\n */\nexport const DEFAULT_LOGGER: Logger = isLoggingEnabled() ? FJELL_LOGGER : SILENT_LOGGER;\n\n/**\n * Wrap an existing logger with library prefix\n * \n * @param toWrap - Logger to wrap\n * @param name - Optional component name\n * @returns Wrapped logger with library prefix\n * \n * @example\n * ```typescript\n * const myLogger = wrapLogger(customLogger, 'MyComponent');\n * myLogger.info('Hello'); // [riotprompt] [MyComponent]: Hello\n * ```\n */\nexport const wrapLogger = (toWrap: Logger, name?: string): Logger => {\n const requiredMethods: (keyof Logger)[] = ['debug', 'info', 'warn', 'error', 'verbose', 'silly'];\n const missingMethods = requiredMethods.filter(method => typeof toWrap[method] !== 'function');\n\n if (missingMethods.length > 0) {\n throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);\n }\n\n const log = (level: keyof Logger, message: string, ...args: any[]) => {\n message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;\n\n if (level === 'debug') toWrap.debug(message, ...args);\n else if (level === 'info') toWrap.info(message, ...args);\n else if (level === 'warn') toWrap.warn(message, ...args);\n else if (level === 'error') toWrap.error(message, ...args);\n else if (level === 'verbose') toWrap.verbose(message, ...args);\n else if (level === 'silly') toWrap.silly(message, ...args);\n };\n\n return {\n name: name || 'wrapped',\n debug: (message: string, ...args: any[]) => log('debug', message, ...args),\n info: (message: string, ...args: any[]) => log('info', message, ...args),\n warn: (message: string, ...args: any[]) => log('warn', message, ...args),\n error: (message: string, ...args: any[]) => log('error', message, ...args),\n verbose: (message: string, ...args: any[]) => log('verbose', message, ...args),\n silly: (message: string, ...args: any[]) => log('silly', message, ...args),\n get: (...components: string[]) => wrapLogger(toWrap, name ? `${name}:${components.join(':')}` : components.join(':')),\n };\n};\n\n/**\n * Create a console-based fallback logger (for environments without Fjell config)\n * \n * @param name - Logger name\n * @returns Console-based logger\n */\nexport function createConsoleLogger(name: string = 'console'): Logger {\n return {\n name,\n debug: (message: string, ...args: any[]) => console.debug(`[DEBUG] [${name}]`, message, ...args),\n info: (message: string, ...args: any[]) => console.info(`[INFO] [${name}]`, message, ...args),\n warn: (message: string, ...args: any[]) => console.warn(`[WARN] [${name}]`, message, ...args),\n error: (message: string, ...args: any[]) => console.error(`[ERROR] [${name}]`, message, ...args),\n verbose: () => {},\n silly: () => {},\n get: (...components: string[]) => createConsoleLogger(`${name}:${components.join(':')}`),\n };\n}\n"],"names":["LibLogger","Logging","getLogger","createSilentLogger","name","debug","info","warn","error","verbose","silly","get","components","join","SILENT_LOGGER","isLoggingEnabled","process","env","RIOTPROMPT_LOGGING","DEBUG","includes","NODE_ENV","createLoggerFromFjell","fjellLogger","message","args","warning","childLogger","FJELL_LOGGER","DEFAULT_LOGGER","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","log","level","LIBRARY_NAME","createConsoleLogger","console"],"mappings":";;;AA0BA;AACA,MAAMA,SAAAA,GAAYC,OAAAA,CAAQC,SAAS,CAAC,yBAAA,CAAA;AAEpC;;IAGA,SAASC,mBAAmBC,IAAY,EAAA;IACpC,OAAO;AACHA,QAAAA,IAAAA;AACAC,QAAAA,KAAAA,EAAO,IAAA,CAAO,CAAA;AACdC,QAAAA,IAAAA,EAAM,IAAA,CAAO,CAAA;AACbC,QAAAA,IAAAA,EAAM,IAAA,CAAO,CAAA;AACbC,QAAAA,KAAAA,EAAO,IAAA,CAAO,CAAA;AACdC,QAAAA,OAAAA,EAAS,IAAA,CAAO,CAAA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,CAAC,EAAEoB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AACxFjB,QAAAA,KAAAA,EAAO,CAACgB,OAAAA,EAAiB,GAAGC,IAAAA,GAAgBiB,QAAQlC,KAAK,CAAC,CAAC,SAAS,EAAEJ,IAAAA,CAAK,CAAC,CAAC,EAAEoB,OAAAA,EAAAA,GAAYC,IAAAA,CAAAA;AAC3FhB,QAAAA,OAAAA,EAAS,IAAA,CAAO,CAAA;AAChBC,QAAAA,KAAAA,EAAO,IAAA,CAAO,CAAA;QACdC,GAAAA,EAAK,CAAC,GAAGC,UAAAA,GAAyB6B,mBAAAA,CAAoB,CAAA,EAAGrC,IAAAA,CAAK,CAAC,EAAEQ,UAAAA,CAAWC,IAAI,CAAC,GAAA,CAAA,CAAA,CAAM;AAC3F,KAAA;AACJ;;;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MaskingConfig } from '@fjell/logging';
|
|
2
|
+
import { Logger } from './logger';
|
|
3
|
+
export declare const RiotPromptLogger: import('@fjell/logging').Logger;
|
|
4
|
+
/**
|
|
5
|
+
* Secure logging configuration options
|
|
6
|
+
*/
|
|
7
|
+
export interface SecureLoggingOptions {
|
|
8
|
+
/** Enable masking (defaults to true in production) */
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
/** Mask API keys (OpenAI, Anthropic, AWS, etc.) */
|
|
11
|
+
maskApiKeys?: boolean;
|
|
12
|
+
/** Mask passwords and secrets */
|
|
13
|
+
maskPasswords?: boolean;
|
|
14
|
+
/** Mask email addresses */
|
|
15
|
+
maskEmails?: boolean;
|
|
16
|
+
/** Mask Social Security Numbers */
|
|
17
|
+
maskSSNs?: boolean;
|
|
18
|
+
/** Mask private keys */
|
|
19
|
+
maskPrivateKeys?: boolean;
|
|
20
|
+
/** Mask JWT tokens */
|
|
21
|
+
maskJWTs?: boolean;
|
|
22
|
+
/** Mask large base64 blobs */
|
|
23
|
+
maskBase64Blobs?: boolean;
|
|
24
|
+
/** Maximum object depth for masking */
|
|
25
|
+
maxDepth?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Configure secure logging defaults for RiotPrompt
|
|
29
|
+
*
|
|
30
|
+
* @param options - Configuration options
|
|
31
|
+
* @returns MaskingConfig for use with maskWithConfig
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const config = configureSecureLogging({ maskEmails: false });
|
|
36
|
+
* const masked = maskWithConfig(content, config);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function configureSecureLogging(options?: SecureLoggingOptions): MaskingConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Default masking configuration with all protections enabled
|
|
42
|
+
*/
|
|
43
|
+
export declare const DEFAULT_MASKING_CONFIG: MaskingConfig;
|
|
44
|
+
/**
|
|
45
|
+
* Permissive masking configuration for development/debugging
|
|
46
|
+
*/
|
|
47
|
+
export declare const DEVELOPMENT_MASKING_CONFIG: MaskingConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Mask a string with default secure settings
|
|
50
|
+
*
|
|
51
|
+
* @param content - Content to mask
|
|
52
|
+
* @param config - Optional custom masking config
|
|
53
|
+
* @returns Masked content
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const masked = maskSensitive('API key: sk-abc123xyz');
|
|
58
|
+
* // Output: "API key: ****"
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function maskSensitive(content: string, config?: MaskingConfig): string;
|
|
62
|
+
/**
|
|
63
|
+
* Execute a function with a correlated logger for request tracking
|
|
64
|
+
*
|
|
65
|
+
* @param fn - Function to execute with correlated logger
|
|
66
|
+
* @param baseLogger - Base logger to correlate
|
|
67
|
+
* @returns Promise with result and correlation ID
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const { result, correlationId } = await executeWithCorrelation(
|
|
72
|
+
* async (logger) => {
|
|
73
|
+
* logger.info('Processing request');
|
|
74
|
+
* return processData();
|
|
75
|
+
* },
|
|
76
|
+
* myLogger
|
|
77
|
+
* );
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function executeWithCorrelation<T>(fn: (logger: Logger, correlationId: string) => Promise<T>, baseLogger: Logger): Promise<{
|
|
81
|
+
result: T;
|
|
82
|
+
correlationId: string;
|
|
83
|
+
}>;
|
|
84
|
+
export { maskWithConfig, createCorrelatedLogger, generateCorrelationId, type MaskingConfig } from '@fjell/logging';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import Logging, { generateCorrelationId, maskWithConfig } from '@fjell/logging';
|
|
2
|
+
export { createCorrelatedLogger, generateCorrelationId, maskWithConfig } from '@fjell/logging';
|
|
3
|
+
|
|
4
|
+
// Get library logger
|
|
5
|
+
const RiotPromptLogger = Logging.getLogger('@theunwalked/riotprompt');
|
|
6
|
+
/**
|
|
7
|
+
* Configure secure logging defaults for RiotPrompt
|
|
8
|
+
*
|
|
9
|
+
* @param options - Configuration options
|
|
10
|
+
* @returns MaskingConfig for use with maskWithConfig
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const config = configureSecureLogging({ maskEmails: false });
|
|
15
|
+
* const masked = maskWithConfig(content, config);
|
|
16
|
+
* ```
|
|
17
|
+
*/ function configureSecureLogging(options = {}) {
|
|
18
|
+
var _options_enabled, _options_maskApiKeys, _options_maskPasswords, _options_maskEmails, _options_maskSSNs, _options_maskPrivateKeys, _options_maskJWTs, _options_maskBase64Blobs, _options_maxDepth;
|
|
19
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
20
|
+
return {
|
|
21
|
+
enabled: (_options_enabled = options.enabled) !== null && _options_enabled !== void 0 ? _options_enabled : isProduction,
|
|
22
|
+
maskApiKeys: (_options_maskApiKeys = options.maskApiKeys) !== null && _options_maskApiKeys !== void 0 ? _options_maskApiKeys : true,
|
|
23
|
+
maskPasswords: (_options_maskPasswords = options.maskPasswords) !== null && _options_maskPasswords !== void 0 ? _options_maskPasswords : true,
|
|
24
|
+
maskEmails: (_options_maskEmails = options.maskEmails) !== null && _options_maskEmails !== void 0 ? _options_maskEmails : true,
|
|
25
|
+
maskSSNs: (_options_maskSSNs = options.maskSSNs) !== null && _options_maskSSNs !== void 0 ? _options_maskSSNs : true,
|
|
26
|
+
maskPrivateKeys: (_options_maskPrivateKeys = options.maskPrivateKeys) !== null && _options_maskPrivateKeys !== void 0 ? _options_maskPrivateKeys : true,
|
|
27
|
+
maskJWTs: (_options_maskJWTs = options.maskJWTs) !== null && _options_maskJWTs !== void 0 ? _options_maskJWTs : true,
|
|
28
|
+
maskBase64Blobs: (_options_maskBase64Blobs = options.maskBase64Blobs) !== null && _options_maskBase64Blobs !== void 0 ? _options_maskBase64Blobs : true,
|
|
29
|
+
maskBearerTokens: true,
|
|
30
|
+
maskGenericSecrets: true,
|
|
31
|
+
maxDepth: (_options_maxDepth = options.maxDepth) !== null && _options_maxDepth !== void 0 ? _options_maxDepth : 8
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Default masking configuration with all protections enabled
|
|
36
|
+
*/ const DEFAULT_MASKING_CONFIG = {
|
|
37
|
+
enabled: true,
|
|
38
|
+
maskApiKeys: true,
|
|
39
|
+
maskPasswords: true,
|
|
40
|
+
maskEmails: true,
|
|
41
|
+
maskSSNs: true,
|
|
42
|
+
maskPrivateKeys: true,
|
|
43
|
+
maskJWTs: true,
|
|
44
|
+
maskBase64Blobs: true,
|
|
45
|
+
maskBearerTokens: true,
|
|
46
|
+
maskGenericSecrets: true,
|
|
47
|
+
maxDepth: 8
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Permissive masking configuration for development/debugging
|
|
51
|
+
*/ const DEVELOPMENT_MASKING_CONFIG = {
|
|
52
|
+
enabled: false,
|
|
53
|
+
maskApiKeys: false,
|
|
54
|
+
maskPasswords: false,
|
|
55
|
+
maskEmails: false,
|
|
56
|
+
maskSSNs: false,
|
|
57
|
+
maskPrivateKeys: false,
|
|
58
|
+
maskJWTs: false,
|
|
59
|
+
maskBase64Blobs: false,
|
|
60
|
+
maskBearerTokens: false,
|
|
61
|
+
maskGenericSecrets: false,
|
|
62
|
+
maxDepth: 8
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Mask a string with default secure settings
|
|
66
|
+
*
|
|
67
|
+
* @param content - Content to mask
|
|
68
|
+
* @param config - Optional custom masking config
|
|
69
|
+
* @returns Masked content
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const masked = maskSensitive('API key: sk-abc123xyz');
|
|
74
|
+
* // Output: "API key: ****"
|
|
75
|
+
* ```
|
|
76
|
+
*/ function maskSensitive(content, config) {
|
|
77
|
+
return maskWithConfig(content, config !== null && config !== void 0 ? config : DEFAULT_MASKING_CONFIG);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Execute a function with a correlated logger for request tracking
|
|
81
|
+
*
|
|
82
|
+
* @param fn - Function to execute with correlated logger
|
|
83
|
+
* @param baseLogger - Base logger to correlate
|
|
84
|
+
* @returns Promise with result and correlation ID
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const { result, correlationId } = await executeWithCorrelation(
|
|
89
|
+
* async (logger) => {
|
|
90
|
+
* logger.info('Processing request');
|
|
91
|
+
* return processData();
|
|
92
|
+
* },
|
|
93
|
+
* myLogger
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*/ async function executeWithCorrelation(fn, baseLogger) {
|
|
97
|
+
const correlationId = generateCorrelationId();
|
|
98
|
+
// Create a correlated wrapper that matches our Logger interface
|
|
99
|
+
const correlatedLogger = {
|
|
100
|
+
name: `${baseLogger.name}:${correlationId}`,
|
|
101
|
+
debug: (msg, ...args)=>baseLogger.debug(`[${correlationId}] ${msg}`, ...args),
|
|
102
|
+
info: (msg, ...args)=>baseLogger.info(`[${correlationId}] ${msg}`, ...args),
|
|
103
|
+
warn: (msg, ...args)=>baseLogger.warn(`[${correlationId}] ${msg}`, ...args),
|
|
104
|
+
error: (msg, ...args)=>baseLogger.error(`[${correlationId}] ${msg}`, ...args),
|
|
105
|
+
verbose: (msg, ...args)=>baseLogger.verbose(`[${correlationId}] ${msg}`, ...args),
|
|
106
|
+
silly: (msg, ...args)=>baseLogger.silly(`[${correlationId}] ${msg}`, ...args)
|
|
107
|
+
};
|
|
108
|
+
const result = await fn(correlatedLogger, correlationId);
|
|
109
|
+
return {
|
|
110
|
+
result,
|
|
111
|
+
correlationId
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { DEFAULT_MASKING_CONFIG, DEVELOPMENT_MASKING_CONFIG, RiotPromptLogger, configureSecureLogging, executeWithCorrelation, maskSensitive };
|
|
116
|
+
//# sourceMappingURL=logging-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging-config.js","sources":["../src/logging-config.ts"],"sourcesContent":["/**\n * RiotPrompt - Secure Logging Configuration\n * \n * Integrates @fjell/logging for comprehensive sensitive data masking\n * and structured logging across the library.\n */\n\nimport Logging, { \n maskWithConfig, \n type MaskingConfig,\n generateCorrelationId \n} from '@fjell/logging';\nimport type { Logger } from './logger';\n\n// Get library logger\nexport const RiotPromptLogger = Logging.getLogger('@theunwalked/riotprompt');\n\n/**\n * Secure logging configuration options\n */\nexport interface SecureLoggingOptions {\n /** Enable masking (defaults to true in production) */\n enabled?: boolean;\n /** Mask API keys (OpenAI, Anthropic, AWS, etc.) */\n maskApiKeys?: boolean;\n /** Mask passwords and secrets */\n maskPasswords?: boolean;\n /** Mask email addresses */\n maskEmails?: boolean;\n /** Mask Social Security Numbers */\n maskSSNs?: boolean;\n /** Mask private keys */\n maskPrivateKeys?: boolean;\n /** Mask JWT tokens */\n maskJWTs?: boolean;\n /** Mask large base64 blobs */\n maskBase64Blobs?: boolean;\n /** Maximum object depth for masking */\n maxDepth?: number;\n}\n\n/**\n * Configure secure logging defaults for RiotPrompt\n * \n * @param options - Configuration options\n * @returns MaskingConfig for use with maskWithConfig\n * \n * @example\n * ```typescript\n * const config = configureSecureLogging({ maskEmails: false });\n * const masked = maskWithConfig(content, config);\n * ```\n */\nexport function configureSecureLogging(options: SecureLoggingOptions = {}): MaskingConfig {\n const isProduction = process.env.NODE_ENV === 'production';\n\n return {\n enabled: options.enabled ?? isProduction,\n maskApiKeys: options.maskApiKeys ?? true,\n maskPasswords: options.maskPasswords ?? true,\n maskEmails: options.maskEmails ?? true,\n maskSSNs: options.maskSSNs ?? true,\n maskPrivateKeys: options.maskPrivateKeys ?? true,\n maskJWTs: options.maskJWTs ?? true,\n maskBase64Blobs: options.maskBase64Blobs ?? true,\n maskBearerTokens: true,\n maskGenericSecrets: true,\n maxDepth: options.maxDepth ?? 8,\n };\n}\n\n/**\n * Default masking configuration with all protections enabled\n */\nexport const DEFAULT_MASKING_CONFIG: MaskingConfig = {\n enabled: true,\n maskApiKeys: true,\n maskPasswords: true,\n maskEmails: true,\n maskSSNs: true,\n maskPrivateKeys: true,\n maskJWTs: true,\n maskBase64Blobs: true,\n maskBearerTokens: true,\n maskGenericSecrets: true,\n maxDepth: 8,\n};\n\n/**\n * Permissive masking configuration for development/debugging\n */\nexport const DEVELOPMENT_MASKING_CONFIG: MaskingConfig = {\n enabled: false,\n maskApiKeys: false,\n maskPasswords: false,\n maskEmails: false,\n maskSSNs: false,\n maskPrivateKeys: false,\n maskJWTs: false,\n maskBase64Blobs: false,\n maskBearerTokens: false,\n maskGenericSecrets: false,\n maxDepth: 8,\n};\n\n/**\n * Mask a string with default secure settings\n * \n * @param content - Content to mask\n * @param config - Optional custom masking config\n * @returns Masked content\n * \n * @example\n * ```typescript\n * const masked = maskSensitive('API key: sk-abc123xyz');\n * // Output: \"API key: ****\"\n * ```\n */\nexport function maskSensitive(content: string, config?: MaskingConfig): string {\n return maskWithConfig(content, config ?? DEFAULT_MASKING_CONFIG);\n}\n\n/**\n * Execute a function with a correlated logger for request tracking\n * \n * @param fn - Function to execute with correlated logger\n * @param baseLogger - Base logger to correlate\n * @returns Promise with result and correlation ID\n * \n * @example\n * ```typescript\n * const { result, correlationId } = await executeWithCorrelation(\n * async (logger) => {\n * logger.info('Processing request');\n * return processData();\n * },\n * myLogger\n * );\n * ```\n */\nexport async function executeWithCorrelation<T>(\n fn: (logger: Logger, correlationId: string) => Promise<T>,\n baseLogger: Logger,\n): Promise<{ result: T; correlationId: string }> {\n const correlationId = generateCorrelationId();\n \n // Create a correlated wrapper that matches our Logger interface\n const correlatedLogger: Logger = {\n name: `${baseLogger.name}:${correlationId}`,\n debug: (msg, ...args) => baseLogger.debug(`[${correlationId}] ${msg}`, ...args),\n info: (msg, ...args) => baseLogger.info(`[${correlationId}] ${msg}`, ...args),\n warn: (msg, ...args) => baseLogger.warn(`[${correlationId}] ${msg}`, ...args),\n error: (msg, ...args) => baseLogger.error(`[${correlationId}] ${msg}`, ...args),\n verbose: (msg, ...args) => baseLogger.verbose(`[${correlationId}] ${msg}`, ...args),\n silly: (msg, ...args) => baseLogger.silly(`[${correlationId}] ${msg}`, ...args),\n };\n\n const result = await fn(correlatedLogger, correlationId);\n return { result, correlationId };\n}\n\n// Re-export useful Fjell utilities\nexport { \n maskWithConfig, \n createCorrelatedLogger, \n generateCorrelationId,\n type MaskingConfig \n} from '@fjell/logging';\n\n"],"names":["RiotPromptLogger","Logging","getLogger","configureSecureLogging","options","isProduction","process","env","NODE_ENV","enabled","maskApiKeys","maskPasswords","maskEmails","maskSSNs","maskPrivateKeys","maskJWTs","maskBase64Blobs","maskBearerTokens","maskGenericSecrets","maxDepth","DEFAULT_MASKING_CONFIG","DEVELOPMENT_MASKING_CONFIG","maskSensitive","content","config","maskWithConfig","executeWithCorrelation","fn","baseLogger","correlationId","generateCorrelationId","correlatedLogger","name","debug","msg","args","info","warn","error","verbose","silly","result"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AA,EAAkBF,aAAAA,CAAAA;IAC1C,OAAO;AAAEY,QAAAA,MAAAA;AAAQZ,QAAAA;AAAc,KAAA;AACnC;;;;"}
|
package/dist/message-builder.js
CHANGED
package/dist/model-config.js
CHANGED
|
@@ -202,5 +202,5 @@ function getModelFamily(model) {
|
|
|
202
202
|
getModelRegistry().register(config);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
export { ModelRegistry, configureModel,
|
|
205
|
+
export { ModelRegistry, configureModel, getEncoding, getModelFamily, getModelRegistry, getPersonaRole, resetModelRegistry, supportsToolCalls };
|
|
206
206
|
//# sourceMappingURL=model-config.js.map
|
package/dist/override.js
CHANGED
|
@@ -4,18 +4,24 @@ import { ParametersSchema } from './items/parameters.js';
|
|
|
4
4
|
import { SectionOptionsSchema } from './items/section.js';
|
|
5
5
|
import { DEFAULT_LOGGER, wrapLogger } from './logger.js';
|
|
6
6
|
import './items/weighted.js';
|
|
7
|
-
import { create as create$
|
|
7
|
+
import { create as create$2 } from './formatter.js';
|
|
8
8
|
import { create as create$3 } from './parser.js';
|
|
9
9
|
import './loader.js';
|
|
10
10
|
import './builder.js';
|
|
11
11
|
import './recipes.js';
|
|
12
12
|
import './conversation.js';
|
|
13
13
|
import 'tiktoken';
|
|
14
|
+
import './logging-config.js';
|
|
14
15
|
import './tools.js';
|
|
15
16
|
import 'openai';
|
|
16
17
|
import '@anthropic-ai/sdk';
|
|
17
18
|
import '@google/generative-ai';
|
|
18
|
-
import
|
|
19
|
+
import './security/types.js';
|
|
20
|
+
import './security/defaults.js';
|
|
21
|
+
import './security/serialization-schemas.js';
|
|
22
|
+
import '@theunwalked/pressurelid';
|
|
23
|
+
import '@theunwalked/spotclean';
|
|
24
|
+
import { create as create$1 } from './util/storage.js';
|
|
19
25
|
|
|
20
26
|
const OptionsSchema = z.object({
|
|
21
27
|
logger: z.any().optional().default(DEFAULT_LOGGER),
|
|
@@ -29,7 +35,7 @@ const create = (overrideOptions = {})=>{
|
|
|
29
35
|
const options = OptionsSchema.parse(overrideOptions);
|
|
30
36
|
const parameters = options.parameters;
|
|
31
37
|
const logger = wrapLogger(options === null || options === void 0 ? void 0 : options.logger, 'Override');
|
|
32
|
-
const storage = create$
|
|
38
|
+
const storage = create$1({
|
|
33
39
|
log: logger.debug
|
|
34
40
|
});
|
|
35
41
|
const loadOptions = (sectionOptions = {})=>{
|
|
@@ -116,7 +122,7 @@ const create = (overrideOptions = {})=>{
|
|
|
116
122
|
logger.silly('Append found, adding to content from file %s', append);
|
|
117
123
|
finalSection = finalSection.append(append);
|
|
118
124
|
}
|
|
119
|
-
const formatter$1 = create$
|
|
125
|
+
const formatter$1 = create$2({
|
|
120
126
|
logger
|
|
121
127
|
});
|
|
122
128
|
logger.silly('Final section %s:\n\n%s\n\n', logger.name, formatter$1.format(finalSection));
|