@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.
Files changed (73) 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.cjs → cli.js} +658 -216
  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/dist/util/storage.js.map +1 -1
  67. package/guide/index.md +2 -0
  68. package/guide/integration.md +1109 -0
  69. package/guide/security.md +237 -0
  70. package/package.json +23 -17
  71. package/vite.config.cli.ts +9 -18
  72. package/dist/riotprompt.cjs +0 -6169
  73. package/dist/riotprompt.cjs.map +0 -1
@@ -0,0 +1,123 @@
1
+ import { TimeoutConfig } from './types';
2
+ import { SecurityAuditLogger } from './audit-logger';
3
+ /**
4
+ * Custom timeout error for identification
5
+ */
6
+ export declare class TimeoutError extends Error {
7
+ readonly isTimeout = true;
8
+ readonly operation: string;
9
+ readonly timeoutMs: number;
10
+ constructor(message: string, operation?: string, timeoutMs?: number);
11
+ }
12
+ /**
13
+ * TimeoutGuard provides timeout protection for async operations.
14
+ *
15
+ * Features:
16
+ * - Configurable timeouts per operation type
17
+ * - AbortController integration
18
+ * - Audit logging of timeouts
19
+ * - Custom TimeoutError for identification
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const guard = new TimeoutGuard({ llmTimeout: 60000 });
24
+ *
25
+ * // Wrap an LLM call
26
+ * const response = await guard.withLLMTimeout(
27
+ * client.chat.completions.create({ ... }),
28
+ * 'openai-chat'
29
+ * );
30
+ *
31
+ * // Wrap any promise
32
+ * const result = await guard.withTimeout(
33
+ * fetchData(),
34
+ * 5000,
35
+ * 'fetch-data'
36
+ * );
37
+ * ```
38
+ */
39
+ export declare class TimeoutGuard {
40
+ private config;
41
+ private auditLogger;
42
+ constructor(config?: Partial<TimeoutConfig>, auditLogger?: SecurityAuditLogger);
43
+ /**
44
+ * Wrap a promise with timeout
45
+ *
46
+ * @param promise - The promise to wrap
47
+ * @param timeoutMs - Timeout in milliseconds
48
+ * @param operation - Operation name for logging
49
+ * @returns The result of the promise
50
+ * @throws TimeoutError if the operation times out
51
+ */
52
+ withTimeout<T>(promise: Promise<T>, timeoutMs: number, operation: string): Promise<T>;
53
+ /**
54
+ * Wrap an LLM call with appropriate timeout
55
+ *
56
+ * @param promise - The LLM call promise
57
+ * @param operation - Operation name for logging
58
+ * @returns The result of the LLM call
59
+ */
60
+ withLLMTimeout<T>(promise: Promise<T>, operation?: string): Promise<T>;
61
+ /**
62
+ * Wrap a tool execution with appropriate timeout
63
+ *
64
+ * @param promise - The tool execution promise
65
+ * @param toolName - Name of the tool
66
+ * @returns The result of the tool execution
67
+ */
68
+ withToolTimeout<T>(promise: Promise<T>, toolName: string): Promise<T>;
69
+ /**
70
+ * Wrap a file operation with appropriate timeout
71
+ *
72
+ * @param promise - The file operation promise
73
+ * @param operation - Operation name for logging
74
+ * @returns The result of the file operation
75
+ */
76
+ withFileTimeout<T>(promise: Promise<T>, operation?: string): Promise<T>;
77
+ /**
78
+ * Create an AbortController with timeout
79
+ *
80
+ * @param timeoutMs - Timeout in milliseconds
81
+ * @param operation - Operation name for logging
82
+ * @returns AbortController that will abort after timeout
83
+ */
84
+ createAbortController(timeoutMs: number, operation: string): {
85
+ controller: AbortController;
86
+ cleanup: () => void;
87
+ };
88
+ /**
89
+ * Get timeout for a specific operation type
90
+ *
91
+ * @param type - The operation type
92
+ * @returns Timeout in milliseconds
93
+ */
94
+ getTimeout(type: 'default' | 'llm' | 'tool' | 'file'): number;
95
+ /**
96
+ * Check if timeout protection is enabled
97
+ */
98
+ isEnabled(): boolean;
99
+ /**
100
+ * Enable or disable timeout protection
101
+ */
102
+ setEnabled(enabled: boolean): void;
103
+ /**
104
+ * Get the current configuration
105
+ */
106
+ getConfig(): TimeoutConfig;
107
+ }
108
+ /**
109
+ * Check if an error is a TimeoutError
110
+ */
111
+ export declare function isTimeoutError(error: unknown): error is TimeoutError;
112
+ /**
113
+ * Get the global TimeoutGuard instance
114
+ */
115
+ export declare function getTimeoutGuard(): TimeoutGuard;
116
+ /**
117
+ * Configure the global TimeoutGuard
118
+ */
119
+ export declare function configureTimeoutGuard(config: Partial<TimeoutConfig>): void;
120
+ /**
121
+ * Reset the global TimeoutGuard
122
+ */
123
+ export declare function resetTimeoutGuard(): void;
@@ -0,0 +1,223 @@
1
+ import { getAuditLogger } from './audit-logger.js';
2
+
3
+ /**
4
+ * RiotPrompt - Timeout Guard
5
+ *
6
+ * Implements request timeouts for LLM calls and other external operations
7
+ * to prevent resource exhaustion and improve reliability.
8
+ */ function _define_property(obj, key, value) {
9
+ if (key in obj) {
10
+ Object.defineProperty(obj, key, {
11
+ value: value,
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true
15
+ });
16
+ } else {
17
+ obj[key] = value;
18
+ }
19
+ return obj;
20
+ }
21
+ /**
22
+ * Default timeout configuration
23
+ */ const DEFAULT_CONFIG = {
24
+ enabled: true,
25
+ defaultTimeout: 30000,
26
+ llmTimeout: 120000,
27
+ toolTimeout: 30000,
28
+ fileTimeout: 5000
29
+ };
30
+ /**
31
+ * Custom timeout error for identification
32
+ */ class TimeoutError extends Error {
33
+ constructor(message, operation = 'unknown', timeoutMs = 0){
34
+ super(message), _define_property(this, "isTimeout", true), _define_property(this, "operation", void 0), _define_property(this, "timeoutMs", void 0);
35
+ this.name = 'TimeoutError';
36
+ this.operation = operation;
37
+ this.timeoutMs = timeoutMs;
38
+ }
39
+ }
40
+ /**
41
+ * TimeoutGuard provides timeout protection for async operations.
42
+ *
43
+ * Features:
44
+ * - Configurable timeouts per operation type
45
+ * - AbortController integration
46
+ * - Audit logging of timeouts
47
+ * - Custom TimeoutError for identification
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const guard = new TimeoutGuard({ llmTimeout: 60000 });
52
+ *
53
+ * // Wrap an LLM call
54
+ * const response = await guard.withLLMTimeout(
55
+ * client.chat.completions.create({ ... }),
56
+ * 'openai-chat'
57
+ * );
58
+ *
59
+ * // Wrap any promise
60
+ * const result = await guard.withTimeout(
61
+ * fetchData(),
62
+ * 5000,
63
+ * 'fetch-data'
64
+ * );
65
+ * ```
66
+ */ class TimeoutGuard {
67
+ /**
68
+ * Wrap a promise with timeout
69
+ *
70
+ * @param promise - The promise to wrap
71
+ * @param timeoutMs - Timeout in milliseconds
72
+ * @param operation - Operation name for logging
73
+ * @returns The result of the promise
74
+ * @throws TimeoutError if the operation times out
75
+ */ async withTimeout(promise, timeoutMs, operation) {
76
+ if (!this.config.enabled || timeoutMs <= 0) {
77
+ return promise;
78
+ }
79
+ return new Promise((resolve, reject)=>{
80
+ let settled = false;
81
+ const timeoutId = setTimeout(()=>{
82
+ if (!settled) {
83
+ settled = true;
84
+ this.auditLogger.requestTimeout(operation, timeoutMs);
85
+ reject(new TimeoutError(`Operation "${operation}" timed out after ${timeoutMs}ms`, operation, timeoutMs));
86
+ }
87
+ }, timeoutMs);
88
+ promise.then((result)=>{
89
+ if (!settled) {
90
+ settled = true;
91
+ clearTimeout(timeoutId);
92
+ resolve(result);
93
+ }
94
+ }).catch((error)=>{
95
+ if (!settled) {
96
+ settled = true;
97
+ clearTimeout(timeoutId);
98
+ reject(error);
99
+ }
100
+ });
101
+ });
102
+ }
103
+ /**
104
+ * Wrap an LLM call with appropriate timeout
105
+ *
106
+ * @param promise - The LLM call promise
107
+ * @param operation - Operation name for logging
108
+ * @returns The result of the LLM call
109
+ */ async withLLMTimeout(promise, operation = 'llm-call') {
110
+ return this.withTimeout(promise, this.config.llmTimeout, operation);
111
+ }
112
+ /**
113
+ * Wrap a tool execution with appropriate timeout
114
+ *
115
+ * @param promise - The tool execution promise
116
+ * @param toolName - Name of the tool
117
+ * @returns The result of the tool execution
118
+ */ async withToolTimeout(promise, toolName) {
119
+ return this.withTimeout(promise, this.config.toolTimeout, `tool:${toolName}`);
120
+ }
121
+ /**
122
+ * Wrap a file operation with appropriate timeout
123
+ *
124
+ * @param promise - The file operation promise
125
+ * @param operation - Operation name for logging
126
+ * @returns The result of the file operation
127
+ */ async withFileTimeout(promise, operation = 'file-operation') {
128
+ return this.withTimeout(promise, this.config.fileTimeout, operation);
129
+ }
130
+ /**
131
+ * Create an AbortController with timeout
132
+ *
133
+ * @param timeoutMs - Timeout in milliseconds
134
+ * @param operation - Operation name for logging
135
+ * @returns AbortController that will abort after timeout
136
+ */ createAbortController(timeoutMs, operation) {
137
+ const controller = new AbortController();
138
+ const timeoutId = setTimeout(()=>{
139
+ if (!controller.signal.aborted) {
140
+ this.auditLogger.requestTimeout(operation, timeoutMs);
141
+ controller.abort(new TimeoutError(`Operation "${operation}" timed out`, operation, timeoutMs));
142
+ }
143
+ }, timeoutMs);
144
+ const cleanup = ()=>{
145
+ clearTimeout(timeoutId);
146
+ };
147
+ return {
148
+ controller,
149
+ cleanup
150
+ };
151
+ }
152
+ /**
153
+ * Get timeout for a specific operation type
154
+ *
155
+ * @param type - The operation type
156
+ * @returns Timeout in milliseconds
157
+ */ getTimeout(type) {
158
+ switch(type){
159
+ case 'llm':
160
+ return this.config.llmTimeout;
161
+ case 'tool':
162
+ return this.config.toolTimeout;
163
+ case 'file':
164
+ return this.config.fileTimeout;
165
+ default:
166
+ return this.config.defaultTimeout;
167
+ }
168
+ }
169
+ /**
170
+ * Check if timeout protection is enabled
171
+ */ isEnabled() {
172
+ return this.config.enabled;
173
+ }
174
+ /**
175
+ * Enable or disable timeout protection
176
+ */ setEnabled(enabled) {
177
+ this.config.enabled = enabled;
178
+ }
179
+ /**
180
+ * Get the current configuration
181
+ */ getConfig() {
182
+ return {
183
+ ...this.config
184
+ };
185
+ }
186
+ constructor(config = {}, auditLogger){
187
+ _define_property(this, "config", void 0);
188
+ _define_property(this, "auditLogger", void 0);
189
+ this.config = {
190
+ ...DEFAULT_CONFIG,
191
+ ...config
192
+ };
193
+ this.auditLogger = auditLogger || getAuditLogger();
194
+ }
195
+ }
196
+ /**
197
+ * Check if an error is a TimeoutError
198
+ */ function isTimeoutError(error) {
199
+ return error instanceof TimeoutError || error !== null && typeof error === 'object' && 'isTimeout' in error && error.isTimeout === true;
200
+ }
201
+ // Global instance
202
+ let globalTimeoutGuard = null;
203
+ /**
204
+ * Get the global TimeoutGuard instance
205
+ */ function getTimeoutGuard() {
206
+ if (!globalTimeoutGuard) {
207
+ globalTimeoutGuard = new TimeoutGuard();
208
+ }
209
+ return globalTimeoutGuard;
210
+ }
211
+ /**
212
+ * Configure the global TimeoutGuard
213
+ */ function configureTimeoutGuard(config) {
214
+ globalTimeoutGuard = new TimeoutGuard(config);
215
+ }
216
+ /**
217
+ * Reset the global TimeoutGuard
218
+ */ function resetTimeoutGuard() {
219
+ globalTimeoutGuard = null;
220
+ }
221
+
222
+ export { TimeoutError, TimeoutGuard, configureTimeoutGuard, getTimeoutGuard, isTimeoutError, resetTimeoutGuard };
223
+ //# sourceMappingURL=timeout-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout-guard.js","sources":["../../src/security/timeout-guard.ts"],"sourcesContent":["/**\n * RiotPrompt - Timeout Guard\n *\n * Implements request timeouts for LLM calls and other external operations\n * to prevent resource exhaustion and improve reliability.\n */\n\nimport { TimeoutConfig } from './types';\nimport { getAuditLogger, SecurityAuditLogger } from './audit-logger';\n\n/**\n * Default timeout configuration\n */\nconst DEFAULT_CONFIG: TimeoutConfig = {\n enabled: true,\n defaultTimeout: 30000, // 30 seconds\n llmTimeout: 120000, // 2 minutes\n toolTimeout: 30000, // 30 seconds\n fileTimeout: 5000, // 5 seconds\n};\n\n/**\n * Custom timeout error for identification\n */\nexport class TimeoutError extends Error {\n readonly isTimeout = true;\n readonly operation: string;\n readonly timeoutMs: number;\n\n constructor(message: string, operation: string = 'unknown', timeoutMs: number = 0) {\n super(message);\n this.name = 'TimeoutError';\n this.operation = operation;\n this.timeoutMs = timeoutMs;\n }\n}\n\n/**\n * TimeoutGuard provides timeout protection for async operations.\n *\n * Features:\n * - Configurable timeouts per operation type\n * - AbortController integration\n * - Audit logging of timeouts\n * - Custom TimeoutError for identification\n *\n * @example\n * ```typescript\n * const guard = new TimeoutGuard({ llmTimeout: 60000 });\n *\n * // Wrap an LLM call\n * const response = await guard.withLLMTimeout(\n * client.chat.completions.create({ ... }),\n * 'openai-chat'\n * );\n *\n * // Wrap any promise\n * const result = await guard.withTimeout(\n * fetchData(),\n * 5000,\n * 'fetch-data'\n * );\n * ```\n */\nexport class TimeoutGuard {\n private config: TimeoutConfig;\n private auditLogger: SecurityAuditLogger;\n\n constructor(config: Partial<TimeoutConfig> = {}, auditLogger?: SecurityAuditLogger) {\n this.config = { ...DEFAULT_CONFIG, ...config };\n this.auditLogger = auditLogger || getAuditLogger();\n }\n\n /**\n * Wrap a promise with timeout\n *\n * @param promise - The promise to wrap\n * @param timeoutMs - Timeout in milliseconds\n * @param operation - Operation name for logging\n * @returns The result of the promise\n * @throws TimeoutError if the operation times out\n */\n async withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n operation: string\n ): Promise<T> {\n if (!this.config.enabled || timeoutMs <= 0) {\n return promise;\n }\n\n return new Promise<T>((resolve, reject) => {\n let settled = false;\n\n const timeoutId = setTimeout(() => {\n if (!settled) {\n settled = true;\n this.auditLogger.requestTimeout(operation, timeoutMs);\n reject(new TimeoutError(\n `Operation \"${operation}\" timed out after ${timeoutMs}ms`,\n operation,\n timeoutMs\n ));\n }\n }, timeoutMs);\n\n promise\n .then((result) => {\n if (!settled) {\n settled = true;\n clearTimeout(timeoutId);\n resolve(result);\n }\n })\n .catch((error) => {\n if (!settled) {\n settled = true;\n clearTimeout(timeoutId);\n reject(error);\n }\n });\n });\n }\n\n /**\n * Wrap an LLM call with appropriate timeout\n *\n * @param promise - The LLM call promise\n * @param operation - Operation name for logging\n * @returns The result of the LLM call\n */\n async withLLMTimeout<T>(promise: Promise<T>, operation: string = 'llm-call'): Promise<T> {\n return this.withTimeout(promise, this.config.llmTimeout, operation);\n }\n\n /**\n * Wrap a tool execution with appropriate timeout\n *\n * @param promise - The tool execution promise\n * @param toolName - Name of the tool\n * @returns The result of the tool execution\n */\n async withToolTimeout<T>(promise: Promise<T>, toolName: string): Promise<T> {\n return this.withTimeout(promise, this.config.toolTimeout, `tool:${toolName}`);\n }\n\n /**\n * Wrap a file operation with appropriate timeout\n *\n * @param promise - The file operation promise\n * @param operation - Operation name for logging\n * @returns The result of the file operation\n */\n async withFileTimeout<T>(promise: Promise<T>, operation: string = 'file-operation'): Promise<T> {\n return this.withTimeout(promise, this.config.fileTimeout, operation);\n }\n\n /**\n * Create an AbortController with timeout\n *\n * @param timeoutMs - Timeout in milliseconds\n * @param operation - Operation name for logging\n * @returns AbortController that will abort after timeout\n */\n createAbortController(timeoutMs: number, operation: string): { controller: AbortController; cleanup: () => void } {\n const controller = new AbortController();\n\n const timeoutId = setTimeout(() => {\n if (!controller.signal.aborted) {\n this.auditLogger.requestTimeout(operation, timeoutMs);\n controller.abort(new TimeoutError(\n `Operation \"${operation}\" timed out`,\n operation,\n timeoutMs\n ));\n }\n }, timeoutMs);\n\n const cleanup = () => {\n clearTimeout(timeoutId);\n };\n\n return { controller, cleanup };\n }\n\n /**\n * Get timeout for a specific operation type\n *\n * @param type - The operation type\n * @returns Timeout in milliseconds\n */\n getTimeout(type: 'default' | 'llm' | 'tool' | 'file'): number {\n switch (type) {\n case 'llm': return this.config.llmTimeout;\n case 'tool': return this.config.toolTimeout;\n case 'file': return this.config.fileTimeout;\n default: return this.config.defaultTimeout;\n }\n }\n\n /**\n * Check if timeout protection is enabled\n */\n isEnabled(): boolean {\n return this.config.enabled;\n }\n\n /**\n * Enable or disable timeout protection\n */\n setEnabled(enabled: boolean): void {\n this.config.enabled = enabled;\n }\n\n /**\n * Get the current configuration\n */\n getConfig(): TimeoutConfig {\n return { ...this.config };\n }\n}\n\n/**\n * Check if an error is a TimeoutError\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return error instanceof TimeoutError || (\n error !== null &&\n typeof error === 'object' &&\n 'isTimeout' in error &&\n (error as { isTimeout: boolean }).isTimeout === true\n );\n}\n\n// Global instance\nlet globalTimeoutGuard: TimeoutGuard | null = null;\n\n/**\n * Get the global TimeoutGuard instance\n */\nexport function getTimeoutGuard(): TimeoutGuard {\n if (!globalTimeoutGuard) {\n globalTimeoutGuard = new TimeoutGuard();\n }\n return globalTimeoutGuard;\n}\n\n/**\n * Configure the global TimeoutGuard\n */\nexport function configureTimeoutGuard(config: Partial<TimeoutConfig>): void {\n globalTimeoutGuard = new TimeoutGuard(config);\n}\n\n/**\n * Reset the global TimeoutGuard\n */\nexport function resetTimeoutGuard(): void {\n globalTimeoutGuard = null;\n}\n\n"],"names":["DEFAULT_CONFIG","enabled","defaultTimeout","llmTimeout","toolTimeout","fileTimeout","TimeoutError","Error","message","operation","timeoutMs","isTimeout","name","TimeoutGuard","withTimeout","promise","config","Promise","resolve","reject","settled","timeoutId","setTimeout","auditLogger","requestTimeout","then","result","clearTimeout","catch","error","withLLMTimeout","withToolTimeout","toolName","withFileTimeout","createAbortController","controller","AbortController","signal","aborted","abort","cleanup","getTimeout","type","isEnabled","setEnabled","getConfig","getAuditLogger","isTimeoutError","globalTimeoutGuard","getTimeoutGuard","configureTimeoutGuard","resetTimeoutGuard"],"mappings":";;AAAA;;;;;AAKC,IAAA,SAAA,gBAAA,CAAA,GAAA,EAAA,GAAA,EAAA,KAAA,EAAA;;;;;;;;;;;;;AAKD;;AAEC,I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ptional<z.ZodBoolean>>;
4
+ basePaths: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
5
+ allowAbsolute: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
6
+ allowSymlinks: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
7
+ denyPatterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
8
+ }, z.core.$strip>;
9
+ export declare const ToolSecurityConfigSchema: z.ZodObject<{
10
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
11
+ validateParams: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
12
+ sandboxExecution: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
13
+ allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
+ deniedTools: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
15
+ maxExecutionTime: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
16
+ maxConcurrentCalls: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
17
+ }, z.core.$strip>;
18
+ export declare const SecretSecurityConfigSchema: z.ZodObject<{
19
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
20
+ redactInLogs: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
21
+ redactInErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
22
+ patterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodCustom<RegExp, RegExp>>>>;
23
+ customPatterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodCustom<RegExp, RegExp>>>>;
24
+ }, z.core.$strip>;
25
+ export declare const LogSecurityConfigSchema: z.ZodObject<{
26
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
27
+ auditSecurityEvents: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
28
+ sanitizeStackTraces: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
29
+ maxContentLength: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
30
+ }, z.core.$strip>;
31
+ export declare const TimeoutConfigSchema: z.ZodObject<{
32
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
33
+ defaultTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
34
+ llmTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
35
+ toolTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
36
+ fileTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
37
+ }, z.core.$strip>;
38
+ export declare function createDefaultPathSecurityConfig(): PathSecurityConfig;
39
+ export declare function createDefaultToolSecurityConfig(): ToolSecurityConfig;
40
+ export declare function createDefaultSecretSecurityConfig(): SecretSecurityConfig;
41
+ export declare function createDefaultLogSecurityConfig(): LogSecurityConfig;
42
+ export declare function createDefaultTimeoutConfig(): TimeoutConfig;
43
+ export declare const SecurityConfigSchema: z.ZodObject<{
44
+ paths: z.ZodDefault<z.ZodOptional<z.ZodObject<{
45
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
46
+ basePaths: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
47
+ allowAbsolute: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
48
+ allowSymlinks: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
49
+ denyPatterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
50
+ }, z.core.$strip>>>;
51
+ tools: z.ZodDefault<z.ZodOptional<z.ZodObject<{
52
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
53
+ validateParams: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
54
+ sandboxExecution: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
55
+ allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
56
+ deniedTools: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
57
+ maxExecutionTime: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
58
+ maxConcurrentCalls: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
59
+ }, z.core.$strip>>>;
60
+ secrets: z.ZodDefault<z.ZodOptional<z.ZodObject<{
61
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
62
+ redactInLogs: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
63
+ redactInErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
64
+ patterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodCustom<RegExp, RegExp>>>>;
65
+ customPatterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodCustom<RegExp, RegExp>>>>;
66
+ }, z.core.$strip>>>;
67
+ logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
68
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
69
+ auditSecurityEvents: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
70
+ sanitizeStackTraces: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
71
+ maxContentLength: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
72
+ }, z.core.$strip>>>;
73
+ timeouts: z.ZodDefault<z.ZodOptional<z.ZodObject<{
74
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
75
+ defaultTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
76
+ llmTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
77
+ toolTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
78
+ fileTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
79
+ }, z.core.$strip>>>;
80
+ }, z.core.$strip>;
81
+ export type PathSecurityConfig = z.infer<typeof PathSecurityConfigSchema>;
82
+ export type ToolSecurityConfig = z.infer<typeof ToolSecurityConfigSchema>;
83
+ export type SecretSecurityConfig = z.infer<typeof SecretSecurityConfigSchema>;
84
+ export type LogSecurityConfig = z.infer<typeof LogSecurityConfigSchema>;
85
+ export type TimeoutConfig = z.infer<typeof TimeoutConfigSchema>;
86
+ export type SecurityConfig = z.infer<typeof SecurityConfigSchema>;
@@ -0,0 +1,80 @@
1
+ import { z } from 'zod';
2
+
3
+ // Path Security Configuration
4
+ const PathSecurityConfigSchema = z.object({
5
+ enabled: z.boolean().optional().default(true),
6
+ basePaths: z.array(z.string()).optional().default([]),
7
+ allowAbsolute: z.boolean().optional().default(false),
8
+ allowSymlinks: z.boolean().optional().default(false),
9
+ denyPatterns: z.array(z.string()).optional().default([
10
+ '\\.\\.',
11
+ '~',
12
+ '\\$\\{'
13
+ ])
14
+ });
15
+ // Tool Security Configuration
16
+ const ToolSecurityConfigSchema = z.object({
17
+ enabled: z.boolean().optional().default(true),
18
+ validateParams: z.boolean().optional().default(true),
19
+ sandboxExecution: z.boolean().optional().default(false),
20
+ allowedTools: z.array(z.string()).optional(),
21
+ deniedTools: z.array(z.string()).optional().default([]),
22
+ maxExecutionTime: z.number().optional().default(30000),
23
+ maxConcurrentCalls: z.number().optional().default(10)
24
+ });
25
+ // Secret Security Configuration
26
+ const SecretSecurityConfigSchema = z.object({
27
+ enabled: z.boolean().optional().default(true),
28
+ redactInLogs: z.boolean().optional().default(true),
29
+ redactInErrors: z.boolean().optional().default(true),
30
+ patterns: z.array(z.instanceof(RegExp)).optional().default([
31
+ /api[_-]?key[\s:="']+[\w-]+/gi,
32
+ /password[\s:="']+[\w-]+/gi,
33
+ /Bearer\s+[\w-]+/gi,
34
+ /sk-[a-zA-Z0-9]{48,}/g,
35
+ /AKIA[0-9A-Z]{16}/g
36
+ ]),
37
+ customPatterns: z.array(z.instanceof(RegExp)).optional().default([])
38
+ });
39
+ // Logging Security Configuration
40
+ const LogSecurityConfigSchema = z.object({
41
+ enabled: z.boolean().optional().default(true),
42
+ auditSecurityEvents: z.boolean().optional().default(true),
43
+ sanitizeStackTraces: z.boolean().optional().default(true),
44
+ maxContentLength: z.number().optional().default(10000)
45
+ });
46
+ // Timeout Configuration
47
+ const TimeoutConfigSchema = z.object({
48
+ enabled: z.boolean().optional().default(true),
49
+ defaultTimeout: z.number().optional().default(30000),
50
+ llmTimeout: z.number().optional().default(120000),
51
+ toolTimeout: z.number().optional().default(30000),
52
+ fileTimeout: z.number().optional().default(5000)
53
+ });
54
+ // Helper to create default configs
55
+ function createDefaultPathSecurityConfig() {
56
+ return PathSecurityConfigSchema.parse({});
57
+ }
58
+ function createDefaultToolSecurityConfig() {
59
+ return ToolSecurityConfigSchema.parse({});
60
+ }
61
+ function createDefaultSecretSecurityConfig() {
62
+ return SecretSecurityConfigSchema.parse({});
63
+ }
64
+ function createDefaultLogSecurityConfig() {
65
+ return LogSecurityConfigSchema.parse({});
66
+ }
67
+ function createDefaultTimeoutConfig() {
68
+ return TimeoutConfigSchema.parse({});
69
+ }
70
+ // Complete Security Configuration
71
+ const SecurityConfigSchema = z.object({
72
+ paths: PathSecurityConfigSchema.optional().default(createDefaultPathSecurityConfig),
73
+ tools: ToolSecurityConfigSchema.optional().default(createDefaultToolSecurityConfig),
74
+ secrets: SecretSecurityConfigSchema.optional().default(createDefaultSecretSecurityConfig),
75
+ logging: LogSecurityConfigSchema.optional().default(createDefaultLogSecurityConfig),
76
+ timeouts: TimeoutConfigSchema.optional().default(createDefaultTimeoutConfig)
77
+ });
78
+
79
+ export { LogSecurityConfigSchema, PathSecurityConfigSchema, SecretSecurityConfigSchema, SecurityConfigSchema, TimeoutConfigSchema, ToolSecurityConfigSchema, createDefaultLogSecurityConfig, createDefaultPathSecurityConfig, createDefaultSecretSecurityConfig, createDefaultTimeoutConfig, createDefaultToolSecurityConfig };
80
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../../src/security/types.ts"],"sourcesContent":["import { z } from 'zod';\n\n// Path Security Configuration\nexport const PathSecurityConfigSchema = z.object({\n enabled: z.boolean().optional().default(true),\n basePaths: z.array(z.string()).optional().default([]),\n allowAbsolute: z.boolean().optional().default(false),\n allowSymlinks: z.boolean().optional().default(false),\n denyPatterns: z.array(z.string()).optional().default([\n '\\\\.\\\\.', // Parent directory\n '~', // Home directory expansion\n '\\\\$\\\\{', // Variable expansion\n ]),\n});\n\n// Tool Security Configuration\nexport const ToolSecurityConfigSchema = z.object({\n enabled: z.boolean().optional().default(true),\n validateParams: z.boolean().optional().default(true),\n sandboxExecution: z.boolean().optional().default(false),\n allowedTools: z.array(z.string()).optional(),\n deniedTools: z.array(z.string()).optional().default([]),\n maxExecutionTime: z.number().optional().default(30000), // 30 seconds\n maxConcurrentCalls: z.number().optional().default(10),\n});\n\n// Secret Security Configuration\nexport const SecretSecurityConfigSchema = z.object({\n enabled: z.boolean().optional().default(true),\n redactInLogs: z.boolean().optional().default(true),\n redactInErrors: z.boolean().optional().default(true),\n patterns: z.array(z.instanceof(RegExp)).optional().default([\n /api[_-]?key[\\s:=\"']+[\\w-]+/gi,\n /password[\\s:=\"']+[\\w-]+/gi,\n /Bearer\\s+[\\w-]+/gi,\n /sk-[a-zA-Z0-9]{48,}/g,\n /AKIA[0-9A-Z]{16}/g, // AWS Access Key\n ]),\n customPatterns: z.array(z.instanceof(RegExp)).optional().default([]),\n});\n\n// Logging Security Configuration\nexport const LogSecurityConfigSchema = z.object({\n enabled: z.boolean().optional().default(true),\n auditSecurityEvents: z.boolean().optional().default(true),\n sanitizeStackTraces: z.boolean().optional().default(true),\n maxContentLength: z.number().optional().default(10000),\n});\n\n// Timeout Configuration\nexport const TimeoutConfigSchema = z.object({\n enabled: z.boolean().optional().default(true),\n defaultTimeout: z.number().optional().default(30000),\n llmTimeout: z.number().optional().default(120000), // 2 minutes for LLM calls\n toolTimeout: z.number().optional().default(30000),\n fileTimeout: z.number().optional().default(5000),\n});\n\n// Helper to create default configs\nexport function createDefaultPathSecurityConfig(): PathSecurityConfig {\n return PathSecurityConfigSchema.parse({});\n}\n\nexport function createDefaultToolSecurityConfig(): ToolSecurityConfig {\n return ToolSecurityConfigSchema.parse({});\n}\n\nexport function createDefaultSecretSecurityConfig(): SecretSecurityConfig {\n return SecretSecurityConfigSchema.parse({});\n}\n\nexport function createDefaultLogSecurityConfig(): LogSecurityConfig {\n return LogSecurityConfigSchema.parse({});\n}\n\nexport function createDefaultTimeoutConfig(): TimeoutConfig {\n return TimeoutConfigSchema.parse({});\n}\n\n// Complete Security Configuration\nexport const SecurityConfigSchema = z.object({\n paths: PathSecurityConfigSchema.optional().default(createDefaultPathSecurityConfig),\n tools: ToolSecurityConfigSchema.optional().default(createDefaultToolSecurityConfig),\n secrets: SecretSecurityConfigSchema.optional().default(createDefaultSecretSecurityConfig),\n logging: LogSecurityConfigSchema.optional().default(createDefaultLogSecurityConfig),\n timeouts: TimeoutConfigSchema.optional().default(createDefaultTimeoutConfig),\n});\n\n// Type exports\nexport type PathSecurityConfig = z.infer<typeof PathSecurityConfigSchema>;\nexport type ToolSecurityConfig = z.infer<typeof ToolSecurityConfigSchema>;\nexport type SecretSecurityConfig = z.infer<typeof SecretSecurityConfigSchema>;\nexport type LogSecurityConfig = z.infer<typeof LogSecurityConfigSchema>;\nexport type TimeoutConfig = z.infer<typeof TimeoutConfigSchema>;\nexport type SecurityConfig = z.infer<typeof SecurityConfigSchema>;\n"],"names":["PathSecurityConfigSchema","z","object","enabled","boolean","optional","default","basePaths","array","string","allowAbsolute","allowSymlinks","denyPatterns","ToolSecurityConfigSchema","validateParams","sandboxExecution","allowedTools","deniedTools","maxExecutionTime","number","maxConcurrentCalls","SecretSecurityConfigSchema","redactInLogs","redactInErrors","patterns","instanceof","RegExp","customPatterns","LogSecurityConfigSchema","auditSecurityEvents","sanitizeStackTraces","maxContentLength","TimeoutConfigSchema","defaultTimeout","llmTimeout","toolTimeout","fileTimeout","createDefaultPathSecurityConfig","parse","createDefaultToolSecurityConfig","createDefaultSecretSecurityConfig","createDefaultLogSecurityConfig","createDefaultTimeoutConfig","SecurityConfigSchema","paths","tools","secrets","logging","timeouts"],"mappings":";;AAEA;AACO,MAAMA,wBAAA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AOV,mBAAAA,CAAoBM,KAAK,CAAC,EAAC,CAAA;AACtC;AAEA;AACO,MAAMK,oBAAAA,GAAuB1C,CAAAA,CAAEC,MAAM,CAAC;AACzC0C,IAAAA,KAAAA,EAAO5C,wBAAAA,CAAyBK,QAAQ,EAAA,CAAGC,OAAO,CAAC+B,+BAAAA,CAAAA;AACnDQ,IAAAA,KAAAA,EAAOhC,wBAAAA,CAAyBR,QAAQ,EAAA,CAAGC,OAAO,CAACiC,+BAAAA,CAAAA;AACnDO,IAAAA,OAAAA,EAASzB,0BAAAA,CAA2BhB,QAAQ,EAAA,CAAGC,OAAO,CAACkC,iCAAAA,CAAAA;AACvDO,IAAAA,OAAAA,EAASnB,uBAAAA,CAAwBvB,QAAQ,EAAA,CAAGC,OAAO,CAACmC,8BAAAA,CAAAA;AACpDO,IAAAA,QAAAA,EAAUhB,mBAAAA,CAAoB3B,QAAQ,EAAA,CAAGC,OAAO,CAACoC,0BAAAA;AACrD,CAAA;;;;"}
@@ -397,5 +397,5 @@ function _define_property(obj, key, value) {
397
397
  }
398
398
  }
399
399
 
400
- export { TokenBudgetManager, TokenCounter, TokenBudgetManager as default };
400
+ export { TokenBudgetManager, TokenCounter };
401
401
  //# sourceMappingURL=token-budget.js.map
package/dist/tools.js CHANGED
@@ -320,5 +320,5 @@ const ToolSchema = z.object({
320
320
  }
321
321
  }
322
322
 
323
- export { ToolRegistry, ToolRegistry as default };
323
+ export { ToolRegistry };
324
324
  //# sourceMappingURL=tools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.js","sources":["../../src/util/storage.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport * as fs from 'fs';\nimport { glob } from 'glob';\nimport path from 'path';\nimport crypto from 'crypto';\n/**\n * This module exists to isolate filesystem operations from the rest of the codebase.\n * This makes testing easier by avoiding direct fs mocking in jest configuration.\n * \n * Additionally, abstracting storage operations allows for future flexibility - \n * this export utility may need to work with storage systems other than the local filesystem\n * (e.g. S3, Google Cloud Storage, etc).\n */\n\nexport interface Utility {\n exists: (path: string) => Promise<boolean>;\n isDirectory: (path: string) => Promise<boolean>;\n isFile: (path: string) => Promise<boolean>;\n isReadable: (path: string) => Promise<boolean>;\n isWritable: (path: string) => Promise<boolean>;\n isFileReadable: (path: string) => Promise<boolean>;\n isDirectoryWritable: (path: string) => Promise<boolean>;\n isDirectoryReadable: (path: string) => Promise<boolean>;\n createDirectory: (path: string) => Promise<void>;\n readFile: (path: string, encoding: string) => Promise<string>;\n readStream: (path: string) => Promise<fs.ReadStream>;\n writeFile: (path: string, data: string | Buffer, encoding: string) => Promise<void>;\n forEachFileIn: (directory: string, callback: (path: string) => Promise<void>, options?: { pattern: string, limit?: number }) => Promise<void>;\n hashFile: (path: string, length: number) => Promise<string>;\n listFiles: (directory: string) => Promise<string[]>;\n}\n\nexport const create = (params: { log?: (message: string, ...args: any[]) => void }): Utility => {\n\n // eslint-disable-next-line no-console\n const log = params.log || console.log;\n\n const exists = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.stat(path);\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: any) {\n return false;\n }\n }\n\n const isDirectory = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isDirectory()) {\n log(`${path} is not a directory`);\n return false;\n }\n return true;\n }\n\n const isFile = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isFile()) {\n log(`${path} is not a file`);\n return false;\n }\n return true;\n }\n\n const isReadable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.R_OK);\n } catch (error: any) {\n log(`${path} is not readable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isWritable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.W_OK);\n } catch (error: any) {\n log(`${path} is not writable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isFileReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isFile(path) && await isReadable(path);\n }\n\n const isDirectoryWritable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isWritable(path);\n }\n\n const isDirectoryReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isReadable(path);\n }\n\n const createDirectory = async (path: string): Promise<void> => {\n try {\n await fs.promises.mkdir(path, { recursive: true });\n } catch (mkdirError: any) {\n throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);\n }\n }\n\n const readFile = async (path: string, encoding: string): Promise<string> => {\n return await fs.promises.readFile(path, { encoding: encoding as BufferEncoding });\n }\n\n const writeFile = async (path: string, data: string | Buffer, encoding: string): Promise<void> => {\n await fs.promises.writeFile(path, data, { encoding: encoding as BufferEncoding });\n }\n\n const forEachFileIn = async (\n directory: string,\n callback: (file: string) => Promise<void>,\n options: { pattern: string | string[], limit?: number } = { pattern: '*.*' },\n ): Promise<void> => {\n try {\n let filesProcessed = 0;\n const files = await glob(options.pattern, { cwd: directory, nodir: true });\n for (const file of files) {\n await callback(path.join(directory, file));\n filesProcessed++;\n if (options.limit && filesProcessed >= options.limit) {\n log(`Reached limit of ${options.limit} files, stopping`);\n break;\n }\n }\n } catch (err: any) {\n throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);\n }\n }\n\n const readStream = async (path: string): Promise<fs.ReadStream> => {\n return fs.createReadStream(path);\n }\n\n const hashFile = async (path: string, length: number): Promise<string> => {\n const file = await readFile(path, 'utf8');\n return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);\n }\n\n const listFiles = async (directory: string): Promise<string[]> => {\n return await fs.promises.readdir(directory);\n }\n\n return {\n exists,\n isDirectory,\n isFile,\n isReadable,\n isWritable,\n isFileReadable,\n isDirectoryWritable,\n isDirectoryReadable,\n createDirectory,\n readFile,\n readStream,\n writeFile,\n forEachFileIn,\n hashFile,\n listFiles,\n };\n}"],"names":["create","params","log","console","exists","path","fs","promises","stat","error","isDirectory","stats","isFile","isReadable","access","constants","R_OK","message","stack","isWritable","W_OK","isFileReadable","isDirectoryWritable","isDirectoryReadable","createDirectory","mkdir","recursive","mkdirError","Error","readFile","encoding","writeFile","data","forEachFileIn","directory","callback","options","pattern","filesProcessed","files","glob","cwd","nodir","file","join","limit","err","readStream","createReadStream","hashFile","length","crypto","createHash","update","digest","slice","listFiles","readdir"],"mappings":";;;;;AAAA;AAgCO,MAAMA,SAAS,CAACC,MAAAA,GAAAA;;AAGnB,IAAA,MAAMC,GAAAA,GAAMD,MAAAA,CAAOC,GAAG,IAAIC,QAAQD,GAAG;AAErC,IAAA,MAAME,SAAS,OAAOC,IAAAA,GAAAA;QAClB,IAAI;AACA,YAAA,MAAMC,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;YACvB,OAAO,IAAA;;AAEX,QAAA,CAAA,CAAE,OAAOI,KAAAA,EAAY;YACjB,OAAO,KAAA;AACX,QAAA;AACJ,IAAA,CAAA;AAEA,IAAA,MAAMC,cAAc,OAAOL,IAAAA,GAAAA;AACvB,QAAA,MAAMM,QAAQ,MAAML,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;QACrC,IAAI,CAACM,KAAAA,CAAMD,WAAW,EAAA,EAAI;YACtBR,GAAAA,CAAI,CAAA,EAAGG,IAAAA,CAAK,mBAAmB,CAAC,CAAA;YAChC,OAAO,KAAA;AACX,QAAA;QACA,OAAO,IAAA;AACX,IAAA,CAAA;AAEA,IAAA,MAAMO,SAAS,OAAOP,IAAAA,GAAAA;AAClB,QAAA,MAAMM,QAAQ,MAAML,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;QACrC,IAAI,CAACM,KAAAA,CAAMC,MAAM,EAAA,EAAI;YACjBV,GAAAA,CAAI,CAAA,EAAGG,IAAAA,CAAK,cAAc,CAAC,CAAA;YAC3B,OAAO,KAAA;AACX,QAAA;QACA,OAAO,IAAA;AACX,IAA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OAAOtB,SAAAA,GAAAA;AACrB,QAAA,OAAO,MAAM5B,EAAAA,CAAGC,QAAQ,CAACkD,OAAO,CAACvB,SAAAA,CAAAA;AACrC,IAAA,CAAA;IAEA,OAAO;AACH9B,QAAAA,MAAAA;AACAM,QAAAA,WAAAA;AACAE,QAAAA,MAAAA;AACAC,QAAAA,UAAAA;AACAM,QAAAA,UAAAA;AACAE,QAAAA,cAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,eAAAA;AACAK,QAAAA,QAAAA;AACAkB,QAAAA,UAAAA;AACAhB,QAAAA,SAAAA;AACAE,QAAAA,aAAAA;AACAgB,QAAAA,QAAAA;AACAO,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"storage.js","sources":["../../src/util/storage.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport * as fs from 'fs';\nimport { glob } from 'glob';\nimport path from 'path';\nimport crypto from 'crypto';\n/**\n * This module exists to isolate filesystem operations from the rest of the codebase.\n * This makes testing easier by avoiding direct fs mocking in jest configuration.\n * \n * Additionally, abstracting storage operations allows for future flexibility - \n * this export utility may need to work with storage systems other than the local filesystem\n * (e.g. S3, Google Cloud Storage, etc).\n */\n\nexport interface Utility {\n exists: (path: string) => Promise<boolean>;\n isDirectory: (path: string) => Promise<boolean>;\n isFile: (path: string) => Promise<boolean>;\n isReadable: (path: string) => Promise<boolean>;\n isWritable: (path: string) => Promise<boolean>;\n isFileReadable: (path: string) => Promise<boolean>;\n isDirectoryWritable: (path: string) => Promise<boolean>;\n isDirectoryReadable: (path: string) => Promise<boolean>;\n createDirectory: (path: string) => Promise<void>;\n readFile: (path: string, encoding: string) => Promise<string>;\n readStream: (path: string) => Promise<fs.ReadStream>;\n writeFile: (path: string, data: string | Buffer, encoding: string) => Promise<void>;\n forEachFileIn: (directory: string, callback: (path: string) => Promise<void>, options?: { pattern: string, limit?: number }) => Promise<void>;\n hashFile: (path: string, length: number) => Promise<string>;\n listFiles: (directory: string) => Promise<string[]>;\n}\n\nexport const create = (params: { log?: (message: string, ...args: any[]) => void }): Utility => {\n\n // eslint-disable-next-line no-console\n const log = params.log || console.log;\n\n const exists = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.stat(path);\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: any) {\n return false;\n }\n }\n\n const isDirectory = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isDirectory()) {\n log(`${path} is not a directory`);\n return false;\n }\n return true;\n }\n\n const isFile = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isFile()) {\n log(`${path} is not a file`);\n return false;\n }\n return true;\n }\n\n const isReadable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.R_OK);\n } catch (error: any) {\n log(`${path} is not readable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isWritable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.W_OK);\n } catch (error: any) {\n log(`${path} is not writable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isFileReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isFile(path) && await isReadable(path);\n }\n\n const isDirectoryWritable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isWritable(path);\n }\n\n const isDirectoryReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isReadable(path);\n }\n\n const createDirectory = async (path: string): Promise<void> => {\n try {\n await fs.promises.mkdir(path, { recursive: true });\n } catch (mkdirError: any) {\n throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);\n }\n }\n\n const readFile = async (path: string, encoding: string): Promise<string> => {\n return await fs.promises.readFile(path, { encoding: encoding as BufferEncoding });\n }\n\n const writeFile = async (path: string, data: string | Buffer, encoding: string): Promise<void> => {\n await fs.promises.writeFile(path, data, { encoding: encoding as BufferEncoding });\n }\n\n const forEachFileIn = async (\n directory: string,\n callback: (file: string) => Promise<void>,\n options: { pattern: string | string[], limit?: number } = { pattern: '*.*' },\n ): Promise<void> => {\n try {\n let filesProcessed = 0;\n const files = await glob(options.pattern, { cwd: directory, nodir: true });\n for (const file of files) {\n await callback(path.join(directory, file));\n filesProcessed++;\n if (options.limit && filesProcessed >= options.limit) {\n log(`Reached limit of ${options.limit} files, stopping`);\n break;\n }\n }\n } catch (err: any) {\n throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);\n }\n }\n\n const readStream = async (path: string): Promise<fs.ReadStream> => {\n return fs.createReadStream(path);\n }\n\n const hashFile = async (path: string, length: number): Promise<string> => {\n const file = await readFile(path, 'utf8');\n return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);\n }\n\n const listFiles = async (directory: string): Promise<string[]> => {\n return await fs.promises.readdir(directory);\n }\n\n return {\n exists,\n isDirectory,\n isFile,\n isReadable,\n isWritable,\n isFileReadable,\n isDirectoryWritable,\n isDirectoryReadable,\n createDirectory,\n readFile,\n readStream,\n writeFile,\n forEachFileIn,\n hashFile,\n listFiles,\n };\n}\n"],"names":["create","params","log","console","exists","path","fs","promises","stat","error","isDirectory","stats","isFile","isReadable","access","constants","R_OK","message","stack","isWritable","W_OK","isFileReadable","isDirectoryWritable","isDirectoryReadable","createDirectory","mkdir","recursive","mkdirError","Error","readFile","encoding","writeFile","data","forEachFileIn","directory","callback","options","pattern","filesProcessed","files","glob","cwd","nodir","file","join","limit","err","readStream","createReadStream","hashFile","length","crypto","createHash","update","digest","slice","listFiles","readdir"],"mappings":";;;;;AAAA;AAgCO,MAAMA,SAAS,CAACC,MAAAA,GAAAA;;AAGnB,IAAA,MAAMC,GAAAA,GAAMD,MAAAA,CAAOC,GAAG,IAAIC,QAAQD,GAAG;AAErC,IAAA,MAAME,SAAS,OAAOC,IAAAA,GAAAA;QAClB,IAAI;AACA,YAAA,MAAMC,EAAAA,CAAGC,QAAQ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/guide/index.md CHANGED
@@ -49,7 +49,9 @@ const result = await executeChat(prompt, { model: 'gpt-4o' });
49
49
 
50
50
  This guide directory contains specialized documentation for different aspects of the system:
51
51
 
52
+ * [Integration](./integration.md): Comprehensive guide for integrating RiotPrompt as a library, including API reference, conversation management, tool integration, and agentic workflows.
52
53
  * [Architecture](./architecture.md): Internal design, module structure, and data flow.
53
54
  * [Usage Patterns](./usage.md): Common patterns for CLI and library usage, including the Recipes API and Structured Outputs.
54
55
  * [Configuration](./configuration.md): Deep dive into configuration options.
56
+ * [Security](./security.md): Security best practices and features.
55
57
  * [Development](./development.md): Guide for contributing to `riotprompt`.