UNPKG

mlld

Version:

mlld: a modular prompt scripting language

128 lines (126 loc) 4.16 kB
import { __name } from './chunk-OMKLS24H.mjs'; // interpreter/utils/variable-migration.ts function extractVariableValue(variable) { let value = variable.value; if (variable.type === "array" && variable.metadata?.customToString) { if (Array.isArray(value)) { Object.defineProperty(value, "toString", { value: variable.metadata.customToString, enumerable: false, configurable: true }); } } if (variable.type === "array" && variable.metadata?.customToJSON) { if (Array.isArray(value)) { Object.defineProperty(value, "toJSON", { value: variable.metadata.customToJSON, enumerable: false, configurable: true }); } } if (variable.type === "array" && variable.metadata?.contentGetter) { if (Array.isArray(value)) { Object.defineProperty(value, "content", { get: variable.metadata.contentGetter, enumerable: false, configurable: true }); } } if (value !== null && typeof value === "object") { Object.defineProperty(value, "__variable", { value: variable, enumerable: false, configurable: true, writable: false }); } return value; } __name(extractVariableValue, "extractVariableValue"); function createRenamedContentVariable(items, metadata) { return { type: "array", name: metadata?.name || "renamed-content", value: items, source: { directive: "var", syntax: "array", hasInterpolation: false, isMultiLine: false }, createdAt: Date.now(), modifiedAt: Date.now(), metadata: { arrayType: "renamed-content", joinSeparator: "\n\n", customToString: /* @__PURE__ */ __name(function() { return items.join("\n\n"); }, "customToString"), customToJSON: /* @__PURE__ */ __name(function() { return [ ...items ]; }, "customToJSON"), ...metadata } }; } __name(createRenamedContentVariable, "createRenamedContentVariable"); function createLoadContentResultVariable(items, metadata) { const toStringFunc = /* @__PURE__ */ __name(function() { return items.map((item) => item.content).join("\n\n"); }, "toStringFunc"); const toJSONFunc = /* @__PURE__ */ __name(function() { return items.map((item) => item.toJSON()); }, "toJSONFunc"); const contentGetterFunc = /* @__PURE__ */ __name(function() { return items.map((item) => item.content).join("\n\n"); }, "contentGetterFunc"); return { type: "array", name: metadata?.name || "load-content-result", value: items, source: { directive: "var", syntax: "array", hasInterpolation: false, isMultiLine: false }, createdAt: Date.now(), modifiedAt: Date.now(), metadata: { arrayType: "load-content-result", joinSeparator: "\n\n", customToString: toStringFunc, customToJSON: toJSONFunc, contentGetter: contentGetterFunc, ...metadata } }; } __name(createLoadContentResultVariable, "createLoadContentResultVariable"); function hasVariableMetadata(value) { return value !== null && typeof value === "object" && "__variable" in value && typeof value.__variable === "object"; } __name(hasVariableMetadata, "hasVariableMetadata"); function getVariableMetadata(value) { if (hasVariableMetadata(value)) { return value.__variable; } return void 0; } __name(getVariableMetadata, "getVariableMetadata"); function isRenamedContentVariable(variable) { return variable.type === "array" && variable.metadata?.arrayType === "renamed-content"; } __name(isRenamedContentVariable, "isRenamedContentVariable"); function isLoadContentResultVariable(variable) { return variable.type === "array" && variable.metadata?.arrayType === "load-content-result"; } __name(isLoadContentResultVariable, "isLoadContentResultVariable"); export { createLoadContentResultVariable, createRenamedContentVariable, extractVariableValue, getVariableMetadata, hasVariableMetadata, isLoadContentResultVariable, isRenamedContentVariable }; //# sourceMappingURL=chunk-WSDJAWOM.mjs.map //# sourceMappingURL=chunk-WSDJAWOM.mjs.map