6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
162 lines
5.4 KiB
TypeScript
162 lines
5.4 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { isLargeArrayManifest } from '@/lib/execution/payloads/large-array-manifest-metadata'
|
|
import { assertNoLargeValueRefs, isLargeValueRef } from '@/lib/execution/payloads/large-value-ref'
|
|
import { VariableManager } from '@/lib/workflows/variables/variable-manager'
|
|
import { isReference, normalizeName, parseReferencePath, REFERENCE } from '@/executor/constants'
|
|
import {
|
|
type AsyncPathNavigator,
|
|
navigatePath,
|
|
type ResolutionContext,
|
|
type Resolver,
|
|
splitLeadingBracketPath,
|
|
} from '@/executor/variables/resolvers/reference'
|
|
import type { VariableType } from '@/stores/variables/types'
|
|
|
|
const logger = createLogger('WorkflowResolver')
|
|
|
|
export class WorkflowResolver implements Resolver {
|
|
constructor(
|
|
private workflowVariables: Record<string, any>,
|
|
private navigatePathAsync?: AsyncPathNavigator
|
|
) {}
|
|
|
|
canResolve(reference: string): boolean {
|
|
if (!isReference(reference)) {
|
|
return false
|
|
}
|
|
const parts = parseReferencePath(reference)
|
|
if (parts.length === 0) {
|
|
return false
|
|
}
|
|
const [type] = parts
|
|
return type === REFERENCE.PREFIX.VARIABLE
|
|
}
|
|
|
|
resolve(reference: string, context: ResolutionContext): any {
|
|
const parts = parseReferencePath(reference)
|
|
if (parts.length < 2) {
|
|
logger.warn('Invalid variable reference - missing variable name', { reference })
|
|
return undefined
|
|
}
|
|
|
|
const [_, rawVariableName, ...rawPathParts] = parts
|
|
const { property: variableName, pathParts: bracketPathParts } =
|
|
splitLeadingBracketPath(rawVariableName)
|
|
const pathParts = [...bracketPathParts, ...rawPathParts]
|
|
const normalizedRefName = normalizeName(variableName)
|
|
|
|
const workflowVars = context.executionContext.workflowVariables || this.workflowVariables
|
|
|
|
for (const varObj of Object.values(workflowVars)) {
|
|
const v = varObj as any
|
|
if (!v) continue
|
|
|
|
// Match by normalized name or exact ID
|
|
const normalizedVarName = v.name ? normalizeName(v.name) : ''
|
|
if (normalizedVarName === normalizedRefName || v.id === variableName) {
|
|
const normalizedType = (v.type === 'string' ? 'plain' : v.type) || 'plain'
|
|
let value: any
|
|
value = this.resolveVariableValue(v.value, normalizedType, variableName)
|
|
|
|
if (pathParts.length > 0) {
|
|
return navigatePath(value, pathParts, {
|
|
allowLargeValueRefs: context.allowLargeValueRefs,
|
|
executionContext: context.executionContext,
|
|
})
|
|
}
|
|
|
|
if (!context.allowLargeValueRefs) {
|
|
assertNoLargeValueRefs(value)
|
|
}
|
|
return value
|
|
}
|
|
}
|
|
|
|
return undefined
|
|
}
|
|
|
|
async resolveAsync(reference: string, context: ResolutionContext): Promise<any> {
|
|
const parts = parseReferencePath(reference)
|
|
if (parts.length < 2) {
|
|
logger.warn('Invalid variable reference - missing variable name', { reference })
|
|
return undefined
|
|
}
|
|
|
|
const [_, rawVariableName, ...rawPathParts] = parts
|
|
const { property: variableName, pathParts: bracketPathParts } =
|
|
splitLeadingBracketPath(rawVariableName)
|
|
const pathParts = [...bracketPathParts, ...rawPathParts]
|
|
const normalizedRefName = normalizeName(variableName)
|
|
const workflowVars = context.executionContext.workflowVariables || this.workflowVariables
|
|
|
|
for (const [variableId, varObj] of Object.entries(workflowVars)) {
|
|
const v = varObj as any
|
|
if (!v) continue
|
|
|
|
const normalizedVarName = v.name ? normalizeName(v.name) : ''
|
|
if (normalizedVarName === normalizedRefName || v.id === variableName) {
|
|
const normalizedType = (v.type === 'string' ? 'plain' : v.type) || 'plain'
|
|
let value: any
|
|
value = this.resolveVariableValue(v.value, normalizedType, variableName)
|
|
|
|
if (pathParts.length > 0) {
|
|
const resolved = this.navigatePathAsync
|
|
? this.navigatePathAsync(value, pathParts, context)
|
|
: navigatePath(value, pathParts, {
|
|
allowLargeValueRefs: context.allowLargeValueRefs,
|
|
executionContext: context.executionContext,
|
|
})
|
|
return this.importResolvedVariableProvenance(variableId, await resolved, context)
|
|
}
|
|
|
|
if (!context.allowLargeValueRefs) {
|
|
assertNoLargeValueRefs(value)
|
|
}
|
|
return this.importResolvedVariableProvenance(variableId, value, context)
|
|
}
|
|
}
|
|
|
|
return undefined
|
|
}
|
|
|
|
private async importResolvedVariableProvenance(
|
|
variableId: string,
|
|
value: unknown,
|
|
context: ResolutionContext
|
|
): Promise<unknown> {
|
|
const registry = context.executionContext.resolvedSecretTraceRegistry
|
|
const provenance =
|
|
context.executionContext.workflowVariableResolvedSecretTraceProvenance?.[variableId]
|
|
if (!registry || !provenance) return value
|
|
|
|
const imported = await registry.importProvenanceForValueAtInputPath(
|
|
provenance,
|
|
value,
|
|
context.inputPath,
|
|
{ trusted: true }
|
|
)
|
|
if (imported.matched) context.onResolvedSecretReference?.()
|
|
return value
|
|
}
|
|
|
|
private resolveVariableValue(
|
|
value: any,
|
|
normalizedType: VariableType,
|
|
variableName: string
|
|
): any {
|
|
if (isLargeValueRef(value) || isLargeArrayManifest(value)) {
|
|
return value
|
|
}
|
|
|
|
try {
|
|
return VariableManager.resolveForExecution(value, normalizedType)
|
|
} catch (error) {
|
|
logger.warn('Failed to resolve workflow variable, returning raw value', {
|
|
variableName,
|
|
error: (error as Error).message,
|
|
})
|
|
return value
|
|
}
|
|
}
|
|
}
|