@riotprompt/riotprompt 0.0.21 → 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.js +481 -22
- 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/guide/index.md +2 -0
- package/guide/integration.md +1109 -0
- package/guide/security.md +237 -0
- package/package.json +17 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization-schemas.js","sources":["../../src/security/serialization-schemas.ts"],"sourcesContent":["/**\n * RiotPrompt - Serialization Schemas\n *\n * Zod schemas for validating deserialized data to prevent\n * object injection attacks and ensure data integrity.\n */\n\nimport { z } from 'zod';\n\n/**\n * Schema version for forward compatibility\n */\nexport const SCHEMA_VERSION = '1.0.0';\n\n/**\n * Maximum sizes for serialized data\n */\nexport const SERIALIZATION_LIMITS = {\n maxContentLength: 1_000_000, // 1MB per message\n maxArgumentsLength: 100_000, // 100KB for tool arguments\n maxMessages: 10_000, // 10k messages per conversation\n maxContextItems: 1_000, // 1k context items\n maxStringLength: 100, // 100 chars for names/ids\n maxToolCalls: 100, // 100 tool calls per message\n};\n\n/**\n * Tool call schema\n */\nexport const ToolCallSchema = z.object({\n id: z.string().max(SERIALIZATION_LIMITS.maxStringLength),\n type: z.literal('function'),\n function: z.object({\n name: z.string().max(SERIALIZATION_LIMITS.maxStringLength),\n arguments: z.string().max(SERIALIZATION_LIMITS.maxArgumentsLength),\n }),\n});\n\nexport type ToolCall = z.infer<typeof ToolCallSchema>;\n\n/**\n * Conversation message schema\n */\nexport const ConversationMessageSchema = z.object({\n role: z.enum(['system', 'user', 'assistant', 'tool']),\n content: z.string().nullable().refine(\n val => val === null || val.length <= SERIALIZATION_LIMITS.maxContentLength,\n { message: `Content exceeds maximum length of ${SERIALIZATION_LIMITS.maxContentLength}` }\n ),\n name: z.string().max(SERIALIZATION_LIMITS.maxStringLength).optional(),\n tool_calls: z.array(ToolCallSchema).max(SERIALIZATION_LIMITS.maxToolCalls).optional(),\n tool_call_id: z.string().max(SERIALIZATION_LIMITS.maxStringLength).optional(),\n});\n\nexport type ConversationMessage = z.infer<typeof ConversationMessageSchema>;\n\n/**\n * Conversation metadata schema\n */\nexport const ConversationMetadataSchema = z.object({\n model: z.string().max(SERIALIZATION_LIMITS.maxStringLength),\n created: z.string().datetime(),\n lastModified: z.string().datetime(),\n messageCount: z.number().int().nonnegative(),\n toolCallCount: z.number().int().nonnegative(),\n});\n\nexport type ConversationMetadata = z.infer<typeof ConversationMetadataSchema>;\n\n/**\n * Serialized conversation schema\n */\nexport const SerializedConversationSchema = z.object({\n // Optional version for forward compatibility\n version: z.string().optional(),\n messages: z.array(ConversationMessageSchema).max(SERIALIZATION_LIMITS.maxMessages),\n metadata: ConversationMetadataSchema,\n contextProvided: z.array(z.string().max(1000)).max(SERIALIZATION_LIMITS.maxContextItems).optional(),\n});\n\nexport type SerializedConversation = z.infer<typeof SerializedConversationSchema>;\n\n/**\n * Prompt serialization schema (flexible for various prompt structures)\n */\nexport const SerializedPromptSchema = z.object({\n version: z.string().optional(),\n persona: z.any().optional(),\n instructions: z.any().optional(),\n contexts: z.any().optional(),\n content: z.any().optional(),\n});\n\nexport type SerializedPrompt = z.infer<typeof SerializedPromptSchema>;\n\n/**\n * Logged conversation schema (for conversation-logger)\n */\nexport const LoggedConversationSchema = z.object({\n id: z.string().max(200),\n metadata: z.object({\n startTime: z.union([z.string().datetime(), z.date()]),\n endTime: z.union([z.string().datetime(), z.date()]).optional(),\n duration: z.number().nonnegative().optional(),\n model: z.string().max(SERIALIZATION_LIMITS.maxStringLength),\n template: z.string().max(SERIALIZATION_LIMITS.maxStringLength).optional(),\n userContext: z.record(z.string(), z.any()).optional(),\n }),\n prompt: z.object({\n persona: z.string().optional(),\n instructions: z.string().optional(),\n content: z.array(z.string()).optional(),\n context: z.array(z.string()).optional(),\n }).optional(),\n messages: z.array(z.object({\n index: z.number().int().nonnegative(),\n timestamp: z.string(),\n role: z.string(),\n content: z.string().nullable(),\n tool_calls: z.array(ToolCallSchema).optional(),\n tool_call_id: z.string().optional(),\n metadata: z.record(z.string(), z.any()).optional(),\n })).max(SERIALIZATION_LIMITS.maxMessages),\n summary: z.object({\n totalMessages: z.number().int().nonnegative(),\n totalTokens: z.number().int().nonnegative().optional(),\n toolCallsExecuted: z.number().int().nonnegative(),\n iterations: z.number().int().nonnegative(),\n finalOutput: z.string().optional(),\n success: z.boolean(),\n }),\n});\n\nexport type LoggedConversation = z.infer<typeof LoggedConversationSchema>;\n\n/**\n * Validate serialized conversation data\n *\n * @param data - The data to validate\n * @returns Validation result\n */\nexport function validateConversation(data: unknown): {\n success: boolean;\n data?: SerializedConversation;\n error?: string;\n} {\n const result = SerializedConversationSchema.safeParse(data);\n\n if (result.success) {\n return { success: true, data: result.data };\n }\n\n // Create safe error message (don't leak full schema details)\n const issues = result.error.issues\n .slice(0, 3) // Limit to first 3 issues\n .map(i => `${i.path.join('.')}: ${i.message}`)\n .join('; ');\n\n return { success: false, error: issues };\n}\n\n/**\n * Validate logged conversation data\n *\n * @param data - The data to validate\n * @returns Validation result\n */\nexport function validateLoggedConversation(data: unknown): {\n success: boolean;\n data?: LoggedConversation;\n error?: string;\n} {\n const result = LoggedConversationSchema.safeParse(data);\n\n if (result.success) {\n return { success: true, data: result.data };\n }\n\n const issues = result.error.issues\n .slice(0, 3)\n .map(i => `${i.path.join('.')}: ${i.message}`)\n .join('; ');\n\n return { success: false, error: issues };\n}\n\n/**\n * Safe JSON parse with schema validation\n *\n * @param json - JSON string to parse\n * @param schema - Zod schema to validate against\n * @returns Parsed and validated data\n * @throws Error if parsing or validation fails\n */\nexport function safeJsonParse<T>(\n json: string,\n schema: z.ZodSchema<T>\n): T {\n let parsed: unknown;\n\n try {\n parsed = JSON.parse(json);\n } catch {\n throw new Error('Invalid JSON format');\n }\n\n const result = schema.safeParse(parsed);\n\n if (!result.success) {\n const issues = result.error.issues\n .slice(0, 3)\n .map(i => `${i.path.join('.')}: ${i.message}`)\n .join('; ');\n throw new Error(`Validation failed: ${issues}`);\n }\n\n return result.data;\n}\n\n"],"names":["SCHEMA_VERSION","SERIALIZATION_LIMITS","maxContentLength","maxArgumentsLength","maxMessages","maxContextItems","maxStringLength","maxToolCalls","ToolCallSchema","z","object","id","string","max","type","literal","function","name","arguments","ConversationMessageSchema","role","enum","content","nullable","refine","val","length","message","optional","tool_calls","array","tool_call_id","ConversationMetadataSchema","model","created","datetime","lastModified","messageCount","number","int","nonnegative","toolCallCount","SerializedConversationSchema","version","messages","metadata","contextProvided","SerializedPromptSchema","persona","any","instructions","contexts","LoggedConversationSchema","startTime","union","date","endTime","duration","template","userContext","record","prompt","context","index","timestamp","summary","totalMessages","totalTokens","toolCallsExecuted","iterations","finalOutput","success","boolean","validateConversation","data","result","safeParse","issues","error","slice","map","i","path","join","validateLoggedConversation","safeJsonParse","json","schema","parsed","JSON","parse","Error"],"mappings":";;AASA;;IAGO,MAAMA,cAAAA,GAAiB;AAE9B;;UAGaC,oBAAAA,GAAuB;IAChCC,gBAAAA,EAAkB,OAAA;IAClBC,kBAAAA,EAAoB,MAAA;IACpBC,WAAAA,EAAa,KAAA;IACbC,eAAAA,EAAiB,IAAA;IACjBC,eAAAA,EAAiB,GAAA;IACjBC,YAAAA,EAAc;AAClB;AAEA;;AAEC,IACM,MAAMC,cAAAA,GAAiBC,CAAAA,CAAEC,MAAM,CAAC;AACnCC,IAAAA,EAAAA,EAAIF,EAAEG,MAAM,EAAA,CAAGC,GAAG,CAACZ,qBAAqBK,eAAe,CAAA;IACvDQ,IAAAA,EAAML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
@@ -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,IACD,MAAMA,cAAAA,GAAgC;IAClCC,OAAAA,EAAS,IAAA;IACTC,cAAAA,EAAgB,KAAA;IAChBC,UAAAA,EAAY,MAAA;IACZC,WAAAA,EAAa,KAAA;IACbC,WAAAA,EAAa;AACjB,CAAA;AAEA;;IAGO,MAAMC,YAAAA,SAAqBC,KAAAA,CAAAA;AAK9B,IAAA,WAAA,CAAYC,OAAe,EAAEC,SAAAA,GAAoB,SAAS,EAAEC,SAAAA,GAAoB,CAAC,CAAE;QAC/E,KAAK,CAACF,OAAAA,CAAAA,EALV,gBAAA,CAAA,IAAA,EAASG,WAAAA,EAAY,IAAA,CAAA,EACrB,gBAAA,CAAA,IAAA,EAASF,WAAAA,EAAT,MAAA,CAAA,EACA,gBAAA,CAAA,IAAA,EAASC,WAAAA,EAAT,MAAA,CAAA;QAII,IAAI,CAACE,IAAI,GAAG,cAAA;QACZ,IAAI,CAACH,SAAS,GAAGA,SAAAA;QACjB,IAAI,CAACC,SAAS,GAAGA,SAAAA;AACrB,IAAA;AACJ;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BC,IACM,MAAMG,YAAAA,CA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AA;AAExD;AAEA;AACA,IAAIqC,kBAAAA,GAA0C,IAAA;AAE9C;;AAEC,IACM,SAASC,eAAAA,GAAAA;AACZ,IAAA,IAAI,CAACD,kBAAAA,EAAoB;AACrBA,QAAAA,kBAAAA,GAAqB,IAAInC,YAAAA,EAAAA;AAC7B,IAAA;IACA,OAAOmC,kBAAAA;AACX;AAEA;;IAGO,SAASE,qBAAAA,CAAsBlC,MAA8B,EAAA;AAChEgC,IAAAA,kBAAAA,GAAqB,IAAInC,YAAAA,CAAaG,MAAAA,CAAAA;AAC1C;AAEA;;AAEC,IACM,SAASmC,iBAAAA,GAAAA;IACZH,kBAAAA,GAAqB,IAAA;AACzB;;;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const PathSecurityConfigSchema: z.ZodObject<{
|
|
3
|
+
enabled: z.ZodDefault<z.ZodOptional<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,wBAAAA,GAA2BC,CAAAA,CAAEC,MAAM,CAAC;AAC7CC,IAAAA,OAAAA,EAASF,EAAEG,OAAO,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAAC,IAAA,CAAA;IACxCC,SAAAA,EAAWN,CAAAA,CAAEO,KAAK,CAACP,CAAAA,CAAEQ,MAAM,IAAIJ,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAE,CAAA;AACpDI,IAAAA,aAAAA,EAAeT,EAAEG,OAAO,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAAC,KAAA,CAAA;AAC9CK,IAAAA,aAAAA,EAAeV,EAAEG,OAAO,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAAC,KAAA,CAAA;IAC9CM,YAAAA,EAAcX,CAAAA,CAAEO,KAAK,CAACP,CAAAA,CAAEQ,MAAM,EAAA,CAAA,CAAIJ,QAAQ,EAAA,CAAGC,OAAO,CAAC;AACjD,QAAA,QAAA;AACA,QAAA,GAAA;AACA,QAAA;AACH,KAAA;AACL,CAAA;AAEA;AACO,MAAMO,wBAAAA,GAA2BZ,CAAAA,CAAEC,MAAM,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t, { 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`.
|