UNPKG

agentswarm

Version:

LLM-agnostic typescript framework for creating OpenAI-style Swarm agents with the Vercel AI SDK

1,680 lines (1,672 loc) 593 kB
import { createRequire } from "node:module"; var __create = Object.create; var __getProtoOf = Object.getPrototypeOf; var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __toESM = (mod, isNodeMode, target) => { target = mod != null ? __create(__getProtoOf(mod)) : {}; const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target; for (let key of __getOwnPropNames(mod)) if (!__hasOwnProp.call(to, key)) __defProp(to, key, { get: () => mod[key], enumerable: true }); return to; }; var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports); var __require = /* @__PURE__ */ createRequire(import.meta.url); // node_modules/nunjucks/src/lib.js var require_lib = __commonJS((exports, module) => { var ArrayProto = Array.prototype; var ObjProto = Object.prototype; var escapeMap = { "&": "&amp;", '"': "&quot;", "'": "&#39;", "<": "&lt;", ">": "&gt;", "\\": "&#92;" }; var escapeRegex = /[&"'<>\\]/g; var _exports = module.exports = {}; function hasOwnProp(obj, k) { return ObjProto.hasOwnProperty.call(obj, k); } _exports.hasOwnProp = hasOwnProp; function lookupEscape(ch) { return escapeMap[ch]; } function _prettifyError(path, withInternals, err) { if (!err.Update) { err = new _exports.TemplateError(err); } err.Update(path); if (!withInternals) { var old = err; err = new Error(old.message); err.name = old.name; } return err; } _exports._prettifyError = _prettifyError; function TemplateError(message, lineno, colno) { var err; var cause; if (message instanceof Error) { cause = message; message = cause.name + ": " + cause.message; } if (Object.setPrototypeOf) { err = new Error(message); Object.setPrototypeOf(err, TemplateError.prototype); } else { err = this; Object.defineProperty(err, "message", { enumerable: false, writable: true, value: message }); } Object.defineProperty(err, "name", { value: "Template render error" }); if (Error.captureStackTrace) { Error.captureStackTrace(err, this.constructor); } var getStack; if (cause) { var stackDescriptor = Object.getOwnPropertyDescriptor(cause, "stack"); getStack = stackDescriptor && (stackDescriptor.get || function() { return stackDescriptor.value; }); if (!getStack) { getStack = function getStack() { return cause.stack; }; } } else { var stack = new Error(message).stack; getStack = function getStack() { return stack; }; } Object.defineProperty(err, "stack", { get: function get() { return getStack.call(err); } }); Object.defineProperty(err, "cause", { value: cause }); err.lineno = lineno; err.colno = colno; err.firstUpdate = true; err.Update = function Update(path) { var msg = "(" + (path || "unknown path") + ")"; if (this.firstUpdate) { if (this.lineno && this.colno) { msg += " [Line " + this.lineno + ", Column " + this.colno + "]"; } else if (this.lineno) { msg += " [Line " + this.lineno + "]"; } } msg += ` `; if (this.firstUpdate) { msg += " "; } this.message = msg + (this.message || ""); this.firstUpdate = false; return this; }; return err; } if (Object.setPrototypeOf) { Object.setPrototypeOf(TemplateError.prototype, Error.prototype); } else { TemplateError.prototype = Object.create(Error.prototype, { constructor: { value: TemplateError } }); } _exports.TemplateError = TemplateError; function escape(val) { return val.replace(escapeRegex, lookupEscape); } _exports.escape = escape; function isFunction(obj) { return ObjProto.toString.call(obj) === "[object Function]"; } _exports.isFunction = isFunction; function isArray(obj) { return ObjProto.toString.call(obj) === "[object Array]"; } _exports.isArray = isArray; function isString(obj) { return ObjProto.toString.call(obj) === "[object String]"; } _exports.isString = isString; function isObject(obj) { return ObjProto.toString.call(obj) === "[object Object]"; } _exports.isObject = isObject; function _prepareAttributeParts(attr) { if (!attr) { return []; } if (typeof attr === "string") { return attr.split("."); } return [attr]; } function getAttrGetter(attribute) { var parts = _prepareAttributeParts(attribute); return function attrGetter(item) { var _item = item; for (var i = 0;i < parts.length; i++) { var part = parts[i]; if (hasOwnProp(_item, part)) { _item = _item[part]; } else { return; } } return _item; }; } _exports.getAttrGetter = getAttrGetter; function groupBy(obj, val, throwOnUndefined) { var result = {}; var iterator = isFunction(val) ? val : getAttrGetter(val); for (var i = 0;i < obj.length; i++) { var value = obj[i]; var key = iterator(value, i); if (key === undefined && throwOnUndefined === true) { throw new TypeError('groupby: attribute "' + val + '" resolved to undefined'); } (result[key] || (result[key] = [])).push(value); } return result; } _exports.groupBy = groupBy; function toArray(obj) { return Array.prototype.slice.call(obj); } _exports.toArray = toArray; function without(array) { var result = []; if (!array) { return result; } var length = array.length; var contains = toArray(arguments).slice(1); var index = -1; while (++index < length) { if (indexOf(contains, array[index]) === -1) { result.push(array[index]); } } return result; } _exports.without = without; function repeat(char_, n) { var str = ""; for (var i = 0;i < n; i++) { str += char_; } return str; } _exports.repeat = repeat; function each(obj, func, context) { if (obj == null) { return; } if (ArrayProto.forEach && obj.forEach === ArrayProto.forEach) { obj.forEach(func, context); } else if (obj.length === +obj.length) { for (var i = 0, l = obj.length;i < l; i++) { func.call(context, obj[i], i, obj); } } } _exports.each = each; function map(obj, func) { var results = []; if (obj == null) { return results; } if (ArrayProto.map && obj.map === ArrayProto.map) { return obj.map(func); } for (var i = 0;i < obj.length; i++) { results[results.length] = func(obj[i], i); } if (obj.length === +obj.length) { results.length = obj.length; } return results; } _exports.map = map; function asyncIter(arr, iter, cb) { var i = -1; function next() { i++; if (i < arr.length) { iter(arr[i], i, next, cb); } else { cb(); } } next(); } _exports.asyncIter = asyncIter; function asyncFor(obj, iter, cb) { var keys = keys_(obj || {}); var len = keys.length; var i = -1; function next() { i++; var k = keys[i]; if (i < len) { iter(k, obj[k], i, len, next); } else { cb(); } } next(); } _exports.asyncFor = asyncFor; function indexOf(arr, searchElement, fromIndex) { return Array.prototype.indexOf.call(arr || [], searchElement, fromIndex); } _exports.indexOf = indexOf; function keys_(obj) { var arr = []; for (var k in obj) { if (hasOwnProp(obj, k)) { arr.push(k); } } return arr; } _exports.keys = keys_; function _entries(obj) { return keys_(obj).map(function(k) { return [k, obj[k]]; }); } _exports._entries = _entries; function _values(obj) { return keys_(obj).map(function(k) { return obj[k]; }); } _exports._values = _values; function extend(obj1, obj2) { obj1 = obj1 || {}; keys_(obj2).forEach(function(k) { obj1[k] = obj2[k]; }); return obj1; } _exports._assign = _exports.extend = extend; function inOperator(key, val) { if (isArray(val) || isString(val)) { return val.indexOf(key) !== -1; } else if (isObject(val)) { return key in val; } throw new Error('Cannot use "in" operator to search for "' + key + '" in unexpected types.'); } _exports.inOperator = inOperator; }); // node_modules/asap/raw.js var require_raw = __commonJS((exports, module) => { var domain; var hasSetImmediate = typeof setImmediate === "function"; module.exports = rawAsap; function rawAsap(task) { if (!queue.length) { requestFlush(); flushing = true; } queue[queue.length] = task; } var queue = []; var flushing = false; var index = 0; var capacity = 1024; function flush() { while (index < queue.length) { var currentIndex = index; index = index + 1; queue[currentIndex].call(); if (index > capacity) { for (var scan = 0, newLength = queue.length - index;scan < newLength; scan++) { queue[scan] = queue[scan + index]; } queue.length -= index; index = 0; } } queue.length = 0; index = 0; flushing = false; } rawAsap.requestFlush = requestFlush; function requestFlush() { var parentDomain = process.domain; if (parentDomain) { if (!domain) { domain = __require("domain"); } domain.active = process.domain = null; } if (flushing && hasSetImmediate) { setImmediate(flush); } else { process.nextTick(flush); } if (parentDomain) { domain.active = process.domain = parentDomain; } } }); // node_modules/asap/asap.js var require_asap = __commonJS((exports, module) => { var rawAsap = require_raw(); var freeTasks = []; module.exports = asap; function asap(task) { var rawTask; if (freeTasks.length) { rawTask = freeTasks.pop(); } else { rawTask = new RawTask; } rawTask.task = task; rawTask.domain = process.domain; rawAsap(rawTask); } function RawTask() { this.task = null; this.domain = null; } RawTask.prototype.call = function() { if (this.domain) { this.domain.enter(); } var threw = true; try { this.task.call(); threw = false; if (this.domain) { this.domain.exit(); } } finally { if (threw) { rawAsap.requestFlush(); } this.task = null; this.domain = null; freeTasks.push(this); } }; }); // node_modules/a-sync-waterfall/index.js var require_a_sync_waterfall = __commonJS((exports, module) => { (function(globals) { var executeSync = function() { var args = Array.prototype.slice.call(arguments); if (typeof args[0] === "function") { args[0].apply(null, args.splice(1)); } }; var executeAsync = function(fn) { if (typeof setImmediate === "function") { setImmediate(fn); } else if (typeof process !== "undefined" && process.nextTick) { process.nextTick(fn); } else { setTimeout(fn, 0); } }; var makeIterator = function(tasks) { var makeCallback = function(index) { var fn = function() { if (tasks.length) { tasks[index].apply(null, arguments); } return fn.next(); }; fn.next = function() { return index < tasks.length - 1 ? makeCallback(index + 1) : null; }; return fn; }; return makeCallback(0); }; var _isArray = Array.isArray || function(maybeArray) { return Object.prototype.toString.call(maybeArray) === "[object Array]"; }; var waterfall = function(tasks, callback, forceAsync) { var nextTick = forceAsync ? executeAsync : executeSync; callback = callback || function() { }; if (!_isArray(tasks)) { var err = new Error("First argument to waterfall must be an array of functions"); return callback(err); } if (!tasks.length) { return callback(); } var wrapIterator = function(iterator) { return function(err2) { if (err2) { callback.apply(null, arguments); callback = function() { }; } else { var args = Array.prototype.slice.call(arguments, 1); var next = iterator.next(); if (next) { args.push(wrapIterator(next)); } else { args.push(callback); } nextTick(function() { iterator.apply(null, args); }); } }; }; wrapIterator(makeIterator(tasks))(); }; if (typeof define !== "undefined" && define.amd) { define([], function() { return waterfall; }); } else if (typeof module !== "undefined" && module.exports) { module.exports = waterfall; } else { globals.waterfall = waterfall; } })(exports); }); // node_modules/nunjucks/src/lexer.js var require_lexer = __commonJS((exports, module) => { var lib = require_lib(); var whitespaceChars = ` \t\r `; var delimChars = "()[]{}%*-+~/#,:|.<>=!"; var intChars = "0123456789"; var BLOCK_START = "{%"; var BLOCK_END = "%}"; var VARIABLE_START = "{{"; var VARIABLE_END = "}}"; var COMMENT_START = "{#"; var COMMENT_END = "#}"; var TOKEN_STRING = "string"; var TOKEN_WHITESPACE = "whitespace"; var TOKEN_DATA = "data"; var TOKEN_BLOCK_START = "block-start"; var TOKEN_BLOCK_END = "block-end"; var TOKEN_VARIABLE_START = "variable-start"; var TOKEN_VARIABLE_END = "variable-end"; var TOKEN_COMMENT = "comment"; var TOKEN_LEFT_PAREN = "left-paren"; var TOKEN_RIGHT_PAREN = "right-paren"; var TOKEN_LEFT_BRACKET = "left-bracket"; var TOKEN_RIGHT_BRACKET = "right-bracket"; var TOKEN_LEFT_CURLY = "left-curly"; var TOKEN_RIGHT_CURLY = "right-curly"; var TOKEN_OPERATOR = "operator"; var TOKEN_COMMA = "comma"; var TOKEN_COLON = "colon"; var TOKEN_TILDE = "tilde"; var TOKEN_PIPE = "pipe"; var TOKEN_INT = "int"; var TOKEN_FLOAT = "float"; var TOKEN_BOOLEAN = "boolean"; var TOKEN_NONE = "none"; var TOKEN_SYMBOL = "symbol"; var TOKEN_SPECIAL = "special"; var TOKEN_REGEX = "regex"; function token(type, value, lineno, colno) { return { type, value, lineno, colno }; } var Tokenizer = /* @__PURE__ */ function() { function Tokenizer2(str, opts) { this.str = str; this.index = 0; this.len = str.length; this.lineno = 0; this.colno = 0; this.in_code = false; opts = opts || {}; var tags = opts.tags || {}; this.tags = { BLOCK_START: tags.blockStart || BLOCK_START, BLOCK_END: tags.blockEnd || BLOCK_END, VARIABLE_START: tags.variableStart || VARIABLE_START, VARIABLE_END: tags.variableEnd || VARIABLE_END, COMMENT_START: tags.commentStart || COMMENT_START, COMMENT_END: tags.commentEnd || COMMENT_END }; this.trimBlocks = !!opts.trimBlocks; this.lstripBlocks = !!opts.lstripBlocks; } var _proto = Tokenizer2.prototype; _proto.nextToken = function nextToken() { var lineno = this.lineno; var colno = this.colno; var tok; if (this.in_code) { var cur = this.current(); if (this.isFinished()) { return null; } else if (cur === '"' || cur === "'") { return token(TOKEN_STRING, this._parseString(cur), lineno, colno); } else if (tok = this._extract(whitespaceChars)) { return token(TOKEN_WHITESPACE, tok, lineno, colno); } else if ((tok = this._extractString(this.tags.BLOCK_END)) || (tok = this._extractString("-" + this.tags.BLOCK_END))) { this.in_code = false; if (this.trimBlocks) { cur = this.current(); if (cur === ` `) { this.forward(); } else if (cur === "\r") { this.forward(); cur = this.current(); if (cur === ` `) { this.forward(); } else { this.back(); } } } return token(TOKEN_BLOCK_END, tok, lineno, colno); } else if ((tok = this._extractString(this.tags.VARIABLE_END)) || (tok = this._extractString("-" + this.tags.VARIABLE_END))) { this.in_code = false; return token(TOKEN_VARIABLE_END, tok, lineno, colno); } else if (cur === "r" && this.str.charAt(this.index + 1) === "/") { this.forwardN(2); var regexBody = ""; while (!this.isFinished()) { if (this.current() === "/" && this.previous() !== "\\") { this.forward(); break; } else { regexBody += this.current(); this.forward(); } } var POSSIBLE_FLAGS = ["g", "i", "m", "y"]; var regexFlags = ""; while (!this.isFinished()) { var isCurrentAFlag = POSSIBLE_FLAGS.indexOf(this.current()) !== -1; if (isCurrentAFlag) { regexFlags += this.current(); this.forward(); } else { break; } } return token(TOKEN_REGEX, { body: regexBody, flags: regexFlags }, lineno, colno); } else if (delimChars.indexOf(cur) !== -1) { this.forward(); var complexOps = ["==", "===", "!=", "!==", "<=", ">=", "//", "**"]; var curComplex = cur + this.current(); var type; if (lib.indexOf(complexOps, curComplex) !== -1) { this.forward(); cur = curComplex; if (lib.indexOf(complexOps, curComplex + this.current()) !== -1) { cur = curComplex + this.current(); this.forward(); } } switch (cur) { case "(": type = TOKEN_LEFT_PAREN; break; case ")": type = TOKEN_RIGHT_PAREN; break; case "[": type = TOKEN_LEFT_BRACKET; break; case "]": type = TOKEN_RIGHT_BRACKET; break; case "{": type = TOKEN_LEFT_CURLY; break; case "}": type = TOKEN_RIGHT_CURLY; break; case ",": type = TOKEN_COMMA; break; case ":": type = TOKEN_COLON; break; case "~": type = TOKEN_TILDE; break; case "|": type = TOKEN_PIPE; break; default: type = TOKEN_OPERATOR; } return token(type, cur, lineno, colno); } else { tok = this._extractUntil(whitespaceChars + delimChars); if (tok.match(/^[-+]?[0-9]+$/)) { if (this.current() === ".") { this.forward(); var dec = this._extract(intChars); return token(TOKEN_FLOAT, tok + "." + dec, lineno, colno); } else { return token(TOKEN_INT, tok, lineno, colno); } } else if (tok.match(/^(true|false)$/)) { return token(TOKEN_BOOLEAN, tok, lineno, colno); } else if (tok === "none") { return token(TOKEN_NONE, tok, lineno, colno); } else if (tok === "null") { return token(TOKEN_NONE, tok, lineno, colno); } else if (tok) { return token(TOKEN_SYMBOL, tok, lineno, colno); } else { throw new Error("Unexpected value while parsing: " + tok); } } } else { var beginChars = this.tags.BLOCK_START.charAt(0) + this.tags.VARIABLE_START.charAt(0) + this.tags.COMMENT_START.charAt(0) + this.tags.COMMENT_END.charAt(0); if (this.isFinished()) { return null; } else if ((tok = this._extractString(this.tags.BLOCK_START + "-")) || (tok = this._extractString(this.tags.BLOCK_START))) { this.in_code = true; return token(TOKEN_BLOCK_START, tok, lineno, colno); } else if ((tok = this._extractString(this.tags.VARIABLE_START + "-")) || (tok = this._extractString(this.tags.VARIABLE_START))) { this.in_code = true; return token(TOKEN_VARIABLE_START, tok, lineno, colno); } else { tok = ""; var data; var inComment = false; if (this._matches(this.tags.COMMENT_START)) { inComment = true; tok = this._extractString(this.tags.COMMENT_START); } while ((data = this._extractUntil(beginChars)) !== null) { tok += data; if ((this._matches(this.tags.BLOCK_START) || this._matches(this.tags.VARIABLE_START) || this._matches(this.tags.COMMENT_START)) && !inComment) { if (this.lstripBlocks && this._matches(this.tags.BLOCK_START) && this.colno > 0 && this.colno <= tok.length) { var lastLine = tok.slice(-this.colno); if (/^\s+$/.test(lastLine)) { tok = tok.slice(0, -this.colno); if (!tok.length) { return this.nextToken(); } } } break; } else if (this._matches(this.tags.COMMENT_END)) { if (!inComment) { throw new Error("unexpected end of comment"); } tok += this._extractString(this.tags.COMMENT_END); break; } else { tok += this.current(); this.forward(); } } if (data === null && inComment) { throw new Error("expected end of comment, got end of file"); } return token(inComment ? TOKEN_COMMENT : TOKEN_DATA, tok, lineno, colno); } } }; _proto._parseString = function _parseString(delimiter) { this.forward(); var str = ""; while (!this.isFinished() && this.current() !== delimiter) { var cur = this.current(); if (cur === "\\") { this.forward(); switch (this.current()) { case "n": str += ` `; break; case "t": str += "\t"; break; case "r": str += "\r"; break; default: str += this.current(); } this.forward(); } else { str += cur; this.forward(); } } this.forward(); return str; }; _proto._matches = function _matches(str) { if (this.index + str.length > this.len) { return null; } var m = this.str.slice(this.index, this.index + str.length); return m === str; }; _proto._extractString = function _extractString(str) { if (this._matches(str)) { this.forwardN(str.length); return str; } return null; }; _proto._extractUntil = function _extractUntil(charString) { return this._extractMatching(true, charString || ""); }; _proto._extract = function _extract(charString) { return this._extractMatching(false, charString); }; _proto._extractMatching = function _extractMatching(breakOnMatch, charString) { if (this.isFinished()) { return null; } var first = charString.indexOf(this.current()); if (breakOnMatch && first === -1 || !breakOnMatch && first !== -1) { var t = this.current(); this.forward(); var idx = charString.indexOf(this.current()); while ((breakOnMatch && idx === -1 || !breakOnMatch && idx !== -1) && !this.isFinished()) { t += this.current(); this.forward(); idx = charString.indexOf(this.current()); } return t; } return ""; }; _proto._extractRegex = function _extractRegex(regex) { var matches = this.currentStr().match(regex); if (!matches) { return null; } this.forwardN(matches[0].length); return matches; }; _proto.isFinished = function isFinished() { return this.index >= this.len; }; _proto.forwardN = function forwardN(n) { for (var i = 0;i < n; i++) { this.forward(); } }; _proto.forward = function forward() { this.index++; if (this.previous() === ` `) { this.lineno++; this.colno = 0; } else { this.colno++; } }; _proto.backN = function backN(n) { for (var i = 0;i < n; i++) { this.back(); } }; _proto.back = function back() { this.index--; if (this.current() === ` `) { this.lineno--; var idx = this.src.lastIndexOf(` `, this.index - 1); if (idx === -1) { this.colno = this.index; } else { this.colno = this.index - idx; } } else { this.colno--; } }; _proto.current = function current() { if (!this.isFinished()) { return this.str.charAt(this.index); } return ""; }; _proto.currentStr = function currentStr() { if (!this.isFinished()) { return this.str.substr(this.index); } return ""; }; _proto.previous = function previous() { return this.str.charAt(this.index - 1); }; return Tokenizer2; }(); module.exports = { lex: function lex(src, opts) { return new Tokenizer(src, opts); }, TOKEN_STRING, TOKEN_WHITESPACE, TOKEN_DATA, TOKEN_BLOCK_START, TOKEN_BLOCK_END, TOKEN_VARIABLE_START, TOKEN_VARIABLE_END, TOKEN_COMMENT, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_LEFT_CURLY, TOKEN_RIGHT_CURLY, TOKEN_OPERATOR, TOKEN_COMMA, TOKEN_COLON, TOKEN_TILDE, TOKEN_PIPE, TOKEN_INT, TOKEN_FLOAT, TOKEN_BOOLEAN, TOKEN_NONE, TOKEN_SYMBOL, TOKEN_SPECIAL, TOKEN_REGEX }; }); // node_modules/nunjucks/src/object.js var require_object = __commonJS((exports, module) => { function _defineProperties(target, props) { for (var i = 0;i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o2, p2) { o2.__proto__ = p2; return o2; }; return _setPrototypeOf(o, p); } var EventEmitter = __require("events"); var lib = require_lib(); function parentWrap(parent, prop) { if (typeof parent !== "function" || typeof prop !== "function") { return prop; } return function wrap() { var tmp = this.parent; this.parent = parent; var res = prop.apply(this, arguments); this.parent = tmp; return res; }; } function extendClass(cls, name, props) { props = props || {}; lib.keys(props).forEach(function(k) { props[k] = parentWrap(cls.prototype[k], props[k]); }); var subclass = /* @__PURE__ */ function(_cls) { _inheritsLoose(subclass2, _cls); function subclass2() { return _cls.apply(this, arguments) || this; } _createClass(subclass2, [{ key: "typename", get: function get() { return name; } }]); return subclass2; }(cls); lib._assign(subclass.prototype, props); return subclass; } var Obj = /* @__PURE__ */ function() { function Obj2() { this.init.apply(this, arguments); } var _proto = Obj2.prototype; _proto.init = function init() { }; Obj2.extend = function extend(name, props) { if (typeof name === "object") { props = name; name = "anonymous"; } return extendClass(this, name, props); }; _createClass(Obj2, [{ key: "typename", get: function get() { return this.constructor.name; } }]); return Obj2; }(); var EmitterObj = /* @__PURE__ */ function(_EventEmitter) { _inheritsLoose(EmitterObj2, _EventEmitter); function EmitterObj2() { var _this2; var _this; _this = _EventEmitter.call(this) || this; (_this2 = _this).init.apply(_this2, arguments); return _this; } var _proto2 = EmitterObj2.prototype; _proto2.init = function init() { }; EmitterObj2.extend = function extend(name, props) { if (typeof name === "object") { props = name; name = "anonymous"; } return extendClass(this, name, props); }; _createClass(EmitterObj2, [{ key: "typename", get: function get() { return this.constructor.name; } }]); return EmitterObj2; }(EventEmitter); module.exports = { Obj, EmitterObj }; }); // node_modules/nunjucks/src/nodes.js var require_nodes = __commonJS((exports, module) => { function _defineProperties(target, props) { for (var i = 0;i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o2, p2) { o2.__proto__ = p2; return o2; }; return _setPrototypeOf(o, p); } var _require = require_object(); var Obj = _require.Obj; function traverseAndCheck(obj, type, results) { if (obj instanceof type) { results.push(obj); } if (obj instanceof Node) { obj.findAll(type, results); } } var Node = /* @__PURE__ */ function(_Obj) { _inheritsLoose(Node2, _Obj); function Node2() { return _Obj.apply(this, arguments) || this; } var _proto = Node2.prototype; _proto.init = function init(lineno, colno) { var _arguments = arguments, _this = this; for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2;_key < _len; _key++) { args[_key - 2] = arguments[_key]; } this.lineno = lineno; this.colno = colno; this.fields.forEach(function(field, i) { var val = _arguments[i + 2]; if (val === undefined) { val = null; } _this[field] = val; }); }; _proto.findAll = function findAll(type, results) { var _this2 = this; results = results || []; if (this instanceof NodeList) { this.children.forEach(function(child) { return traverseAndCheck(child, type, results); }); } else { this.fields.forEach(function(field) { return traverseAndCheck(_this2[field], type, results); }); } return results; }; _proto.iterFields = function iterFields(func) { var _this3 = this; this.fields.forEach(function(field) { func(_this3[field], field); }); }; return Node2; }(Obj); var Value = /* @__PURE__ */ function(_Node) { _inheritsLoose(Value2, _Node); function Value2() { return _Node.apply(this, arguments) || this; } _createClass(Value2, [{ key: "typename", get: function get() { return "Value"; } }, { key: "fields", get: function get() { return ["value"]; } }]); return Value2; }(Node); var NodeList = /* @__PURE__ */ function(_Node2) { _inheritsLoose(NodeList2, _Node2); function NodeList2() { return _Node2.apply(this, arguments) || this; } var _proto2 = NodeList2.prototype; _proto2.init = function init(lineno, colno, nodes) { _Node2.prototype.init.call(this, lineno, colno, nodes || []); }; _proto2.addChild = function addChild(node) { this.children.push(node); }; _createClass(NodeList2, [{ key: "typename", get: function get() { return "NodeList"; } }, { key: "fields", get: function get() { return ["children"]; } }]); return NodeList2; }(Node); var Root = NodeList.extend("Root"); var Literal = Value.extend("Literal"); var _Symbol = Value.extend("Symbol"); var Group = NodeList.extend("Group"); var ArrayNode = NodeList.extend("Array"); var Pair = Node.extend("Pair", { fields: ["key", "value"] }); var Dict = NodeList.extend("Dict"); var LookupVal = Node.extend("LookupVal", { fields: ["target", "val"] }); var If = Node.extend("If", { fields: ["cond", "body", "else_"] }); var IfAsync = If.extend("IfAsync"); var InlineIf = Node.extend("InlineIf", { fields: ["cond", "body", "else_"] }); var For = Node.extend("For", { fields: ["arr", "name", "body", "else_"] }); var AsyncEach = For.extend("AsyncEach"); var AsyncAll = For.extend("AsyncAll"); var Macro = Node.extend("Macro", { fields: ["name", "args", "body"] }); var Caller = Macro.extend("Caller"); var Import = Node.extend("Import", { fields: ["template", "target", "withContext"] }); var FromImport = /* @__PURE__ */ function(_Node3) { _inheritsLoose(FromImport2, _Node3); function FromImport2() { return _Node3.apply(this, arguments) || this; } var _proto3 = FromImport2.prototype; _proto3.init = function init(lineno, colno, template, names, withContext) { _Node3.prototype.init.call(this, lineno, colno, template, names || new NodeList, withContext); }; _createClass(FromImport2, [{ key: "typename", get: function get() { return "FromImport"; } }, { key: "fields", get: function get() { return ["template", "names", "withContext"]; } }]); return FromImport2; }(Node); var FunCall = Node.extend("FunCall", { fields: ["name", "args"] }); var Filter = FunCall.extend("Filter"); var FilterAsync = Filter.extend("FilterAsync", { fields: ["name", "args", "symbol"] }); var KeywordArgs = Dict.extend("KeywordArgs"); var Block = Node.extend("Block", { fields: ["name", "body"] }); var Super = Node.extend("Super", { fields: ["blockName", "symbol"] }); var TemplateRef = Node.extend("TemplateRef", { fields: ["template"] }); var Extends = TemplateRef.extend("Extends"); var Include = Node.extend("Include", { fields: ["template", "ignoreMissing"] }); var Set2 = Node.extend("Set", { fields: ["targets", "value"] }); var Switch = Node.extend("Switch", { fields: ["expr", "cases", "default"] }); var Case = Node.extend("Case", { fields: ["cond", "body"] }); var Output = NodeList.extend("Output"); var Capture = Node.extend("Capture", { fields: ["body"] }); var TemplateData = Literal.extend("TemplateData"); var UnaryOp = Node.extend("UnaryOp", { fields: ["target"] }); var BinOp = Node.extend("BinOp", { fields: ["left", "right"] }); var In = BinOp.extend("In"); var Is = BinOp.extend("Is"); var Or = BinOp.extend("Or"); var And = BinOp.extend("And"); var Not = UnaryOp.extend("Not"); var Add = BinOp.extend("Add"); var Concat = BinOp.extend("Concat"); var Sub = BinOp.extend("Sub"); var Mul = BinOp.extend("Mul"); var Div = BinOp.extend("Div"); var FloorDiv = BinOp.extend("FloorDiv"); var Mod = BinOp.extend("Mod"); var Pow = BinOp.extend("Pow"); var Neg = UnaryOp.extend("Neg"); var Pos = UnaryOp.extend("Pos"); var Compare = Node.extend("Compare", { fields: ["expr", "ops"] }); var CompareOperand = Node.extend("CompareOperand", { fields: ["expr", "type"] }); var CallExtension = Node.extend("CallExtension", { init: function init(ext, prop, args, contentArgs) { this.parent(); this.extName = ext.__name || ext; this.prop = prop; this.args = args || new NodeList; this.contentArgs = contentArgs || []; this.autoescape = ext.autoescape; }, fields: ["extName", "prop", "args", "contentArgs"] }); var CallExtensionAsync = CallExtension.extend("CallExtensionAsync"); function print(str, indent, inline) { var lines = str.split(` `); lines.forEach(function(line, i) { if (line && (inline && i > 0 || !inline)) { process.stdout.write(" ".repeat(indent)); } var nl = i === lines.length - 1 ? "" : ` `; process.stdout.write("" + line + nl); }); } function printNodes(node, indent) { indent = indent || 0; print(node.typename + ": ", indent); if (node instanceof NodeList) { print(` `); node.children.forEach(function(n) { printNodes(n, indent + 2); }); } else if (node instanceof CallExtension) { print(node.extName + "." + node.prop + ` `); if (node.args) { printNodes(node.args, indent + 2); } if (node.contentArgs) { node.contentArgs.forEach(function(n) { printNodes(n, indent + 2); }); } } else { var nodes = []; var props = null; node.iterFields(function(val, fieldName) { if (val instanceof Node) { nodes.push([fieldName, val]); } else { props = props || {}; props[fieldName] = val; } }); if (props) { print(JSON.stringify(props, null, 2) + ` `, null, true); } else { print(` `); } nodes.forEach(function(_ref) { var fieldName = _ref[0], n = _ref[1]; print("[" + fieldName + "] =>", indent + 2); printNodes(n, indent + 4); }); } } module.exports = { Node, Root, NodeList, Value, Literal, Symbol: _Symbol, Group, Array: ArrayNode, Pair, Dict, Output, Capture, TemplateData, If, IfAsync, InlineIf, For, AsyncEach, AsyncAll, Macro, Caller, Import, FromImport, FunCall, Filter, FilterAsync, KeywordArgs, Block, Super, Extends, Include, Set: Set2, Switch, Case, LookupVal, BinOp, In, Is, Or, And, Not, Add, Concat, Sub, Mul, Div, FloorDiv, Mod, Pow, Neg, Pos, Compare, CompareOperand, CallExtension, CallExtensionAsync, printNodes }; }); // node_modules/nunjucks/src/parser.js var require_parser = __commonJS((exports, module) => { function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o2, p2) { o2.__proto__ = p2; return o2; }; return _setPrototypeOf(o, p); } var lexer = require_lexer(); var nodes = require_nodes(); var Obj = require_object().Obj; var lib = require_lib(); var Parser = /* @__PURE__ */ function(_Obj) { _inheritsLoose(Parser2, _Obj); function Parser2() { return _Obj.apply(this, arguments) || this; } var _proto = Parser2.prototype; _proto.init = function init(tokens) { this.tokens = tokens; this.peeked = null; this.breakOnBlocks = null; this.dropLeadingWhitespace = false; this.extensions = []; }; _proto.nextToken = function nextToken(withWhitespace) { var tok; if (this.peeked) { if (!withWhitespace && this.peeked.type === lexer.TOKEN_WHITESPACE) { this.peeked = null; } else { tok = this.peeked; this.peeked = null; return tok; } } tok = this.tokens.nextToken(); if (!withWhitespace) { while (tok && tok.type === lexer.TOKEN_WHITESPACE) { tok = this.tokens.nextToken(); } } return tok; }; _proto.peekToken = function peekToken() { this.peeked = this.peeked || this.nextToken(); return this.peeked; }; _proto.pushToken = function pushToken(tok) { if (this.peeked) { throw new Error("pushToken: can only push one token on between reads"); } this.peeked = tok; }; _proto.error = function error(msg, lineno, colno) { if (lineno === undefined || colno === undefined) { var tok = this.peekToken() || {}; lineno = tok.lineno; colno = tok.colno; } if (lineno !== undefined) { lineno += 1; } if (colno !== undefined) { colno += 1; } return new lib.TemplateError(msg, lineno, colno); }; _proto.fail = function fail(msg, lineno, colno) { throw this.error(msg, lineno, colno); }; _proto.skip = function skip(type) { var tok = this.nextToken(); if (!tok || tok.type !== type) { this.pushToken(tok); return false; } return true; }; _proto.expect = function expect(type) { var tok = this.nextToken(); if (tok.type !== type) { this.fail("expected " + type + ", got " + tok.type, tok.lineno, tok.colno); } return tok; }; _proto.skipValue = function skipValue(type, val) { var tok = this.nextToken(); if (!tok || tok.type !== type || tok.value !== val) { this.pushToken(tok); return false; } return true; }; _proto.skipSymbol = function skipSymbol(val) { return this.skipValue(lexer.TOKEN_SYMBOL, val); }; _proto.advanceAfterBlockEnd = function advanceAfterBlockEnd(name) { var tok; if (!name) { tok = this.peekToken(); if (!tok) { this.fail("unexpected end of file"); } if (tok.type !== lexer.TOKEN_SYMBOL) { this.fail("advanceAfterBlockEnd: expected symbol token or " + "explicit name to be passed"); } name = this.nextToken().value; } tok = this.nextToken(); if (tok && tok.type === lexer.TOKEN_BLOCK_END) { if (tok.value.charAt(0) === "-") { this.dropLeadingWhitespace = true; } } else { this.fail("expected block end in " + name + " statement"); } return tok; }; _proto.advanceAfterVariableEnd = function advanceAfterVariableEnd() { var tok = this.nextToken(); if (tok && tok.type === lexer.TOKEN_VARIABLE_END) { this.dropLeadingWhitespace = tok.value.charAt(tok.value.length - this.tokens.tags.VARIABLE_END.length - 1) === "-"; } else { this.pushToken(tok); this.fail("expected variable end"); } }; _proto.parseFor = function parseFor() { var forTok = this.peekToken(); var node; var endBlock; if (this.skipSymbol("for")) { node = new nodes.For(forTok.lineno, forTok.colno); endBlock = "endfor"; } else if (this.skipSymbol("asyncEach")) { node = new nodes.AsyncEach(forTok.lineno, forTok.colno); endBlock = "endeach"; } else if (this.skipSymbol("asyncAll")) { node = new nodes.AsyncAll(forTok.lineno, forTok.colno); endBlock = "endall"; } else { this.fail("parseFor: expected for{Async}", forTok.lineno, forTok.colno); } node.name = this.parsePrimary(); if (!(node.name instanceof nodes.Symbol)) { this.fail("parseFor: variable name expected for loop"); } var type = this.peekToken().type; if (type === lexer.TOKEN_COMMA) { var key = node.name; node.name = new nodes.Array(key.lineno, key.colno); node.name.addChild(key); while (this.skip(lexer.TOKEN_COMMA)) { var prim = this.parsePrimary(); node.name.addChild(prim); } } if (!this.skipSymbol("in")) { this.fail('parseFor: expected "in" keyword for loop', forTok.lineno, forTok.colno); } node.arr = this.parseExpression(); this.advanceAfterBlockEnd(forTok.value); node.body = this.parseUntilBlocks(endBlock, "else"); if (this.skipSymbol("else")) { this.advanceAfterBlockEnd("else"); node.else_ = this.parseUntilBlocks(endBlock); } this.advanceAfterBlockEnd(); return node; }; _proto.parseMacro = function parseMacro() { var macroTok = this.peekToken(); if (!this.skipSymbol("macro")) { this.fail("expected macro"); } var name = this.parsePrimary(true); var args = this.parseSignature(); var node = new nodes.Macro(macroTok.lineno, macroTok.colno, name, args); this.advanceAfterBlockEnd(macroTok.value); node.body = this.parseUntilBlocks("endmacro"); this.advanceAfterBlockEnd(); return node; }; _proto.parseCall = function parseCall() { var callTok = this.peekToken(); if (!this.skipSymbol("call")) { this.fail("expected call"); } var callerArgs = this.parseSignature(true) || new nodes.NodeList; var macroCall = this.parsePrimary(); this.advanceAfterBlockEnd(callTok.value); var body = this.parseUntilBlocks("endcall"); this.advanceAfterBlockEnd(); var callerName = new nodes.Symbol(callTok.lineno, callTok.colno, "caller"); var callerNode = new nodes.Caller(callTok.lineno, callTok.colno, callerName, callerArgs, body); var args = macroCall.args.children; if (!(args[args.length - 1] instanceof nodes.KeywordArgs)) { args.push(new nodes.KeywordArgs); } var kwargs = args[args.length - 1]; kwargs.addChild(new nodes.Pair(callTok.lineno, callTok.colno, callerName, callerNode)); return new nodes.Output(callTok.lineno, callTok.colno, [macroCall]); }; _proto.parseWithContext = function parseWithContext() { var tok = this.peekToken(); var withContext = null; if (this.skipSymbol("with")) { withContext = true; } else if (this.skipSymbol("without")) { withContext = false; } if (withContext !== null) { if (!this.skipSymbol("context")) { this.fail("parseFrom: expected context after with/without", tok.lineno, tok.colno); } } return withContext; }; _proto.parseImport = function parseImport() { var importTok = this.peekToken(); if (!this.skipSymbol("import")) { this.fail("parseImport: expected import", importTok.lineno, importTok.colno); } var template = this.parseExpression(); if (!this.skipSymbol("as")) { this.fail('parseImport: expected "as" keyword', importTok.lineno, importTok.colno); } var target = this.parseExpression(); var withContext = this.parseWithContext(); var node = new nodes.Import(importTok.l