UNPKG

mlld

Version:

mlld: llm scripting language

125 lines (123 loc) 4.38 kB
import { __name } from './chunk-NJQT543K.mjs'; // interpreter/eval/pipeline/detector.ts function detectPipeline(node, directive) { if (node && Array.isArray(node.pipes) && node.pipes.length > 0) { const pipeline = node.pipes.map(convertCondensedPipe); return { pipeline, source: "node-pipes", isRetryable: false // Variable pipes are not retryable }; } if (node && node.withClause && node.withClause.pipeline) { return { pipeline: node.withClause.pipeline, source: "node-withClause", format: node.withClause.format, isRetryable: node.type === "ExecInvocation", parallelCap: node.withClause.parallel, delayMs: node.withClause.delayMs }; } if (directive?.values?.withClause && directive.values.withClause.pipeline) { return { pipeline: directive.values.withClause.pipeline, source: "directive-values", format: directive.values.withClause.format, isRetryable: false, parallelCap: directive.values.withClause.parallel, delayMs: directive.values.withClause.delayMs }; } if (directive?.meta?.withClause && directive.meta.withClause.pipeline) { return { pipeline: directive.meta.withClause.pipeline, source: "directive-meta", format: directive.meta.withClause.format, isRetryable: false, parallelCap: directive.meta.withClause.parallel, delayMs: directive.meta.withClause.delayMs }; } return null; } __name(detectPipeline, "detectPipeline"); function convertCondensedPipe(pipe) { if (pipe.type === "CondensedPipe") { const transform = pipe.transform; const fields = pipe.fields ?? []; const identifierParts = transform.split("."); const baseIdentifier = identifierParts[0]; const resolvedFields = fields.length > 0 ? fields : identifierParts.slice(1); const variableRef = { type: "VariableReference", valueType: "varIdentifier", identifier: baseIdentifier }; if (resolvedFields.length > 0) { variableRef.fields = resolvedFields.map((value) => ({ type: "field", value })); } return { identifier: [ variableRef ], args: pipe.args || [], fields: resolvedFields, rawIdentifier: transform, rawArgs: pipe.args || [] }; } return pipe; } __name(convertCondensedPipe, "convertCondensedPipe"); function hasPipeline(node, directive) { return !!(node?.pipes?.length || node?.withClause?.pipeline || directive?.values?.withClause?.pipeline || directive?.meta?.withClause?.pipeline); } __name(hasPipeline, "hasPipeline"); function extractPipelineMetadata(node, directive) { const withClause = node?.withClause || directive?.values?.withClause || directive?.meta?.withClause; if (withClause) { return { pipeline: withClause.pipeline, format: withClause.format, asSection: withClause.asSection }; } if (node?.pipes?.length) { return { pipeline: node.pipes.map(convertCondensedPipe) }; } return null; } __name(extractPipelineMetadata, "extractPipelineMetadata"); function debugPipelineDetection(identifier, node, directive) { if (process.env.MLLD_DEBUG !== "true") return; console.log(` === Pipeline Detection for @${identifier} ===`); const sources = []; if (node?.pipes?.length) sources.push(`node.pipes (${node.pipes.length} pipes)`); if (node?.withClause?.pipeline) sources.push("node.withClause"); if (directive?.values?.withClause?.pipeline) sources.push("directive.values.withClause"); if (directive?.meta?.withClause?.pipeline) sources.push("directive.meta.withClause"); if (sources.length === 0) { console.log(" No pipeline found"); } else { console.log(" Pipeline sources found:", sources.join(", ")); const detected = detectPipeline(node, directive); if (detected) { console.log(" Selected source:", detected.source); console.log(" Pipeline:", detected.pipeline.map((p) => p.rawIdentifier).join(" | ")); console.log(" Format:", detected.format || "none"); console.log(" Retryable:", detected.isRetryable); } } } __name(debugPipelineDetection, "debugPipelineDetection"); export { debugPipelineDetection, detectPipeline, extractPipelineMetadata, hasPipeline }; //# sourceMappingURL=chunk-JM4XNSW2.mjs.map //# sourceMappingURL=chunk-JM4XNSW2.mjs.map