UNPKG

mlld

Version:

mlld: llm scripting language

145 lines (143 loc) 5.75 kB
import { isStructuredValue, asData, asText } from './chunk-CQPPOI5P.mjs'; import { isPipelineInput, isStructured, isExecutableVariable, isPrimitive, isTextLike, isPath, isImported, isComputed } from './chunk-VKEM6RSR.mjs'; import { __name } from './chunk-NJQWMXLH.mjs'; // interpreter/utils/variable-resolution.ts var ResolutionContext = /* @__PURE__ */ ((ResolutionContext2) => { ResolutionContext2["VariableAssignment"] = "variable-assignment"; ResolutionContext2["VariableCopy"] = "variable-copy"; ResolutionContext2["ArrayElement"] = "array-element"; ResolutionContext2["ObjectProperty"] = "object-property"; ResolutionContext2["FunctionArgument"] = "function-argument"; ResolutionContext2["DataStructure"] = "data-structure"; ResolutionContext2["FieldAccess"] = "field-access"; ResolutionContext2["ImportResult"] = "import-result"; ResolutionContext2["StringInterpolation"] = "string-interpolation"; ResolutionContext2["CommandExecution"] = "command-execution"; ResolutionContext2["FileOutput"] = "file-output"; ResolutionContext2["Conditional"] = "conditional"; ResolutionContext2["Display"] = "display"; ResolutionContext2["PipelineInput"] = "pipeline-input"; ResolutionContext2["Truthiness"] = "truthiness"; ResolutionContext2["Equality"] = "equality"; return ResolutionContext2; })(ResolutionContext || {}); function shouldPreserveVariable(context) { switch (context) { // Preserve Variable wrapper contexts case "variable-assignment" /* VariableAssignment */: case "variable-copy" /* VariableCopy */: case "array-element" /* ArrayElement */: case "object-property" /* ObjectProperty */: case "function-argument" /* FunctionArgument */: case "data-structure" /* DataStructure */: case "field-access" /* FieldAccess */: case "import-result" /* ImportResult */: return true; // Extract raw value contexts case "string-interpolation" /* StringInterpolation */: case "command-execution" /* CommandExecution */: case "file-output" /* FileOutput */: case "conditional" /* Conditional */: case "display" /* Display */: case "pipeline-input" /* PipelineInput */: case "truthiness" /* Truthiness */: case "equality" /* Equality */: return false; default: return false; } } __name(shouldPreserveVariable, "shouldPreserveVariable"); async function resolveVariable(variable, env, context = "display" /* Display */) { if (isPipelineInput(variable) && context === "pipeline-input" /* PipelineInput */) { return variable.value; } if (shouldPreserveVariable(context)) { if (isStructured(variable)) { const complexFlag = variable.isComplex; if (complexFlag) { const { evaluateDataValue } = await import('./data-value-evaluator-NMZLI3DJ.mjs'); const evaluatedValue = await evaluateDataValue(variable.value, env); return { ...variable, value: evaluatedValue, metadata: { ...variable.metadata, wasEvaluated: true, evaluatedAt: Date.now() } }; } } if (isExecutableVariable(variable)) { return variable; } return variable; } const extracted = await extractVariableValue(variable, env); if (!isStructuredValue(extracted)) { return extracted; } if (context === "equality" /* Equality */) { return asData(extracted); } if (context === "command-execution" /* CommandExecution */) { return asText(extracted); } return extracted; } __name(resolveVariable, "resolveVariable"); async function extractVariableValue(variable, env) { if (isPrimitive(variable)) { return variable.value; } else if (isTextLike(variable)) { return variable.value; } else if (isStructured(variable)) { const complexFlag = variable.isComplex; if (complexFlag) { const { evaluateDataValue } = await import('./data-value-evaluator-NMZLI3DJ.mjs'); const evaluatedValue = await evaluateDataValue(variable.value, env); return evaluatedValue; } if (variable.type === "array" && variable.metadata?.arrayType && (variable.metadata.arrayType === "renamed-content" || variable.metadata.arrayType === "load-content-result")) { const { extractVariableValue: extractWithBehaviors } = await import('./variable-migration-NHYVBLHS.mjs'); return extractWithBehaviors(variable); } return variable.value; } else if (isPath(variable)) { return variable.value.resolvedPath; } else if (isPipelineInput(variable)) { return variable.value; } else if (isExecutableVariable(variable)) { const { evaluateExecInvocation } = await import('./exec-invocation-YOT2VAWN.mjs'); const invocation = { type: "ExecInvocation", commandRef: { identifier: variable.name, args: [] } }; const result = await evaluateExecInvocation(invocation, env); return result.value; } else if (isImported(variable)) { return variable.value; } else if (isComputed(variable)) { return variable.value; } return variable.value; } __name(extractVariableValue, "extractVariableValue"); function isVariable(value) { return value !== null && typeof value === "object" && "type" in value && "name" in value && "value" in value && "source" in value; } __name(isVariable, "isVariable"); async function resolveValue(value, env, context) { if (isVariable(value)) { return resolveVariable(value, env, context); } return value; } __name(resolveValue, "resolveValue"); export { ResolutionContext, extractVariableValue, isVariable, resolveValue, resolveVariable, shouldPreserveVariable }; //# sourceMappingURL=chunk-AXDK3AHT.mjs.map //# sourceMappingURL=chunk-AXDK3AHT.mjs.map