@ateam-ai-mobile/core 0.1.35 → 0.1.37

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.
package/dist/index.mjs CHANGED
@@ -920,10 +920,10 @@ function backoffMs(attempt) {
920
920
  const jitter = Math.random() * 250;
921
921
  return base + jitter;
922
922
  }
923
- function send(obj) {
923
+ function send(obj2) {
924
924
  if (_ws && _ws.readyState === 1) {
925
925
  try {
926
- _ws.send(JSON.stringify(obj));
926
+ _ws.send(JSON.stringify(obj2));
927
927
  } catch (e) {
928
928
  console.warn("[acsWs] send failed", e);
929
929
  }
@@ -1454,7 +1454,13 @@ var DETAILS_BLOCK_OPEN = "\uE102";
1454
1454
  var DETAILS_BLOCK_CLOSE = "\uE103";
1455
1455
  var DIAGRAM_BLOCK_OPEN = "\uE104";
1456
1456
  var DIAGRAM_BLOCK_CLOSE = "\uE105";
1457
- var SENTINEL_CHARS = /[\uE100-\uE105]/g;
1457
+ var CHART_BLOCK_OPEN = "\uE106";
1458
+ var CHART_BLOCK_CLOSE = "\uE107";
1459
+ var COMPARISON_BLOCK_OPEN = "\uE108";
1460
+ var COMPARISON_BLOCK_CLOSE = "\uE109";
1461
+ var TIMELINE_BLOCK_OPEN = "\uE10A";
1462
+ var TIMELINE_BLOCK_CLOSE = "\uE10B";
1463
+ var SENTINEL_CHARS = /[\uE100-\uE10B]/g;
1458
1464
  var clean = (text) => text.replace(SENTINEL_CHARS, "");
1459
1465
  function renderTableShape(content) {
1460
1466
  if (!content || typeof content !== "object") return null;
@@ -1470,28 +1476,152 @@ var statusOf = (v) => DIAGRAM_STATUSES.includes(v) ? v : "";
1470
1476
  function diagramView(content) {
1471
1477
  if (!content || typeof content !== "object" || !Array.isArray(content.steps)) return null;
1472
1478
  const steps = [];
1473
- for (const s of content.steps) {
1474
- if (!s || typeof s !== "object") continue;
1479
+ const kept = [];
1480
+ const rawNext = [];
1481
+ content.steps.forEach((s, i) => {
1482
+ kept[i + 1] = 0;
1483
+ if (!s || typeof s !== "object") return;
1475
1484
  const title = str(s.title);
1476
1485
  const text = str(s.text);
1477
- if (!title && !text) continue;
1486
+ if (!title && !text) return;
1478
1487
  const badges = [];
1479
1488
  for (const b of Array.isArray(s.badges) ? s.badges : []) {
1480
1489
  const bt = str(b && typeof b === "object" ? b.text : b);
1481
1490
  if (bt) badges.push({ text: bt, status: statusOf(b && b.status) });
1482
1491
  }
1483
- steps.push({ title: title || text, text: title ? text : "", status: statusOf(s.status), badges });
1484
- }
1485
- return steps.length < 2 ? null : { title: str(content.title), steps };
1492
+ steps.push({ title: title || text, text: title ? text : "", status: statusOf(s.status), badges, decision: s.kind === "decision" || s.decision === true, next: null });
1493
+ rawNext.push(Array.isArray(s.next) ? s.next : null);
1494
+ kept[i + 1] = steps.length;
1495
+ });
1496
+ if (steps.length < 2) return null;
1497
+ steps.forEach((st, i) => {
1498
+ const raw = rawNext[i];
1499
+ if (!raw) return;
1500
+ const out = [];
1501
+ for (const e of raw) {
1502
+ const to = e && typeof e === "object" && Number.isInteger(e.to) ? kept[e.to] || 0 : 0;
1503
+ if (!to || to === i + 1 || out.some((x) => x.to === to) || out.length >= 3) continue;
1504
+ out.push({ to, label: str(e.label).slice(0, 40) });
1505
+ }
1506
+ st.next = out;
1507
+ });
1508
+ return { title: str(content.title), steps };
1509
+ }
1510
+ function diagramFlow(view) {
1511
+ const last = view.steps.length - 1;
1512
+ return view.steps.map((st, i) => {
1513
+ const flow = { arrow: null, jumps: [], loops: [] };
1514
+ if (!st.next) {
1515
+ if (i < last) flow.arrow = { label: "" };
1516
+ return flow;
1517
+ }
1518
+ for (const e of st.next) {
1519
+ if (e.to === i + 2) flow.arrow = { label: e.label };
1520
+ else if (e.to > i + 2) flow.jumps.push(e);
1521
+ else flow.loops.push(e);
1522
+ }
1523
+ return flow;
1524
+ });
1486
1525
  }
1487
1526
  function diagramAsText(d) {
1488
1527
  const lines = d.title ? [d.title] : [];
1489
1528
  d.steps.forEach((s, i) => {
1490
1529
  const badges = s.badges.length ? ` [${s.badges.map((b) => b.text).join(", ")}]` : "";
1491
- lines.push(`${i + 1}. ${s.title}${s.text ? ` \u2014 ${s.text}` : ""}${badges}`);
1530
+ lines.push(`${i + 1}. ${s.title}${s.decision ? " (decision)" : ""}${s.text ? ` \u2014 ${s.text}` : ""}${badges}`);
1531
+ if (s.next) lines.push(s.next.length ? ` ${s.next.map((e) => `${e.label ? `${e.label} ` : ""}\u2192 ${e.to}`).join("; ")}` : " (end)");
1532
+ });
1533
+ return lines.join("\n");
1534
+ }
1535
+ var num = (v) => typeof v === "number" && Number.isFinite(v) && Math.abs(v) <= 1e15 ? v : null;
1536
+ var list = (v) => Array.isArray(v) ? v : [];
1537
+ var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
1538
+ var numText = (n) => String(Math.round(n * 100) / 100);
1539
+ function chartView(content) {
1540
+ const c = obj(content);
1541
+ const labels = list(c.labels).map(str);
1542
+ if (labels.length < 2) return null;
1543
+ const series = [];
1544
+ for (const s of list(c.series)) {
1545
+ const values = list(obj(s).values).slice(0, labels.length).map(num);
1546
+ if (values.length === labels.length && values.every((v) => v !== null)) series.push({ name: str(obj(s).name), values });
1547
+ }
1548
+ if (!series.length) return null;
1549
+ const highlight = str(c.highlight);
1550
+ return { title: str(c.title), type: c.type === "line" ? "line" : "bar", labels, series, unit: str(c.unit), highlight: labels.includes(highlight) ? highlight : "" };
1551
+ }
1552
+ function chartScale(view) {
1553
+ const all = view.series.flatMap((s) => s.values);
1554
+ const lo = Math.min(0, ...all);
1555
+ const hi = Math.max(0, ...all);
1556
+ return { lo, hi: hi === lo ? lo + 1 : hi };
1557
+ }
1558
+ function chartAsText(view) {
1559
+ const u = view.unit ? ` ${view.unit}` : "";
1560
+ const lines = view.title ? [view.title] : [];
1561
+ view.labels.forEach((l, i) => {
1562
+ const cells = view.series.map((s) => `${s.name ? `${s.name} ` : ""}${numText(s.values[i])}${u}`);
1563
+ lines.push(`${l}: ${cells.join(", ")}${view.highlight === l ? " (highlighted)" : ""}`);
1564
+ });
1565
+ return lines.join("\n");
1566
+ }
1567
+ function comparisonView(content) {
1568
+ const c = obj(content);
1569
+ const options = [];
1570
+ for (const o of list(c.options)) {
1571
+ const ob = obj(o);
1572
+ const name = str(ob.name);
1573
+ if (!name) continue;
1574
+ const rows = list(ob.rows).map((r) => ({ text: str(obj(r).text), ok: typeof obj(r).ok === "boolean" ? obj(r).ok : null })).filter((r) => r.text);
1575
+ options.push({ name, price: str(ob.price), badge: str(ob.badge), best: ob.best === true, rows });
1576
+ }
1577
+ if (options.length < 2) return null;
1578
+ const first = options.findIndex((o) => o.best);
1579
+ options.forEach((o, i) => {
1580
+ if (i !== first) o.best = false;
1492
1581
  });
1582
+ return { title: str(c.title), options: options.slice(0, 3) };
1583
+ }
1584
+ function comparisonAsText(view) {
1585
+ const lines = view.title ? [view.title] : [];
1586
+ for (const o of view.options) {
1587
+ lines.push(`${o.name}${o.price ? ` (${o.price})` : ""}${o.badge ? ` [${o.badge}]` : ""}${o.best ? " (best)" : ""}`);
1588
+ for (const r of o.rows) lines.push(` ${r.ok === true ? "+" : r.ok === false ? "-" : "\xB7"} ${r.text}`);
1589
+ }
1493
1590
  return lines.join("\n");
1494
1591
  }
1592
+ function timelineView(content) {
1593
+ const c = obj(content);
1594
+ const days = list(c.days).map((d) => ({
1595
+ title: str(obj(d).title),
1596
+ events: list(obj(d).events).map((e) => ({ time: str(obj(e).time), text: str(obj(e).text) })).filter((e) => e.text)
1597
+ })).filter((d) => d.title || d.events.length);
1598
+ if (days.reduce((n, d) => n + d.events.length, 0) < 2) return null;
1599
+ return { title: str(c.title), subtitle: str(c.subtitle), days };
1600
+ }
1601
+ function timelineAsText(view) {
1602
+ const lines = [];
1603
+ if (view.title) lines.push(view.title);
1604
+ if (view.subtitle) lines.push(view.subtitle);
1605
+ for (const d of view.days) {
1606
+ if (d.title) lines.push(d.title);
1607
+ for (const e of d.events) lines.push(` ${e.time ? `${e.time} ` : ""}${e.text}`);
1608
+ }
1609
+ return lines.join("\n");
1610
+ }
1611
+ var VISUALS = {
1612
+ diagram: { open: DIAGRAM_BLOCK_OPEN, close: DIAGRAM_BLOCK_CLOSE, view: diagramView, asText: diagramAsText },
1613
+ chart: { open: CHART_BLOCK_OPEN, close: CHART_BLOCK_CLOSE, view: chartView, asText: chartAsText },
1614
+ comparison: { open: COMPARISON_BLOCK_OPEN, close: COMPARISON_BLOCK_CLOSE, view: comparisonView, asText: comparisonAsText },
1615
+ timeline: { open: TIMELINE_BLOCK_OPEN, close: TIMELINE_BLOCK_CLOSE, view: timelineView, asText: timelineAsText }
1616
+ };
1617
+ var isVisualKind = (kind) => typeof kind === "string" && Object.prototype.hasOwnProperty.call(VISUALS, kind);
1618
+ function visualViewOf(kind, payload) {
1619
+ try {
1620
+ return VISUALS[kind].view(JSON.parse(decodeURIComponent(payload)));
1621
+ } catch {
1622
+ return null;
1623
+ }
1624
+ }
1495
1625
  function fence(code, language) {
1496
1626
  const longest = (code.match(/`+/g) || []).reduce((n, run) => Math.max(n, run.length), 0);
1497
1627
  const ticks = "`".repeat(Math.max(3, longest + 1));
@@ -1514,9 +1644,10 @@ function blockText(b) {
1514
1644
  const md = renderTableShape(b.content);
1515
1645
  if (md) return md;
1516
1646
  }
1517
- if (b.kind === "diagram") {
1518
- const view = diagramView(b.content);
1519
- if (view) return `${DIAGRAM_BLOCK_OPEN}${encodeURIComponent(JSON.stringify(view))}${DIAGRAM_BLOCK_CLOSE}`;
1647
+ if (isVisualKind(b.kind)) {
1648
+ const v = VISUALS[b.kind];
1649
+ const view = v.view(b.content);
1650
+ if (view) return `${v.open}${encodeURIComponent(JSON.stringify(view))}${v.close}`;
1520
1651
  }
1521
1652
  if (b.kind === "json") {
1522
1653
  const md = renderTableShape(b.content);
@@ -1536,14 +1667,14 @@ function blocksToText(blocks) {
1536
1667
  if (!b || typeof b !== "object") return "";
1537
1668
  const text = blockText(b);
1538
1669
  if (!text) return "";
1539
- if (text.startsWith(TABLE_BLOCK_OPEN) || text.startsWith(DIAGRAM_BLOCK_OPEN)) return text;
1670
+ if (text.startsWith(TABLE_BLOCK_OPEN) || Object.values(VISUALS).some((v) => text.startsWith(v.open))) return text;
1540
1671
  return b.meta?.display === "folded" ? `${DETAILS_BLOCK_OPEN}${encodeURIComponent(text)}${DETAILS_BLOCK_CLOSE}` : text;
1541
1672
  }).filter(Boolean).join("\n\n");
1542
1673
  }
1543
1674
  var PAIRS = [
1544
1675
  { kind: "table", open: TABLE_BLOCK_OPEN, close: TABLE_BLOCK_CLOSE },
1545
1676
  { kind: "details", open: DETAILS_BLOCK_OPEN, close: DETAILS_BLOCK_CLOSE },
1546
- { kind: "diagram", open: DIAGRAM_BLOCK_OPEN, close: DIAGRAM_BLOCK_CLOSE }
1677
+ ...Object.keys(VISUALS).map((kind) => ({ kind, open: VISUALS[kind].open, close: VISUALS[kind].close }))
1547
1678
  ];
1548
1679
  function splitBlockSegments(content) {
1549
1680
  const segments = [];
@@ -1589,13 +1720,9 @@ function plainTextOf(content) {
1589
1720
  return splitBlockSegments(content).map((seg) => {
1590
1721
  if (seg.kind === "md") return seg.content;
1591
1722
  if (seg.kind === "table") return tableAsText(seg.content);
1592
- if (seg.kind === "diagram") {
1593
- try {
1594
- const view = diagramView(JSON.parse(decodeURIComponent(seg.content)));
1595
- return view ? diagramAsText(view) : "";
1596
- } catch {
1597
- return "";
1598
- }
1723
+ if (isVisualKind(seg.kind)) {
1724
+ const view = visualViewOf(seg.kind, seg.content);
1725
+ return view ? VISUALS[seg.kind].asText(view) : "";
1599
1726
  }
1600
1727
  try {
1601
1728
  return decodeURIComponent(seg.content);
@@ -2450,6 +2577,10 @@ var borderRadius = {
2450
2577
  full: 9999
2451
2578
  };
2452
2579
  export {
2580
+ CHART_BLOCK_CLOSE,
2581
+ CHART_BLOCK_OPEN,
2582
+ COMPARISON_BLOCK_CLOSE,
2583
+ COMPARISON_BLOCK_OPEN,
2453
2584
  DETAILS_BLOCK_CLOSE,
2454
2585
  DETAILS_BLOCK_OPEN,
2455
2586
  DIAGRAM_BLOCK_CLOSE,
@@ -2460,14 +2591,22 @@ export {
2460
2591
  PluginCommandEmitter,
2461
2592
  TABLE_BLOCK_CLOSE,
2462
2593
  TABLE_BLOCK_OPEN,
2594
+ TIMELINE_BLOCK_CLOSE,
2595
+ TIMELINE_BLOCK_OPEN,
2596
+ VISUALS,
2463
2597
  ada,
2464
2598
  apiFetch,
2465
2599
  apiFetchRaw,
2466
2600
  blocksToText,
2467
2601
  borderRadius,
2468
2602
  capabilityEnabled,
2603
+ chartAsText,
2604
+ chartScale,
2605
+ chartView,
2469
2606
  closeChatStream,
2470
2607
  colors,
2608
+ comparisonAsText,
2609
+ comparisonView,
2471
2610
  connectAcsWs,
2472
2611
  connectorCall,
2473
2612
  createAuthSession,
@@ -2475,6 +2614,7 @@ export {
2475
2614
  deleteArtifact,
2476
2615
  devModeFromCatalog,
2477
2616
  diagramAsText,
2617
+ diagramFlow,
2478
2618
  diagramView,
2479
2619
  disconnectAcsWs,
2480
2620
  exchangeHandoff,
@@ -2495,6 +2635,7 @@ export {
2495
2635
  initAdas,
2496
2636
  isAdasInitialized,
2497
2637
  isDevHost,
2638
+ isVisualKind,
2498
2639
  joinWithApple,
2499
2640
  joinWithGoogle,
2500
2641
  linkChannelStart,
@@ -2509,6 +2650,7 @@ export {
2509
2650
  nestByMaster,
2510
2651
  notifyAcsWsForeground,
2511
2652
  notifyAppForeground,
2653
+ numText,
2512
2654
  onAppForeground,
2513
2655
  openJoinWithApple,
2514
2656
  openJoinWithGoogle,
@@ -2542,6 +2684,8 @@ export {
2542
2684
  splitBlockSegments,
2543
2685
  switchTenant,
2544
2686
  tenantFromToken,
2687
+ timelineAsText,
2688
+ timelineView,
2545
2689
  unlinkChannel as unlinkNotifChannel,
2546
2690
  unregisterDevice as unregisterPushDevice,
2547
2691
  unwrapMcpResult,
@@ -2550,6 +2694,7 @@ export {
2550
2694
  useHomeActionsStore,
2551
2695
  useWidgetsStore,
2552
2696
  useWorkspaceStore,
2553
- userFromJwt
2697
+ userFromJwt,
2698
+ visualViewOf
2554
2699
  };
2555
2700
  //# sourceMappingURL=index.mjs.map