@ateam-ai-mobile/core 0.1.33 → 0.1.35
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.d.mts +90 -20
- package/dist/index.d.ts +90 -20
- package/dist/index.js +176 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +167 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/blockText.ts +253 -0
- package/src/chat/store.ts +1 -70
- package/src/index.ts +13 -1
package/dist/index.mjs
CHANGED
|
@@ -1447,6 +1447,164 @@ 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 SENTINEL_CHARS = /[\uE100-\uE105]/g;
|
|
1458
|
+
var clean = (text) => text.replace(SENTINEL_CHARS, "");
|
|
1459
|
+
function renderTableShape(content) {
|
|
1460
|
+
if (!content || typeof content !== "object") return null;
|
|
1461
|
+
const cols = Array.isArray(content.columns) ? content.columns : null;
|
|
1462
|
+
const rows = Array.isArray(content.rows) ? content.rows : null;
|
|
1463
|
+
if (!cols || !rows) return null;
|
|
1464
|
+
const payload = encodeURIComponent(JSON.stringify({ columns: cols, rows }));
|
|
1465
|
+
return `${TABLE_BLOCK_OPEN}${payload}${TABLE_BLOCK_CLOSE}`;
|
|
1466
|
+
}
|
|
1467
|
+
var DIAGRAM_STATUSES = ["ok", "bad", "warn", "info"];
|
|
1468
|
+
var str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" ? String(v) : "";
|
|
1469
|
+
var statusOf = (v) => DIAGRAM_STATUSES.includes(v) ? v : "";
|
|
1470
|
+
function diagramView(content) {
|
|
1471
|
+
if (!content || typeof content !== "object" || !Array.isArray(content.steps)) return null;
|
|
1472
|
+
const steps = [];
|
|
1473
|
+
for (const s of content.steps) {
|
|
1474
|
+
if (!s || typeof s !== "object") continue;
|
|
1475
|
+
const title = str(s.title);
|
|
1476
|
+
const text = str(s.text);
|
|
1477
|
+
if (!title && !text) continue;
|
|
1478
|
+
const badges = [];
|
|
1479
|
+
for (const b of Array.isArray(s.badges) ? s.badges : []) {
|
|
1480
|
+
const bt = str(b && typeof b === "object" ? b.text : b);
|
|
1481
|
+
if (bt) badges.push({ text: bt, status: statusOf(b && b.status) });
|
|
1482
|
+
}
|
|
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 };
|
|
1486
|
+
}
|
|
1487
|
+
function diagramAsText(d) {
|
|
1488
|
+
const lines = d.title ? [d.title] : [];
|
|
1489
|
+
d.steps.forEach((s, i) => {
|
|
1490
|
+
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}`);
|
|
1492
|
+
});
|
|
1493
|
+
return lines.join("\n");
|
|
1494
|
+
}
|
|
1495
|
+
function fence(code, language) {
|
|
1496
|
+
const longest = (code.match(/`+/g) || []).reduce((n, run) => Math.max(n, run.length), 0);
|
|
1497
|
+
const ticks = "`".repeat(Math.max(3, longest + 1));
|
|
1498
|
+
return `${ticks}${language}
|
|
1499
|
+
${code}
|
|
1500
|
+
${ticks}`;
|
|
1501
|
+
}
|
|
1502
|
+
function blockText(b) {
|
|
1503
|
+
if (b.kind === "text" || b.kind === "markdown" || b.kind === "description") {
|
|
1504
|
+
return typeof b.content === "string" ? clean(b.content) : "";
|
|
1505
|
+
}
|
|
1506
|
+
if (b.kind === "code") {
|
|
1507
|
+
const nested = b.content && typeof b.content === "object";
|
|
1508
|
+
const code = nested ? b.content.content : b.content;
|
|
1509
|
+
if (typeof code !== "string" || !code.trim()) return "";
|
|
1510
|
+
const lang = clean(String((nested ? b.content.language : b.language) || "").trim());
|
|
1511
|
+
return fence(clean(code), lang && lang.toLowerCase() !== "auto" ? lang : "");
|
|
1512
|
+
}
|
|
1513
|
+
if (b.kind === "table" && b.content && typeof b.content === "object") {
|
|
1514
|
+
const md = renderTableShape(b.content);
|
|
1515
|
+
if (md) return md;
|
|
1516
|
+
}
|
|
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}`;
|
|
1520
|
+
}
|
|
1521
|
+
if (b.kind === "json") {
|
|
1522
|
+
const md = renderTableShape(b.content);
|
|
1523
|
+
if (md) return md;
|
|
1524
|
+
const pretty = JSON.stringify(b.content, null, 2);
|
|
1525
|
+
return typeof pretty === "string" ? fence(clean(pretty), "json") : "";
|
|
1526
|
+
}
|
|
1527
|
+
if (b.kind === "html") {
|
|
1528
|
+
return typeof b.content === "string" ? clean(b.content) : "";
|
|
1529
|
+
}
|
|
1530
|
+
if (typeof b.content === "string") return clean(b.content);
|
|
1531
|
+
return b.content === void 0 ? "" : clean(JSON.stringify(b.content) ?? "");
|
|
1532
|
+
}
|
|
1533
|
+
function blocksToText(blocks) {
|
|
1534
|
+
if (!blocks || blocks.length === 0) return "";
|
|
1535
|
+
return blocks.map((b) => {
|
|
1536
|
+
if (!b || typeof b !== "object") return "";
|
|
1537
|
+
const text = blockText(b);
|
|
1538
|
+
if (!text) return "";
|
|
1539
|
+
if (text.startsWith(TABLE_BLOCK_OPEN) || text.startsWith(DIAGRAM_BLOCK_OPEN)) return text;
|
|
1540
|
+
return b.meta?.display === "folded" ? `${DETAILS_BLOCK_OPEN}${encodeURIComponent(text)}${DETAILS_BLOCK_CLOSE}` : text;
|
|
1541
|
+
}).filter(Boolean).join("\n\n");
|
|
1542
|
+
}
|
|
1543
|
+
var PAIRS = [
|
|
1544
|
+
{ kind: "table", open: TABLE_BLOCK_OPEN, close: TABLE_BLOCK_CLOSE },
|
|
1545
|
+
{ kind: "details", open: DETAILS_BLOCK_OPEN, close: DETAILS_BLOCK_CLOSE },
|
|
1546
|
+
{ kind: "diagram", open: DIAGRAM_BLOCK_OPEN, close: DIAGRAM_BLOCK_CLOSE }
|
|
1547
|
+
];
|
|
1548
|
+
function splitBlockSegments(content) {
|
|
1549
|
+
const segments = [];
|
|
1550
|
+
if (!content) return segments;
|
|
1551
|
+
let cursor = 0;
|
|
1552
|
+
while (cursor < content.length) {
|
|
1553
|
+
let found = null;
|
|
1554
|
+
for (const pair of PAIRS) {
|
|
1555
|
+
const index = content.indexOf(pair.open, cursor);
|
|
1556
|
+
if (index !== -1 && (!found || index < found.index)) found = { index, pair };
|
|
1557
|
+
}
|
|
1558
|
+
if (!found) {
|
|
1559
|
+
segments.push({ kind: "md", content: content.slice(cursor) });
|
|
1560
|
+
break;
|
|
1561
|
+
}
|
|
1562
|
+
if (found.index > cursor) {
|
|
1563
|
+
segments.push({ kind: "md", content: content.slice(cursor, found.index) });
|
|
1564
|
+
}
|
|
1565
|
+
const close = content.indexOf(found.pair.close, found.index + found.pair.open.length);
|
|
1566
|
+
if (close === -1) {
|
|
1567
|
+
segments.push({ kind: "md", content: content.slice(found.index) });
|
|
1568
|
+
break;
|
|
1569
|
+
}
|
|
1570
|
+
segments.push({ kind: found.pair.kind, content: content.slice(found.index + found.pair.open.length, close) });
|
|
1571
|
+
cursor = close + found.pair.close.length;
|
|
1572
|
+
}
|
|
1573
|
+
return segments;
|
|
1574
|
+
}
|
|
1575
|
+
function tableAsText(payload) {
|
|
1576
|
+
try {
|
|
1577
|
+
const data = JSON.parse(decodeURIComponent(payload));
|
|
1578
|
+
const cols = Array.isArray(data?.columns) ? data.columns : [];
|
|
1579
|
+
const rows = Array.isArray(data?.rows) ? data.rows : [];
|
|
1580
|
+
const cell = (v) => v == null ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
1581
|
+
const line = (cells) => (Array.isArray(cells) ? cells : [cells]).map(cell).join(" | ");
|
|
1582
|
+
return [line(cols), ...rows.map(line)].join("\n");
|
|
1583
|
+
} catch {
|
|
1584
|
+
return "";
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
function plainTextOf(content) {
|
|
1588
|
+
if (!content) return "";
|
|
1589
|
+
return splitBlockSegments(content).map((seg) => {
|
|
1590
|
+
if (seg.kind === "md") return seg.content;
|
|
1591
|
+
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
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
try {
|
|
1601
|
+
return decodeURIComponent(seg.content);
|
|
1602
|
+
} catch {
|
|
1603
|
+
return seg.content;
|
|
1604
|
+
}
|
|
1605
|
+
}).join("");
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1450
1608
|
// src/chat/store.ts
|
|
1451
1609
|
function coreHeaders() {
|
|
1452
1610
|
const token = getToken();
|
|
@@ -1526,48 +1684,6 @@ function isTerminalSnapshot(snap) {
|
|
|
1526
1684
|
if (extractPendingQuestion(snap)) return false;
|
|
1527
1685
|
return snap?.done === true || isTerminalStatus(snap?.status);
|
|
1528
1686
|
}
|
|
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
1687
|
function blocksToAttachments(blocks) {
|
|
1572
1688
|
if (!blocks || blocks.length === 0) return void 0;
|
|
1573
1689
|
const atts = [];
|
|
@@ -2334,6 +2450,11 @@ var borderRadius = {
|
|
|
2334
2450
|
full: 9999
|
|
2335
2451
|
};
|
|
2336
2452
|
export {
|
|
2453
|
+
DETAILS_BLOCK_CLOSE,
|
|
2454
|
+
DETAILS_BLOCK_OPEN,
|
|
2455
|
+
DIAGRAM_BLOCK_CLOSE,
|
|
2456
|
+
DIAGRAM_BLOCK_OPEN,
|
|
2457
|
+
DIAGRAM_STATUSES,
|
|
2337
2458
|
MAX_ATTACHMENT_BYTES,
|
|
2338
2459
|
MAX_INLINE_ATTACHMENT_BYTES,
|
|
2339
2460
|
PluginCommandEmitter,
|
|
@@ -2353,6 +2474,8 @@ export {
|
|
|
2353
2474
|
createPushRegistration,
|
|
2354
2475
|
deleteArtifact,
|
|
2355
2476
|
devModeFromCatalog,
|
|
2477
|
+
diagramAsText,
|
|
2478
|
+
diagramView,
|
|
2356
2479
|
disconnectAcsWs,
|
|
2357
2480
|
exchangeHandoff,
|
|
2358
2481
|
fetchConsumerConfig,
|
|
@@ -2394,6 +2517,7 @@ export {
|
|
|
2394
2517
|
parseInviteCode,
|
|
2395
2518
|
patchArtifact,
|
|
2396
2519
|
patchHomeAction,
|
|
2520
|
+
plainTextOf,
|
|
2397
2521
|
pluginCommandEmitter,
|
|
2398
2522
|
postCommandResult,
|
|
2399
2523
|
prepareAttachments,
|
|
@@ -2415,6 +2539,7 @@ export {
|
|
|
2415
2539
|
signInWithApple,
|
|
2416
2540
|
signInWithGoogle,
|
|
2417
2541
|
spacing,
|
|
2542
|
+
splitBlockSegments,
|
|
2418
2543
|
switchTenant,
|
|
2419
2544
|
tenantFromToken,
|
|
2420
2545
|
unlinkChannel as unlinkNotifChannel,
|