Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.3 KB
Raw Blame
import path from 'node:path'
import { assertSafeCodeNamespace, assertSafePathSegment } from '../../../utils/path-safety'

const STEP_ENTRY_FILENAME = 'index.ts'
// esbuild output for legacy (useDeno=false) steps: a self-contained CJS bundle with dependencies inlined.
const COMPILED_CODE_FILENAME = 'index.js'
// sucrase output for deno (useDeno=true) steps: CJS with imports rewritten to require(), resolved from node_modules at runtime.
const TRANSPILED_CODE_FILENAME = 'index.cjs'

export const codeCache = (codesFolderPath: string) => ({
    flowVersionDir(flowVersionId: string): string {
        assertSafeCodeNamespace(flowVersionId)
        return path.join(codesFolderPath, flowVersionId)
    },

    stepDir({ flowVersionId, stepName }: StepRef): string {
        assertSafeCodeNamespace(flowVersionId)
        assertSafePathSegment(stepName, 'stepName')
        return path.join(codesFolderPath, flowVersionId, stepName)
    },

    stepEntryPath(ref: StepRef): string {
        return path.join(this.stepDir(ref), STEP_ENTRY_FILENAME)
    },

    compiledStepPath(ref: StepRef): string {
        return path.join(this.stepDir(ref), COMPILED_CODE_FILENAME)
    },

    transpiledStepPath(ref: StepRef): string {
        return path.join(this.stepDir(ref), TRANSPILED_CODE_FILENAME)
    },
})

type StepRef = {
    flowVersionId: string
    stepName: string
}