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

Class ParallelResolver

apps/sim/executor/variables/resolvers/parallel.ts:29–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27const COLLECTION_PARALLEL_CONTEXT_FIELDS = ['index', 'currentItem', 'items'] as const
28
29export class ParallelResolver implements Resolver {
30 private parallelNameToId: Map<string, string>
31
32 constructor(
33 private workflow: SerializedWorkflow,
34 private navigatePathAsync?: AsyncPathNavigator
35 ) {
36 this.parallelNameToId = new Map()
37 for (const block of workflow.blocks) {
38 if (workflow.parallels?.[block.id] && block.metadata?.name) {
39 this.parallelNameToId.set(normalizeName(block.metadata.name), block.id)
40 }
41 }
42 }
43
44 private static OUTPUT_PROPERTIES = new Set(['result', 'results'])
45 private static KNOWN_PROPERTIES = new Set(['index', 'currentItem', 'items'])
46
47 canResolve(reference: string): boolean {
48 if (!isReference(reference)) {
49 return false
50 }
51 const parts = parseReferencePath(reference)
52 if (parts.length === 0) {
53 return false
54 }
55 const [type] = parts
56 return type === REFERENCE.PREFIX.PARALLEL || this.parallelNameToId.has(type)
57 }
58
59 resolve(reference: string, context: ResolutionContext): any {
60 return this.resolveInternal(reference, context, false)
61 }
62
63 async resolveAsync(reference: string, context: ResolutionContext): Promise<any> {
64 if (!this.navigatePathAsync) {
65 return this.resolve(reference, context)
66 }
67 return this.resolveInternal(reference, context, true)
68 }
69
70 private async resolveInternal(
71 reference: string,
72 context: ResolutionContext,
73 useAsyncPath: true
74 ): Promise<any>
75 private resolveInternal(reference: string, context: ResolutionContext, useAsyncPath: false): any
76 private resolveInternal(
77 reference: string,
78 context: ResolutionContext,
79 useAsyncPath: boolean
80 ): any | Promise<any> {
81 const parts = parseReferencePath(reference)
82 if (parts.length === 0) {
83 logger.warn('Invalid parallel reference', { reference })
84 return undefined
85 }
86

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected