@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 38 lines 971 Bytes
Raw
1 const REDACTED = '[REDACTED]';
2
3 const SENSITIVE_KEYS = new Set([
4 'access_token',
5 'api_key',
6 'apikey',
7 'authorization',
8 'client_secret',
9 'composio_agent_key',
10 'password',
11 'refresh_token',
12 'secret',
13 'token',
14 'user_api_key',
15 ]);
16
17 const normalizeKey = (key: string): string =>
18 key
19 .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
20 .replace(/-/g, '_')
21 .toLowerCase();
22
23 const redactStructuredValue = (value: unknown): unknown => {
24 if (Array.isArray(value)) return value.map(redactStructuredValue);
25 if (value === null || typeof value !== 'object') return value;
26
27 return Object.fromEntries(
28 Object.entries(value).map(([key, nested]) => [
29 key,
30 SENSITIVE_KEYS.has(normalizeKey(key)) ? REDACTED : redactStructuredValue(nested),
31 ])
32 );
33 };
34
35 /** Redact credential-shaped fields from structured values before logging. */
36 export const redactSensitiveLogValue = (value: unknown): unknown => {
37 return redactStructuredValue(value);
38 };