| 22 | } from './ToolDefinition.js'; |
| 23 | |
| 24 | function headerStringTransform( |
| 25 | value: string | undefined, |
| 26 | ): Record<string, string> | undefined { |
| 27 | if (value === undefined) { |
| 28 | return undefined; |
| 29 | } |
| 30 | if (value === '') { |
| 31 | return {}; |
| 32 | } |
| 33 | try { |
| 34 | const parsed = JSON.parse(value); |
| 35 | if ( |
| 36 | typeof parsed !== 'object' || |
| 37 | parsed === null || |
| 38 | Array.isArray(parsed) |
| 39 | ) { |
| 40 | throw new Error('Headers must be a JSON object'); |
| 41 | } |
| 42 | return parsed as Record<string, string>; |
| 43 | } catch (error) { |
| 44 | throw new Error( |
| 45 | `Invalid JSON for headers: ${error instanceof Error ? error.message : String(error)}`, |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | const throttlingOptions: [string, ...string[]] = [ |
| 51 | 'Offline', |