(value: unknown)
| 109 | }; |
| 110 | |
| 111 | const pickFirstString = (value: unknown): string | undefined => { |
| 112 | if (typeof value === 'string') { |
| 113 | const trimmed = value.trim(); |
| 114 | return trimmed.length > 0 ? trimmed : undefined; |
| 115 | } |
| 116 | if (typeof value === 'number' || typeof value === 'boolean') { |
| 117 | return String(value); |
| 118 | } |
| 119 | if (Array.isArray(value)) { |
| 120 | for (const entry of value) { |
| 121 | const candidate = pickFirstString(entry); |
| 122 | if (candidate) return candidate; |
| 123 | } |
| 124 | return undefined; |
| 125 | } |
| 126 | if (value && typeof value === 'object') { |
| 127 | const obj = value as Record<string, unknown>; |
| 128 | const nestedKeys = ['path', 'filepath', 'filePath', 'file_path', 'target', 'value']; |
| 129 | for (const key of nestedKeys) { |
| 130 | if (key in obj) { |
| 131 | const candidate = pickFirstString(obj[key]); |
| 132 | if (candidate) return candidate; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | return undefined; |
| 137 | }; |
| 138 | |
| 139 | const extractPathFromInput = (input: unknown, action?: ToolAction): string | undefined => { |
| 140 | if (!input || typeof input !== 'object') return undefined; |
no outgoing calls
no test coverage detected