MCPcopy Index your code
hub / github.com/simstudioai/sim / parseResponseFormatSafely

Function parseResponseFormatSafely

apps/sim/lib/core/utils/response-format.ts:58–83  ·  view source on GitHub ↗
(
  responseFormatValue: any,
  blockId: string,
  options?: { allowReferences?: boolean }
)

Source from the content-addressed store, hash-verified

56 * Handles both string and object formats
57 */
58export function parseResponseFormatSafely(
59 responseFormatValue: any,
60 blockId: string,
61 options?: { allowReferences?: boolean }
62): any {
63 if (!responseFormatValue) {
64 return null
65 }
66
67 const allowReferences = options?.allowReferences ?? false
68
69 try {
70 if (typeof responseFormatValue === 'string') {
71 const trimmedValue = responseFormatValue.trim()
72 if (trimmedValue === '') return null
73 if (allowReferences && trimmedValue.startsWith('<') && trimmedValue.includes('>')) {
74 return trimmedValue
75 }
76 return JSON.parse(trimmedValue)
77 }
78 return responseFormatValue
79 } catch (error) {
80 logger.warn(`Failed to parse response format for block ${blockId}:`, error)
81 return null
82 }
83}
84
85/**
86 * Extract field values from a parsed JSON object based on selected output paths

Callers 1

getResponseFormatOutputsFunction · 0.90

Calls 2

parseMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected