@player-ui/common-expressions-plugin 0.15.4-next.0 → 0.16.0--canary.866.36538

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1521,6 +1521,412 @@ var CommonExpressionsPlugin = function() {
1521
1521
  });
1522
1522
  return batchTxn;
1523
1523
  };
1524
+ var pointerToBinding = function pointerToBinding(pointer) {
1525
+ if (!pointer || pointer === "/") return "";
1526
+ var absolute = pointer.startsWith("/");
1527
+ var raw = absolute ? pointer.slice(1) : pointer;
1528
+ var segments = raw.split("/").map(decodeSegment);
1529
+ var out = "";
1530
+ for(var i = 0; i < segments.length; i++){
1531
+ var seg = segments[i];
1532
+ if (NUMERIC_SEGMENT.test(seg)) {
1533
+ out += "[".concat(seg, "]");
1534
+ } else {
1535
+ out += i === 0 ? seg : ".".concat(seg);
1536
+ }
1537
+ }
1538
+ return out;
1539
+ };
1540
+ var bindingToSegments = function bindingToSegments(binding) {
1541
+ if (!binding) return [];
1542
+ var segments = [];
1543
+ var parts = binding.split(".");
1544
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1545
+ try {
1546
+ for(var _iterator = parts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1547
+ var part = _step.value;
1548
+ var match = part.match(/^([^[]+)((?:\[\d+\])*)$/);
1549
+ if (!match) {
1550
+ segments.push(part);
1551
+ continue;
1552
+ }
1553
+ var _match = _sliced_to_array(match, 3), name = _match[1], arrays = _match[2];
1554
+ if (name) segments.push(name);
1555
+ if (arrays) {
1556
+ var _segments;
1557
+ var _arrays_match;
1558
+ var arrayMatches = (_arrays_match = arrays.match(/\[\d+\]/g)) !== null && _arrays_match !== void 0 ? _arrays_match : [];
1559
+ (_segments = segments).push.apply(_segments, _to_consumable_array(arrayMatches));
1560
+ }
1561
+ }
1562
+ } catch (err) {
1563
+ _didIteratorError = true;
1564
+ _iteratorError = err;
1565
+ } finally{
1566
+ try {
1567
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1568
+ _iterator.return();
1569
+ }
1570
+ } finally{
1571
+ if (_didIteratorError) {
1572
+ throw _iteratorError;
1573
+ }
1574
+ }
1575
+ }
1576
+ return segments;
1577
+ };
1578
+ var interpolatePointers = function interpolatePointers(input) {
1579
+ return input.replace(/\$\{([^}]+)\}/g, function(_, pointer) {
1580
+ return "{{".concat(pointerToBinding(pointer), "}}");
1581
+ });
1582
+ };
1583
+ var translateFunctionCall = function translateFunctionCall(call, logger) {
1584
+ if (call.call === "formatString") {
1585
+ var _call_args;
1586
+ var value = (_call_args = call.args) === null || _call_args === void 0 ? void 0 : _call_args.value;
1587
+ if (typeof value === "string") return interpolatePointers(value);
1588
+ logger === null || logger === void 0 ? void 0 : logger.warn("[a2ui] formatString received non-string 'value' arg; emitting expression form");
1589
+ }
1590
+ var argList = renderArgList(call.args);
1591
+ if (call.call === "formatString") {
1592
+ return "@[formatString(".concat(argList, ")]@");
1593
+ }
1594
+ return "@[".concat(call.call, "(").concat(argList, ")]@");
1595
+ };
1596
+ var renderArgList = function renderArgList(args) {
1597
+ if (!args) return "";
1598
+ return Object.values(args).map(renderArg).join(", ");
1599
+ };
1600
+ var newBuilder = function newBuilder() {
1601
+ return {
1602
+ schema: {
1603
+ ROOT: {}
1604
+ },
1605
+ knownTypes: /* @__PURE__ */ new Set([
1606
+ "ROOT"
1607
+ ])
1608
+ };
1609
+ };
1610
+ var findBoundPath = function findBoundPath(component, logger) {
1611
+ var lookupProp = INPUT_BINDING_PROPS[component.component];
1612
+ if (lookupProp) {
1613
+ var prop = component[lookupProp];
1614
+ if (isPathRef(prop)) return prop.path;
1615
+ }
1616
+ var pathRefs = collectPathRefs(component);
1617
+ if (pathRefs.length === 1) return pathRefs[0];
1618
+ if (pathRefs.length > 1) {
1619
+ logger === null || logger === void 0 ? void 0 : logger.warn("[a2ui] Component '".concat(component.id, "' (").concat(component.component, ") has checks but multiple {path} refs; skipping schema synthesis for this component"));
1620
+ } else {
1621
+ logger === null || logger === void 0 ? void 0 : logger.warn("[a2ui] Component '".concat(component.id, "' (").concat(component.component, ") has checks but no bound path could be determined; skipping"));
1622
+ }
1623
+ return void 0;
1624
+ };
1625
+ var collectPathRefs = function collectPathRefs(component) {
1626
+ var found = [];
1627
+ var walk = function walk1(v) {
1628
+ if (!v || (typeof v === "undefined" ? "undefined" : _type_of(v)) !== "object") return;
1629
+ if (Array.isArray(v)) {
1630
+ v.forEach(walk);
1631
+ return;
1632
+ }
1633
+ if (isPathRef(v)) {
1634
+ found.push(v.path);
1635
+ return;
1636
+ }
1637
+ Object.values(v).forEach(walk);
1638
+ };
1639
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1640
+ try {
1641
+ for(var _iterator = Object.entries(component)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1642
+ var _step_value = _sliced_to_array(_step.value, 2), k = _step_value[0], v = _step_value[1];
1643
+ if (k === "id" || k === "component" || k === "checks" || k === "action") {
1644
+ continue;
1645
+ }
1646
+ walk(v);
1647
+ }
1648
+ } catch (err) {
1649
+ _didIteratorError = true;
1650
+ _iteratorError = err;
1651
+ } finally{
1652
+ try {
1653
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1654
+ _iterator.return();
1655
+ }
1656
+ } finally{
1657
+ if (_didIteratorError) {
1658
+ throw _iteratorError;
1659
+ }
1660
+ }
1661
+ }
1662
+ return found;
1663
+ };
1664
+ var translateCheck = function translateCheck(check, logger) {
1665
+ var _check_args;
1666
+ var type = CHECK_TO_VALIDATOR[check.call];
1667
+ if (!type) {
1668
+ logger === null || logger === void 0 ? void 0 : logger.warn("[a2ui] Unknown validation check '".concat(check.call, "'; dropping"));
1669
+ return void 0;
1670
+ }
1671
+ var ref = {
1672
+ type: type,
1673
+ severity: "error"
1674
+ };
1675
+ if (check.message) ref.message = check.message;
1676
+ if (check.call === "regex" && ((_check_args = check.args) === null || _check_args === void 0 ? void 0 : _check_args.pattern)) {
1677
+ ref.regex = unwrapLiteral(check.args.pattern);
1678
+ }
1679
+ if (check.call === "length") {
1680
+ var _check_args1, _check_args2;
1681
+ if (((_check_args1 = check.args) === null || _check_args1 === void 0 ? void 0 : _check_args1.min) !== void 0) ref.min = unwrapLiteral(check.args.min);
1682
+ if (((_check_args2 = check.args) === null || _check_args2 === void 0 ? void 0 : _check_args2.max) !== void 0) ref.max = unwrapLiteral(check.args.max);
1683
+ }
1684
+ return ref;
1685
+ };
1686
+ var unwrapLiteral = function unwrapLiteral(value) {
1687
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) {
1688
+ return value;
1689
+ }
1690
+ return value;
1691
+ };
1692
+ var installAtPath = function installAtPath(builder, binding, leafType, validations, logger) {
1693
+ var segments = bindingToSegments(binding).filter(function(s) {
1694
+ return !s.startsWith("[");
1695
+ });
1696
+ if (segments.length === 0) {
1697
+ logger === null || logger === void 0 ? void 0 : logger.warn("[a2ui] Cannot install schema validation at empty path; skipping");
1698
+ return;
1699
+ }
1700
+ var currentNode = builder.schema.ROOT;
1701
+ var ownerPath = [];
1702
+ for(var i = 0; i < segments.length - 1; i++){
1703
+ var seg = segments[i];
1704
+ ownerPath.push(seg);
1705
+ var typeName = "".concat(TYPE_PREFIX).concat(ownerPath.join("_"));
1706
+ var existing = currentNode[seg];
1707
+ if (!existing) {
1708
+ currentNode[seg] = {
1709
+ type: typeName
1710
+ };
1711
+ } else if (existing.type !== typeName) {}
1712
+ var ref = currentNode[seg].type;
1713
+ if (!builder.schema[ref]) {
1714
+ builder.schema[ref] = {};
1715
+ builder.knownTypes.add(ref);
1716
+ }
1717
+ currentNode = builder.schema[ref];
1718
+ }
1719
+ var leafSeg = segments[segments.length - 1];
1720
+ var existingLeaf = currentNode[leafSeg];
1721
+ if (existingLeaf) {
1722
+ var _existingLeaf_validation;
1723
+ var merged = _object_spread_props(_object_spread({}, existingLeaf), {
1724
+ type: pickLeafType(existingLeaf.type, leafType),
1725
+ validation: _to_consumable_array((_existingLeaf_validation = existingLeaf.validation) !== null && _existingLeaf_validation !== void 0 ? _existingLeaf_validation : []).concat(_to_consumable_array(validations))
1726
+ });
1727
+ currentNode[leafSeg] = merged;
1728
+ } else {
1729
+ currentNode[leafSeg] = {
1730
+ type: leafType,
1731
+ validation: validations
1732
+ };
1733
+ }
1734
+ };
1735
+ var pickLeafType = function pickLeafType(existing, incoming) {
1736
+ if (incoming !== "string") return incoming;
1737
+ return existing;
1738
+ };
1739
+ var defaultLeafType = function defaultLeafType(component, checks) {
1740
+ if (component.component === "CheckBox") return "boolean";
1741
+ if (checks.some(function(c) {
1742
+ return c.call === "numeric";
1743
+ })) return "number";
1744
+ return "string";
1745
+ };
1746
+ var synthesizeSchema = function synthesizeSchema(components, logger) {
1747
+ var builder = newBuilder();
1748
+ var found = false;
1749
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1750
+ try {
1751
+ for(var _iterator = components[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1752
+ var component = _step.value;
1753
+ if (!component.checks || component.checks.length === 0) continue;
1754
+ var pointer = findBoundPath(component, logger);
1755
+ if (!pointer) continue;
1756
+ var binding = pointerToBinding(pointer);
1757
+ if (!binding) continue;
1758
+ var validations = component.checks.map(function(c) {
1759
+ return translateCheck(c, logger);
1760
+ }).filter(function(v) {
1761
+ return v !== void 0;
1762
+ });
1763
+ if (validations.length === 0) continue;
1764
+ installAtPath(builder, binding, defaultLeafType(component, component.checks), validations, logger);
1765
+ found = true;
1766
+ }
1767
+ } catch (err) {
1768
+ _didIteratorError = true;
1769
+ _iteratorError = err;
1770
+ } finally{
1771
+ try {
1772
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1773
+ _iterator.return();
1774
+ }
1775
+ } finally{
1776
+ if (_didIteratorError) {
1777
+ throw _iteratorError;
1778
+ }
1779
+ }
1780
+ }
1781
+ return found ? builder.schema : void 0;
1782
+ };
1783
+ var resolveAndInline = function resolveAndInline(id, ctx, templateScope) {
1784
+ var component = ctx.byId.get(id);
1785
+ if (!component) {
1786
+ throw new Error("[a2ui] Component reference '".concat(id, "' could not be resolved in the snapshot."));
1787
+ }
1788
+ return inlineComponent(component, ctx, templateScope);
1789
+ };
1790
+ var wrapInlined = function wrapInlined(asset) {
1791
+ return {
1792
+ asset: asset
1793
+ };
1794
+ };
1795
+ var scopedBinding = function scopedBinding(pointer, scope) {
1796
+ if (!pointer || pointer === "/") return scope !== null && scope !== void 0 ? scope : "";
1797
+ if (pointer.startsWith("/")) return pointerToBinding(pointer);
1798
+ if (!scope) return pointerToBinding(pointer);
1799
+ var relative = pointerToBinding(pointer);
1800
+ return relative ? "".concat(scope, "._index_.").concat(relative) : "".concat(scope, "._index_");
1801
+ };
1802
+ var scopedPointer = function scopedPointer(pointer, scope) {
1803
+ if (pointer.startsWith("/")) return pointer;
1804
+ return "/".concat(scope, "/_index_/").concat(pointer);
1805
+ };
1806
+ var translateAction = function translateAction(action, ctx) {
1807
+ if ("event" in action) {
1808
+ var _action_event = action.event, name = _action_event.name, context = _action_event.context;
1809
+ ctx.eventNames.add(name);
1810
+ var result = {
1811
+ value: name
1812
+ };
1813
+ if (context && Object.keys(context).length > 0) {
1814
+ result.exp = buildContextWriteExpressions(context);
1815
+ }
1816
+ return result;
1817
+ }
1818
+ return {
1819
+ exp: translateFunctionCall(action.functionCall, ctx.logger)
1820
+ };
1821
+ };
1822
+ var buildContextWriteExpressions = function buildContextWriteExpressions(context) {
1823
+ return Object.entries(context).map(function(param) {
1824
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
1825
+ var lhs = "{{".concat(A2UI_EVENT_CONTEXT_NAMESPACE, ".").concat(key, "}}");
1826
+ return "".concat(lhs, " = ").concat(renderRhs(value));
1827
+ });
1828
+ };
1829
+ var buildNavigation = function buildNavigation(surfaceId, eventNames) {
1830
+ var view = {
1831
+ state_type: "VIEW",
1832
+ ref: surfaceId,
1833
+ transitions: {
1834
+ "*": "END_Done"
1835
+ }
1836
+ };
1837
+ var endStates = {
1838
+ END_Done: {
1839
+ state_type: "END",
1840
+ outcome: "done"
1841
+ }
1842
+ };
1843
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1844
+ try {
1845
+ for(var _iterator = eventNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1846
+ var name = _step.value;
1847
+ var endName = "END_".concat(name);
1848
+ view.transitions[name] = endName;
1849
+ endStates[endName] = {
1850
+ state_type: "END",
1851
+ outcome: name
1852
+ };
1853
+ }
1854
+ } catch (err) {
1855
+ _didIteratorError = true;
1856
+ _iteratorError = err;
1857
+ } finally{
1858
+ try {
1859
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1860
+ _iterator.return();
1861
+ }
1862
+ } finally{
1863
+ if (_didIteratorError) {
1864
+ throw _iteratorError;
1865
+ }
1866
+ }
1867
+ }
1868
+ var flow = _object_spread({
1869
+ startState: "VIEW_1",
1870
+ VIEW_1: view
1871
+ }, endStates);
1872
+ return {
1873
+ BEGIN: "FLOW_1",
1874
+ FLOW_1: flow
1875
+ };
1876
+ };
1877
+ var adaptA2UIToFlow = function adaptA2UIToFlow(snapshot, logger) {
1878
+ var _snapshot_data;
1879
+ if (!snapshot || !Array.isArray(snapshot.components)) {
1880
+ throw new Error("[a2ui] snapshot.components must be an array");
1881
+ }
1882
+ var byId = /* @__PURE__ */ new Map();
1883
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1884
+ try {
1885
+ for(var _iterator = snapshot.components[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1886
+ var component = _step.value;
1887
+ if (!(component === null || component === void 0 ? void 0 : component.id)) {
1888
+ throw new Error("[a2ui] every component must have an id");
1889
+ }
1890
+ byId.set(component.id, component);
1891
+ }
1892
+ } catch (err) {
1893
+ _didIteratorError = true;
1894
+ _iteratorError = err;
1895
+ } finally{
1896
+ try {
1897
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1898
+ _iterator.return();
1899
+ }
1900
+ } finally{
1901
+ if (_didIteratorError) {
1902
+ throw _iteratorError;
1903
+ }
1904
+ }
1905
+ }
1906
+ var root = byId.get("root");
1907
+ if (!root) {
1908
+ throw new Error("[a2ui] snapshot must contain a component with id 'root'");
1909
+ }
1910
+ var ctx = {
1911
+ byId: byId,
1912
+ inProgress: /* @__PURE__ */ new Set(),
1913
+ eventNames: /* @__PURE__ */ new Set(),
1914
+ logger: logger
1915
+ };
1916
+ var rootAsset = inlineComponent(root, ctx);
1917
+ rootAsset.id = snapshot.surfaceId;
1918
+ var schema = synthesizeSchema(snapshot.components, logger);
1919
+ var flow = {
1920
+ id: snapshot.surfaceId,
1921
+ views: [
1922
+ rootAsset
1923
+ ],
1924
+ data: (_snapshot_data = snapshot.data) !== null && _snapshot_data !== void 0 ? _snapshot_data : {},
1925
+ navigation: buildNavigation(snapshot.surfaceId, ctx.eventNames)
1926
+ };
1927
+ if (schema) flow.schema = schema;
1928
+ return flow;
1929
+ };
1524
1930
  var toNum = // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-expressions/core/src/expressions/toNum.ts
1525
1931
  function toNum(val, coerceTo0) {
1526
1932
  if (typeof val === "number") {
@@ -1763,7 +2169,7 @@ var CommonExpressionsPlugin = function() {
1763
2169
  }
1764
2170
  return out;
1765
2171
  }
1766
- function isObject(o) {
2172
+ function isObject2(o) {
1767
2173
  return o != null && (typeof o === "undefined" ? "undefined" : _type_of(o)) === "object";
1768
2174
  }
1769
2175
  function addLast2(array, val) {
@@ -1836,7 +2242,7 @@ var CommonExpressionsPlugin = function() {
1836
2242
  if (idx === path.length - 1) {
1837
2243
  newValue = val;
1838
2244
  } else {
1839
- var nestedObj = isObject(obj) && isObject(obj[key]) ? obj[key] : typeof path[idx + 1] === "number" ? [] : {};
2245
+ var nestedObj = isObject2(obj) && isObject2(obj[key]) ? obj[key] : typeof path[idx + 1] === "number" ? [] : {};
1840
2246
  newValue = doSetIn(nestedObj, path, val, idx + 1);
1841
2247
  }
1842
2248
  return set2(obj, key, newValue);
@@ -1966,7 +2372,7 @@ var CommonExpressionsPlugin = function() {
1966
2372
  var key = keys[j];
1967
2373
  if (fAddDefaults && out[key] !== void 0) continue;
1968
2374
  var nextVal = obj[key];
1969
- if (fDeep && isObject(out[key]) && isObject(nextVal)) {
2375
+ if (fDeep && isObject2(out[key]) && isObject2(nextVal)) {
1970
2376
  nextVal = doMerge(fAddDefaults, fDeep, out[key], nextVal);
1971
2377
  }
1972
2378
  if (nextVal === void 0 || nextVal === out[key]) continue;
@@ -7517,8 +7923,234 @@ var CommonExpressionsPlugin = function() {
7517
7923
  ref: Symbol("not-started"),
7518
7924
  status: "not-started"
7519
7925
  };
7520
- var PLAYER_VERSION = true ? "0.15.4-next.0" : "unknown";
7521
- var COMMIT = true ? "23a98a4b8e5d2c8078103ef189e9167a0d96823d" : "unknown";
7926
+ var A2UI_EVENT_CONTEXT_NAMESPACE = "agent.event.context";
7927
+ var NUMERIC_SEGMENT = /^(0|[1-9]\d*)$/;
7928
+ var decodeSegment = function decodeSegment(segment) {
7929
+ return segment.replace(/~1/g, "/").replace(/~0/g, "~");
7930
+ };
7931
+ var isObject = function isObject(v) {
7932
+ return (typeof v === "undefined" ? "undefined" : _type_of(v)) === "object" && v !== null && !Array.isArray(v);
7933
+ };
7934
+ var isPathRef = function isPathRef(v) {
7935
+ return isObject(v) && typeof v.path === "string" && Object.keys(v).length === 1;
7936
+ };
7937
+ var isFunctionCall = function isFunctionCall(v) {
7938
+ return isObject(v) && typeof v.call === "string";
7939
+ };
7940
+ function renderArg(value) {
7941
+ if (value === null) return "null";
7942
+ if (value === void 0) return "null";
7943
+ if (typeof value === "boolean") return String(value);
7944
+ if (typeof value === "number") return String(value);
7945
+ if (typeof value === "string") return JSON.stringify(value);
7946
+ if (Array.isArray(value)) {
7947
+ return "[".concat(value.map(renderArg).join(", "), "]");
7948
+ }
7949
+ if (isPathRef(value)) {
7950
+ return "{{".concat(pointerToBinding(value.path), "}}");
7951
+ }
7952
+ if (isFunctionCall(value)) {
7953
+ var inner = translateFunctionCall(value);
7954
+ return inner.replace(/^@\[/, "").replace(/\]@$/, "");
7955
+ }
7956
+ return JSON.stringify(value);
7957
+ }
7958
+ var INPUT_BINDING_PROPS = {
7959
+ TextField: "text",
7960
+ CheckBox: "checked",
7961
+ DateTimeInput: "value",
7962
+ ChoicePicker: "value",
7963
+ Slider: "value"
7964
+ };
7965
+ var CHECK_TO_VALIDATOR = {
7966
+ required: "required",
7967
+ regex: "regex",
7968
+ email: "email",
7969
+ length: "length",
7970
+ numeric: "numeric"
7971
+ };
7972
+ var TYPE_PREFIX = "T_";
7973
+ var STRUCTURAL_KEYS = /* @__PURE__ */ new Set([
7974
+ "id",
7975
+ "component",
7976
+ "child",
7977
+ "children",
7978
+ "checks",
7979
+ "action"
7980
+ ]);
7981
+ function inlineComponent(component, ctx, templateScope) {
7982
+ if (ctx.inProgress.has(component.id)) {
7983
+ throw new Error("[a2ui] Component cycle detected at id '".concat(component.id, "'. A2UI requires the component graph to be a tree."));
7984
+ }
7985
+ ctx.inProgress.add(component.id);
7986
+ var asset = {
7987
+ id: component.id,
7988
+ type: component.component
7989
+ };
7990
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
7991
+ try {
7992
+ for(var _iterator = Object.entries(component)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
7993
+ var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
7994
+ if (STRUCTURAL_KEYS.has(key)) continue;
7995
+ asset[key] = translatePropValue(value, templateScope, ctx, key);
7996
+ }
7997
+ } catch (err) {
7998
+ _didIteratorError = true;
7999
+ _iteratorError = err;
8000
+ } finally{
8001
+ try {
8002
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
8003
+ _iterator.return();
8004
+ }
8005
+ } finally{
8006
+ if (_didIteratorError) {
8007
+ throw _iteratorError;
8008
+ }
8009
+ }
8010
+ }
8011
+ if (typeof component.child === "string") {
8012
+ var childId = component.child;
8013
+ asset.child = wrapInlined(resolveAndInline(childId, ctx, templateScope));
8014
+ }
8015
+ if (component.children) {
8016
+ if (Array.isArray(component.children)) {
8017
+ asset.children = component.children.map(function(id) {
8018
+ return wrapInlined(resolveAndInline(id, ctx, templateScope));
8019
+ });
8020
+ } else {
8021
+ var _component_children = component.children, path = _component_children.path, componentId = _component_children.componentId;
8022
+ var data = scopedBinding(path, templateScope);
8023
+ var templateComponent = ctx.byId.get(componentId);
8024
+ if (!templateComponent) {
8025
+ throw new Error("[a2ui] Templated children reference unknown componentId '".concat(componentId, "' on component '").concat(component.id, "'."));
8026
+ }
8027
+ var templated = inlineComponent(_object_spread_props(_object_spread({}, templateComponent), {
8028
+ id: "".concat(templateComponent.id, "-_index_")
8029
+ }), ctx, data);
8030
+ asset.template = [
8031
+ {
8032
+ data: data,
8033
+ output: "children",
8034
+ value: {
8035
+ asset: templated
8036
+ }
8037
+ }
8038
+ ];
8039
+ }
8040
+ }
8041
+ if (component.action) {
8042
+ Object.assign(asset, translateAction(component.action, ctx));
8043
+ }
8044
+ ctx.inProgress.delete(component.id);
8045
+ return asset;
8046
+ }
8047
+ var CHILD_KEY_RE = /(?:^|[a-z])Child$|^child$/;
8048
+ var CHILDREN_KEY_RE = /(?:^|[a-z])Children$|^children$/;
8049
+ function translatePropValue(value, templateScope, ctx, parentKey) {
8050
+ if (value === null || value === void 0) return value;
8051
+ if (parentKey && CHILD_KEY_RE.test(parentKey) && typeof value === "string") {
8052
+ return wrapInlined(resolveAndInline(value, ctx, templateScope));
8053
+ }
8054
+ if (parentKey && CHILDREN_KEY_RE.test(parentKey)) {
8055
+ if (Array.isArray(value) && value.every(function(v) {
8056
+ return typeof v === "string";
8057
+ })) {
8058
+ return value.map(function(id) {
8059
+ return wrapInlined(resolveAndInline(id, ctx, templateScope));
8060
+ });
8061
+ }
8062
+ if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && value !== null && !Array.isArray(value) && "componentId" in value) {
8063
+ var _ctx_logger;
8064
+ (_ctx_logger = ctx.logger) === null || _ctx_logger === void 0 ? void 0 : _ctx_logger.warn("[a2ui] Templated children are only supported at top-level 'children'; '".concat(parentKey, "' will be left unresolved."));
8065
+ }
8066
+ }
8067
+ if ((typeof value === "undefined" ? "undefined" : _type_of(value)) !== "object") return value;
8068
+ if (Array.isArray(value)) {
8069
+ return value.map(function(v) {
8070
+ return translatePropValue(v, templateScope, ctx, void 0);
8071
+ });
8072
+ }
8073
+ if (isPathRef(value)) {
8074
+ return scopedBinding(value.path, templateScope);
8075
+ }
8076
+ if (isFunctionCall(value)) {
8077
+ if (templateScope) {
8078
+ return translateFunctionCall(rewritePathsInCall(value, templateScope), ctx.logger);
8079
+ }
8080
+ return translateFunctionCall(value, ctx.logger);
8081
+ }
8082
+ var out = {};
8083
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
8084
+ try {
8085
+ for(var _iterator = Object.entries(value)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
8086
+ var _step_value = _sliced_to_array(_step.value, 2), k = _step_value[0], v = _step_value[1];
8087
+ out[k] = translatePropValue(v, templateScope, ctx, k);
8088
+ }
8089
+ } catch (err) {
8090
+ _didIteratorError = true;
8091
+ _iteratorError = err;
8092
+ } finally{
8093
+ try {
8094
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
8095
+ _iterator.return();
8096
+ }
8097
+ } finally{
8098
+ if (_didIteratorError) {
8099
+ throw _iteratorError;
8100
+ }
8101
+ }
8102
+ }
8103
+ return out;
8104
+ }
8105
+ function rewritePathsInCall(value, scope) {
8106
+ if (!value || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== "object") return value;
8107
+ if (Array.isArray(value)) {
8108
+ return value.map(function(v) {
8109
+ return rewritePathsInCall(v, scope);
8110
+ });
8111
+ }
8112
+ if (isPathRef(value)) {
8113
+ return {
8114
+ path: scopedPointer(value.path, scope)
8115
+ };
8116
+ }
8117
+ if (isFunctionCall(value)) {
8118
+ return _object_spread_props(_object_spread({}, value), {
8119
+ args: value.args ? Object.fromEntries(Object.entries(value.args).map(function(param) {
8120
+ var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
8121
+ return [
8122
+ k,
8123
+ rewritePathsInCall(v, scope)
8124
+ ];
8125
+ })) : value.args
8126
+ });
8127
+ }
8128
+ return Object.fromEntries(Object.entries(value).map(function(param) {
8129
+ var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
8130
+ return [
8131
+ k,
8132
+ rewritePathsInCall(v, scope)
8133
+ ];
8134
+ }));
8135
+ }
8136
+ function renderRhs(value) {
8137
+ if (value === null || value === void 0) return "null";
8138
+ if (typeof value === "boolean") return String(value);
8139
+ if (typeof value === "number") return String(value);
8140
+ if (typeof value === "string") return JSON.stringify(value);
8141
+ if (Array.isArray(value)) {
8142
+ return "[".concat(value.map(renderRhs).join(", "), "]");
8143
+ }
8144
+ if (isPathRef(value)) {
8145
+ return "{{".concat(pointerToBinding(value.path), "}}");
8146
+ }
8147
+ if (isFunctionCall(value)) {
8148
+ return translateFunctionCall(value).replace(/^@\[/, "").replace(/\]@$/, "");
8149
+ }
8150
+ return JSON.stringify(value);
8151
+ }
8152
+ var PLAYER_VERSION = true ? "0.16.0--canary.866.36538" : "unknown";
8153
+ var COMMIT = true ? "0186f1bd04fda238cbc62b8d293c8048ab26efc2" : "unknown";
7522
8154
  var _Player = /*#__PURE__*/ function() {
7523
8155
  function _Player2(config) {
7524
8156
  var _this = this;
@@ -7846,14 +8478,15 @@ var CommonExpressionsPlugin = function() {
7846
8478
  },
7847
8479
  {
7848
8480
  key: "start",
7849
- value: function start(payload) {
8481
+ value: function start(payload, options) {
7850
8482
  return _async_to_generator(function() {
7851
- var _this, _ref, ref, maybeUpdateState, _this_setupFlow, state, start, endProps, _tmp, error, errorState;
8483
+ var _this, _ref, flow, ref, maybeUpdateState, _this_setupFlow, state, start, endProps, _tmp, error, errorState;
7852
8484
  return _ts_generator(this, function(_state) {
7853
8485
  switch(_state.label){
7854
8486
  case 0:
7855
8487
  _this = this;
7856
- ref = Symbol((_ref = payload === null || payload === void 0 ? void 0 : payload.id) !== null && _ref !== void 0 ? _ref : "payload");
8488
+ flow = (options === null || options === void 0 ? void 0 : options.format) === "a2ui" ? adaptA2UIToFlow(payload, this.logger) : payload;
8489
+ ref = Symbol((_ref = flow === null || flow === void 0 ? void 0 : flow.id) !== null && _ref !== void 0 ? _ref : "payload");
7857
8490
  maybeUpdateState = function maybeUpdateState(newState) {
7858
8491
  if (_this.state.ref !== ref) {
7859
8492
  _this.logger.warn("Received update for a flow that's not the current one");
@@ -7874,7 +8507,7 @@ var CommonExpressionsPlugin = function() {
7874
8507
  ,
7875
8508
  4
7876
8509
  ]);
7877
- _this_setupFlow = this.setupFlow(payload), state = _this_setupFlow.state, start = _this_setupFlow.start;
8510
+ _this_setupFlow = this.setupFlow(flow), state = _this_setupFlow.state, start = _this_setupFlow.start;
7878
8511
  this.setState(_object_spread({
7879
8512
  ref: ref
7880
8513
  }, state));
@@ -7909,7 +8542,7 @@ var CommonExpressionsPlugin = function() {
7909
8542
  errorState = {
7910
8543
  status: "error",
7911
8544
  ref: ref,
7912
- flow: payload,
8545
+ flow: flow,
7913
8546
  error: error
7914
8547
  };
7915
8548
  maybeUpdateState(errorState);