@ateam-ai-mobile/core 0.1.33 → 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
  }
@@ -1447,6 +1447,291 @@ async function prepareAttachments(attachments, onProgress) {
1447
1447
  return out;
1448
1448
  }
1449
1449
 
1450
+ // src/chat/blockText.ts
1451
+ var TABLE_BLOCK_OPEN = "\uE100";
1452
+ var TABLE_BLOCK_CLOSE = "\uE101";
1453
+ var DETAILS_BLOCK_OPEN = "\uE102";
1454
+ var DETAILS_BLOCK_CLOSE = "\uE103";
1455
+ var DIAGRAM_BLOCK_OPEN = "\uE104";
1456
+ var DIAGRAM_BLOCK_CLOSE = "\uE105";
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;
1464
+ var clean = (text) => text.replace(SENTINEL_CHARS, "");
1465
+ function renderTableShape(content) {
1466
+ if (!content || typeof content !== "object") return null;
1467
+ const cols = Array.isArray(content.columns) ? content.columns : null;
1468
+ const rows = Array.isArray(content.rows) ? content.rows : null;
1469
+ if (!cols || !rows) return null;
1470
+ const payload = encodeURIComponent(JSON.stringify({ columns: cols, rows }));
1471
+ return `${TABLE_BLOCK_OPEN}${payload}${TABLE_BLOCK_CLOSE}`;
1472
+ }
1473
+ var DIAGRAM_STATUSES = ["ok", "bad", "warn", "info"];
1474
+ var str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" ? String(v) : "";
1475
+ var statusOf = (v) => DIAGRAM_STATUSES.includes(v) ? v : "";
1476
+ function diagramView(content) {
1477
+ if (!content || typeof content !== "object" || !Array.isArray(content.steps)) return null;
1478
+ const steps = [];
1479
+ const kept = [];
1480
+ const rawNext = [];
1481
+ content.steps.forEach((s, i) => {
1482
+ kept[i + 1] = 0;
1483
+ if (!s || typeof s !== "object") return;
1484
+ const title = str(s.title);
1485
+ const text = str(s.text);
1486
+ if (!title && !text) return;
1487
+ const badges = [];
1488
+ for (const b of Array.isArray(s.badges) ? s.badges : []) {
1489
+ const bt = str(b && typeof b === "object" ? b.text : b);
1490
+ if (bt) badges.push({ text: bt, status: statusOf(b && b.status) });
1491
+ }
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
+ });
1525
+ }
1526
+ function diagramAsText(d) {
1527
+ const lines = d.title ? [d.title] : [];
1528
+ d.steps.forEach((s, i) => {
1529
+ const badges = s.badges.length ? ` [${s.badges.map((b) => b.text).join(", ")}]` : "";
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;
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
+ }
1590
+ return lines.join("\n");
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
+ }
1625
+ function fence(code, language) {
1626
+ const longest = (code.match(/`+/g) || []).reduce((n, run) => Math.max(n, run.length), 0);
1627
+ const ticks = "`".repeat(Math.max(3, longest + 1));
1628
+ return `${ticks}${language}
1629
+ ${code}
1630
+ ${ticks}`;
1631
+ }
1632
+ function blockText(b) {
1633
+ if (b.kind === "text" || b.kind === "markdown" || b.kind === "description") {
1634
+ return typeof b.content === "string" ? clean(b.content) : "";
1635
+ }
1636
+ if (b.kind === "code") {
1637
+ const nested = b.content && typeof b.content === "object";
1638
+ const code = nested ? b.content.content : b.content;
1639
+ if (typeof code !== "string" || !code.trim()) return "";
1640
+ const lang = clean(String((nested ? b.content.language : b.language) || "").trim());
1641
+ return fence(clean(code), lang && lang.toLowerCase() !== "auto" ? lang : "");
1642
+ }
1643
+ if (b.kind === "table" && b.content && typeof b.content === "object") {
1644
+ const md = renderTableShape(b.content);
1645
+ if (md) return md;
1646
+ }
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}`;
1651
+ }
1652
+ if (b.kind === "json") {
1653
+ const md = renderTableShape(b.content);
1654
+ if (md) return md;
1655
+ const pretty = JSON.stringify(b.content, null, 2);
1656
+ return typeof pretty === "string" ? fence(clean(pretty), "json") : "";
1657
+ }
1658
+ if (b.kind === "html") {
1659
+ return typeof b.content === "string" ? clean(b.content) : "";
1660
+ }
1661
+ if (typeof b.content === "string") return clean(b.content);
1662
+ return b.content === void 0 ? "" : clean(JSON.stringify(b.content) ?? "");
1663
+ }
1664
+ function blocksToText(blocks) {
1665
+ if (!blocks || blocks.length === 0) return "";
1666
+ return blocks.map((b) => {
1667
+ if (!b || typeof b !== "object") return "";
1668
+ const text = blockText(b);
1669
+ if (!text) return "";
1670
+ if (text.startsWith(TABLE_BLOCK_OPEN) || Object.values(VISUALS).some((v) => text.startsWith(v.open))) return text;
1671
+ return b.meta?.display === "folded" ? `${DETAILS_BLOCK_OPEN}${encodeURIComponent(text)}${DETAILS_BLOCK_CLOSE}` : text;
1672
+ }).filter(Boolean).join("\n\n");
1673
+ }
1674
+ var PAIRS = [
1675
+ { kind: "table", open: TABLE_BLOCK_OPEN, close: TABLE_BLOCK_CLOSE },
1676
+ { kind: "details", open: DETAILS_BLOCK_OPEN, close: DETAILS_BLOCK_CLOSE },
1677
+ ...Object.keys(VISUALS).map((kind) => ({ kind, open: VISUALS[kind].open, close: VISUALS[kind].close }))
1678
+ ];
1679
+ function splitBlockSegments(content) {
1680
+ const segments = [];
1681
+ if (!content) return segments;
1682
+ let cursor = 0;
1683
+ while (cursor < content.length) {
1684
+ let found = null;
1685
+ for (const pair of PAIRS) {
1686
+ const index = content.indexOf(pair.open, cursor);
1687
+ if (index !== -1 && (!found || index < found.index)) found = { index, pair };
1688
+ }
1689
+ if (!found) {
1690
+ segments.push({ kind: "md", content: content.slice(cursor) });
1691
+ break;
1692
+ }
1693
+ if (found.index > cursor) {
1694
+ segments.push({ kind: "md", content: content.slice(cursor, found.index) });
1695
+ }
1696
+ const close = content.indexOf(found.pair.close, found.index + found.pair.open.length);
1697
+ if (close === -1) {
1698
+ segments.push({ kind: "md", content: content.slice(found.index) });
1699
+ break;
1700
+ }
1701
+ segments.push({ kind: found.pair.kind, content: content.slice(found.index + found.pair.open.length, close) });
1702
+ cursor = close + found.pair.close.length;
1703
+ }
1704
+ return segments;
1705
+ }
1706
+ function tableAsText(payload) {
1707
+ try {
1708
+ const data = JSON.parse(decodeURIComponent(payload));
1709
+ const cols = Array.isArray(data?.columns) ? data.columns : [];
1710
+ const rows = Array.isArray(data?.rows) ? data.rows : [];
1711
+ const cell = (v) => v == null ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
1712
+ const line = (cells) => (Array.isArray(cells) ? cells : [cells]).map(cell).join(" | ");
1713
+ return [line(cols), ...rows.map(line)].join("\n");
1714
+ } catch {
1715
+ return "";
1716
+ }
1717
+ }
1718
+ function plainTextOf(content) {
1719
+ if (!content) return "";
1720
+ return splitBlockSegments(content).map((seg) => {
1721
+ if (seg.kind === "md") return seg.content;
1722
+ if (seg.kind === "table") return tableAsText(seg.content);
1723
+ if (isVisualKind(seg.kind)) {
1724
+ const view = visualViewOf(seg.kind, seg.content);
1725
+ return view ? VISUALS[seg.kind].asText(view) : "";
1726
+ }
1727
+ try {
1728
+ return decodeURIComponent(seg.content);
1729
+ } catch {
1730
+ return seg.content;
1731
+ }
1732
+ }).join("");
1733
+ }
1734
+
1450
1735
  // src/chat/store.ts
1451
1736
  function coreHeaders() {
1452
1737
  const token = getToken();
@@ -1526,48 +1811,6 @@ function isTerminalSnapshot(snap) {
1526
1811
  if (extractPendingQuestion(snap)) return false;
1527
1812
  return snap?.done === true || isTerminalStatus(snap?.status);
1528
1813
  }
1529
- var TABLE_BLOCK_OPEN = "\uE100";
1530
- var TABLE_BLOCK_CLOSE = "\uE101";
1531
- function renderTableShape(content) {
1532
- if (!content || typeof content !== "object") return null;
1533
- const cols = Array.isArray(content.columns) ? content.columns : null;
1534
- const rows = Array.isArray(content.rows) ? content.rows : null;
1535
- if (!cols || !rows) return null;
1536
- const payload = encodeURIComponent(JSON.stringify({ columns: cols, rows }));
1537
- return `${TABLE_BLOCK_OPEN}${payload}${TABLE_BLOCK_CLOSE}`;
1538
- }
1539
- function blocksToText(blocks) {
1540
- if (!blocks || blocks.length === 0) return "";
1541
- const hasTextBlock = blocks.some(
1542
- (b) => b.kind === "text" || b.kind === "markdown" || b.kind === "description"
1543
- );
1544
- return blocks.map((b) => {
1545
- if ((b.kind === "json" || b.kind === "code") && hasTextBlock) return "";
1546
- if (b.kind === "text" || b.kind === "markdown" || b.kind === "description") {
1547
- return typeof b.content === "string" ? b.content : "";
1548
- }
1549
- if (b.kind === "code") {
1550
- const code = typeof b.content === "object" ? b.content.content : b.content;
1551
- return `\`\`\`
1552
- ${code}
1553
- \`\`\``;
1554
- }
1555
- if (b.kind === "table" && b.content && typeof b.content === "object") {
1556
- const md = renderTableShape(b.content);
1557
- if (md) return md;
1558
- }
1559
- if (b.kind === "json") {
1560
- if (b.content && typeof b.content === "object" && "pendingQuestion" in b.content) return "";
1561
- const md = renderTableShape(b.content);
1562
- if (md) return md;
1563
- return "```json\n" + JSON.stringify(b.content, null, 2) + "\n```";
1564
- }
1565
- if (b.kind === "html") {
1566
- return typeof b.content === "string" ? b.content : "";
1567
- }
1568
- return typeof b.content === "string" ? b.content : JSON.stringify(b.content);
1569
- }).filter(Boolean).join("\n\n");
1570
- }
1571
1814
  function blocksToAttachments(blocks) {
1572
1815
  if (!blocks || blocks.length === 0) return void 0;
1573
1816
  const atts = [];
@@ -2334,25 +2577,45 @@ var borderRadius = {
2334
2577
  full: 9999
2335
2578
  };
2336
2579
  export {
2580
+ CHART_BLOCK_CLOSE,
2581
+ CHART_BLOCK_OPEN,
2582
+ COMPARISON_BLOCK_CLOSE,
2583
+ COMPARISON_BLOCK_OPEN,
2584
+ DETAILS_BLOCK_CLOSE,
2585
+ DETAILS_BLOCK_OPEN,
2586
+ DIAGRAM_BLOCK_CLOSE,
2587
+ DIAGRAM_BLOCK_OPEN,
2588
+ DIAGRAM_STATUSES,
2337
2589
  MAX_ATTACHMENT_BYTES,
2338
2590
  MAX_INLINE_ATTACHMENT_BYTES,
2339
2591
  PluginCommandEmitter,
2340
2592
  TABLE_BLOCK_CLOSE,
2341
2593
  TABLE_BLOCK_OPEN,
2594
+ TIMELINE_BLOCK_CLOSE,
2595
+ TIMELINE_BLOCK_OPEN,
2596
+ VISUALS,
2342
2597
  ada,
2343
2598
  apiFetch,
2344
2599
  apiFetchRaw,
2345
2600
  blocksToText,
2346
2601
  borderRadius,
2347
2602
  capabilityEnabled,
2603
+ chartAsText,
2604
+ chartScale,
2605
+ chartView,
2348
2606
  closeChatStream,
2349
2607
  colors,
2608
+ comparisonAsText,
2609
+ comparisonView,
2350
2610
  connectAcsWs,
2351
2611
  connectorCall,
2352
2612
  createAuthSession,
2353
2613
  createPushRegistration,
2354
2614
  deleteArtifact,
2355
2615
  devModeFromCatalog,
2616
+ diagramAsText,
2617
+ diagramFlow,
2618
+ diagramView,
2356
2619
  disconnectAcsWs,
2357
2620
  exchangeHandoff,
2358
2621
  fetchConsumerConfig,
@@ -2372,6 +2635,7 @@ export {
2372
2635
  initAdas,
2373
2636
  isAdasInitialized,
2374
2637
  isDevHost,
2638
+ isVisualKind,
2375
2639
  joinWithApple,
2376
2640
  joinWithGoogle,
2377
2641
  linkChannelStart,
@@ -2386,6 +2650,7 @@ export {
2386
2650
  nestByMaster,
2387
2651
  notifyAcsWsForeground,
2388
2652
  notifyAppForeground,
2653
+ numText,
2389
2654
  onAppForeground,
2390
2655
  openJoinWithApple,
2391
2656
  openJoinWithGoogle,
@@ -2394,6 +2659,7 @@ export {
2394
2659
  parseInviteCode,
2395
2660
  patchArtifact,
2396
2661
  patchHomeAction,
2662
+ plainTextOf,
2397
2663
  pluginCommandEmitter,
2398
2664
  postCommandResult,
2399
2665
  prepareAttachments,
@@ -2415,8 +2681,11 @@ export {
2415
2681
  signInWithApple,
2416
2682
  signInWithGoogle,
2417
2683
  spacing,
2684
+ splitBlockSegments,
2418
2685
  switchTenant,
2419
2686
  tenantFromToken,
2687
+ timelineAsText,
2688
+ timelineView,
2420
2689
  unlinkChannel as unlinkNotifChannel,
2421
2690
  unregisterDevice as unregisterPushDevice,
2422
2691
  unwrapMcpResult,
@@ -2425,6 +2694,7 @@ export {
2425
2694
  useHomeActionsStore,
2426
2695
  useWidgetsStore,
2427
2696
  useWorkspaceStore,
2428
- userFromJwt
2697
+ userFromJwt,
2698
+ visualViewOf
2429
2699
  };
2430
2700
  //# sourceMappingURL=index.mjs.map