MCPcopy
hub / github.com/simstudioai/sim / WorkflowResolver

Class WorkflowResolver

apps/sim/executor/variables/resolvers/workflow.ts:17–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15const logger = createLogger('WorkflowResolver')
16
17export class WorkflowResolver implements Resolver {
18 constructor(
19 private workflowVariables: Record<string, any>,
20 private navigatePathAsync?: AsyncPathNavigator
21 ) {}
22
23 canResolve(reference: string): boolean {
24 if (!isReference(reference)) {
25 return false
26 }
27 const parts = parseReferencePath(reference)
28 if (parts.length === 0) {
29 return false
30 }
31 const [type] = parts
32 return type === REFERENCE.PREFIX.VARIABLE
33 }
34
35 resolve(reference: string, context: ResolutionContext): any {
36 const parts = parseReferencePath(reference)
37 if (parts.length < 2) {
38 logger.warn('Invalid variable reference - missing variable name', { reference })
39 return undefined
40 }
41
42 const [_, rawVariableName, ...rawPathParts] = parts
43 const { property: variableName, pathParts: bracketPathParts } =
44 splitLeadingBracketPath(rawVariableName)
45 const pathParts = [...bracketPathParts, ...rawPathParts]
46 const normalizedRefName = normalizeName(variableName)
47
48 const workflowVars = context.executionContext.workflowVariables || this.workflowVariables
49
50 for (const varObj of Object.values(workflowVars)) {
51 const v = varObj as any
52 if (!v) continue
53
54 // Match by normalized name or exact ID
55 const normalizedVarName = v.name ? normalizeName(v.name) : ''
56 if (normalizedVarName === normalizedRefName || v.id === variableName) {
57 const normalizedType = (v.type === 'string' ? 'plain' : v.type) || 'plain'
58 let value: any
59 value = this.resolveVariableValue(v.value, normalizedType, variableName)
60
61 if (pathParts.length > 0) {
62 return navigatePath(value, pathParts, {
63 allowLargeValueRefs: context.allowLargeValueRefs,
64 executionContext: context.executionContext,
65 })
66 }
67
68 if (!context.allowLargeValueRefs) {
69 assertNoLargeValueRefs(value)
70 }
71 return value
72 }
73 }
74

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected