* Safely converts a value into a plain object.
(value: any)
| 5 | * Safely converts a value into a plain object. |
| 6 | */ |
| 7 | function asObjectSafe(value: any): object { |
| 8 | // Handle null/undefined |
| 9 | if (!value) { |
| 10 | return {} |
| 11 | } |
| 12 | |
| 13 | try { |
| 14 | // Handle strings that might be JSON |
| 15 | if (typeof value === "string") { |
| 16 | return JSON.parse(value) |
| 17 | } |
| 18 | |
| 19 | // Handle pre-existing objects |
| 20 | if (typeof value === "object") { |
| 21 | return { ...value } |
| 22 | } |
| 23 | |
| 24 | return {} |
| 25 | } catch (error) { |
| 26 | console.warn("Roo Code <Language Model API>: Failed to parse object:", error) |
| 27 | return {} |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | export function convertToVsCodeLmMessages( |
| 32 | anthropicMessages: Anthropic.Messages.MessageParam[], |
no test coverage detected