MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / asObjectSafe

Function asObjectSafe

src/api/transform/vscode-lm-format.ts:7–29  ·  view source on GitHub ↗

* Safely converts a value into a plain object.

(value: any)

Source from the content-addressed store, hash-verified

5 * Safely converts a value into a plain object.
6 */
7function 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
31export function convertToVsCodeLmMessages(
32 anthropicMessages: Anthropic.Messages.MessageParam[],

Callers 1

Calls 2

parseMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected