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

Function resolveArrayInputAsync

apps/sim/executor/utils/subflow-utils.server.ts:76–127  ·  view source on GitHub ↗
(
  ctx: ExecutionContext,
  items: any,
  resolver: VariableResolver | null,
  currentNodeId = ''
)

Source from the content-addressed store, hash-verified

74 * execution values that cannot be imported into client-reachable utilities.
75 */
76export async function resolveArrayInputAsync(
77 ctx: ExecutionContext,
78 items: any,
79 resolver: VariableResolver | null,
80 currentNodeId = ''
81): Promise<any[]> {
82 if (typeof items !== 'string') {
83 if (items === null) {
84 return []
85 }
86 if (!Array.isArray(items) && typeof items !== 'object') {
87 if (!resolver) {
88 return []
89 }
90 try {
91 const resolved = (await resolver.resolveInputs(ctx, currentNodeId, { items })).items
92 return normalizeCollectionValue(ctx, resolved)
93 } catch (error) {
94 if (error instanceof Error && error.message.startsWith('Resolved items')) {
95 throw error
96 }
97 throw new Error(`Failed to resolve items: ${toError(error).message}`)
98 }
99 }
100 return normalizeCollectionValue(ctx, items)
101 }
102
103 if (items.startsWith(REFERENCE.START) && items.endsWith(REFERENCE.END) && resolver) {
104 try {
105 const resolved = await resolver.resolveSingleReference(ctx, currentNodeId, items, undefined, {
106 allowLargeValueRefs: true,
107 })
108 return normalizeCollectionValue(ctx, resolved)
109 } catch (error) {
110 if (error instanceof Error && error.message.startsWith('Reference "')) {
111 throw error
112 }
113 throw new Error(`Failed to resolve reference "${items}": ${toError(error).message}`)
114 }
115 }
116
117 try {
118 const normalized = items.replace(/'/g, '"')
119 const parsed = JSON.parse(normalized)
120 return normalizeCollectionValue(ctx, parsed)
121 } catch (error) {
122 if (error instanceof Error && error.message.startsWith('Parsed value')) {
123 throw error
124 }
125 throw new Error(`Failed to parse items as JSON: "${items}"`)
126 }
127}

Callers 3

initializeLoopScopeMethod · 0.90

Calls 6

toErrorFunction · 0.90
normalizeCollectionValueFunction · 0.85
resolveInputsMethod · 0.80
parseMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected