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

Function processVariables

apps/sim/app/api/tools/stagehand/agent/route.ts:44–71  ·  view source on GitHub ↗

* Processes variables from various input formats into a standardized key-value object

(variables: any)

Source from the content-addressed store, hash-verified

42 * Processes variables from various input formats into a standardized key-value object
43 */
44function processVariables(variables: any): Record<string, string> | undefined {
45 if (!variables) return undefined
46
47 let variablesObject: Record<string, string> = {}
48
49 if (Array.isArray(variables)) {
50 variables.forEach((item: any) => {
51 if (item?.cells?.Key && typeof item.cells.Key === 'string') {
52 variablesObject[item.cells.Key] = item.cells.Value || ''
53 }
54 })
55 } else if (typeof variables === 'object' && variables !== null) {
56 variablesObject = { ...variables }
57 } else if (typeof variables === 'string') {
58 try {
59 variablesObject = JSON.parse(variables)
60 } catch (_e) {
61 logger.warn('Failed to parse variables string as JSON', { variables })
62 return undefined
63 }
64 }
65
66 if (Object.keys(variablesObject).length === 0) {
67 return undefined
68 }
69
70 return variablesObject
71}
72
73/**
74 * Substitutes variable placeholders in text with their actual values

Callers 1

route.tsFile · 0.85

Calls 2

parseMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected