@ateam-ai-mobile/core 0.1.32 → 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 +166 -22
- package/dist/index.d.ts +166 -22
- package/dist/index.js +297 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +285 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/attachments.ts +139 -0
- package/src/chat/blockText.ts +253 -0
- package/src/chat/store.ts +19 -74
- package/src/chat/types.ts +2 -0
- package/src/config.ts +4 -1
- package/src/index.ts +19 -1
- package/src/storage/types.ts +57 -2
package/dist/index.js
CHANGED
|
@@ -20,6 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
DETAILS_BLOCK_CLOSE: () => DETAILS_BLOCK_CLOSE,
|
|
24
|
+
DETAILS_BLOCK_OPEN: () => DETAILS_BLOCK_OPEN,
|
|
25
|
+
DIAGRAM_BLOCK_CLOSE: () => DIAGRAM_BLOCK_CLOSE,
|
|
26
|
+
DIAGRAM_BLOCK_OPEN: () => DIAGRAM_BLOCK_OPEN,
|
|
27
|
+
DIAGRAM_STATUSES: () => DIAGRAM_STATUSES,
|
|
28
|
+
MAX_ATTACHMENT_BYTES: () => MAX_ATTACHMENT_BYTES,
|
|
29
|
+
MAX_INLINE_ATTACHMENT_BYTES: () => MAX_INLINE_ATTACHMENT_BYTES,
|
|
23
30
|
PluginCommandEmitter: () => PluginCommandEmitter,
|
|
24
31
|
TABLE_BLOCK_CLOSE: () => TABLE_BLOCK_CLOSE,
|
|
25
32
|
TABLE_BLOCK_OPEN: () => TABLE_BLOCK_OPEN,
|
|
@@ -37,6 +44,8 @@ __export(index_exports, {
|
|
|
37
44
|
createPushRegistration: () => createPushRegistration,
|
|
38
45
|
deleteArtifact: () => deleteArtifact,
|
|
39
46
|
devModeFromCatalog: () => devModeFromCatalog,
|
|
47
|
+
diagramAsText: () => diagramAsText,
|
|
48
|
+
diagramView: () => diagramView,
|
|
40
49
|
disconnectAcsWs: () => disconnectAcsWs,
|
|
41
50
|
exchangeHandoff: () => exchangeHandoff,
|
|
42
51
|
fetchConsumerConfig: () => fetchConsumerConfig,
|
|
@@ -78,8 +87,10 @@ __export(index_exports, {
|
|
|
78
87
|
parseInviteCode: () => parseInviteCode,
|
|
79
88
|
patchArtifact: () => patchArtifact,
|
|
80
89
|
patchHomeAction: () => patchHomeAction,
|
|
90
|
+
plainTextOf: () => plainTextOf,
|
|
81
91
|
pluginCommandEmitter: () => pluginCommandEmitter,
|
|
82
92
|
postCommandResult: () => postCommandResult,
|
|
93
|
+
prepareAttachments: () => prepareAttachments,
|
|
83
94
|
previewInvite: () => previewInvite,
|
|
84
95
|
readDevMode: () => readDevMode,
|
|
85
96
|
recentNotifDispatches: () => recentDispatches,
|
|
@@ -98,6 +109,7 @@ __export(index_exports, {
|
|
|
98
109
|
signInWithApple: () => signInWithApple,
|
|
99
110
|
signInWithGoogle: () => signInWithGoogle,
|
|
100
111
|
spacing: () => spacing,
|
|
112
|
+
splitBlockSegments: () => splitBlockSegments,
|
|
101
113
|
switchTenant: () => switchTenant,
|
|
102
114
|
tenantFromToken: () => tenantFromToken,
|
|
103
115
|
unlinkNotifChannel: () => unlinkChannel,
|
|
@@ -1461,6 +1473,264 @@ function focusPlugin(pluginId, props) {
|
|
|
1461
1473
|
pluginCommandEmitter.emit("focus-plugin", { pluginId, props });
|
|
1462
1474
|
}
|
|
1463
1475
|
|
|
1476
|
+
// src/storage/types.ts
|
|
1477
|
+
var MAX_ATTACHMENT_BYTES = 90 * 1024 * 1024;
|
|
1478
|
+
var MAX_INLINE_ATTACHMENT_BYTES = 7 * 1024 * 1024;
|
|
1479
|
+
|
|
1480
|
+
// src/chat/attachments.ts
|
|
1481
|
+
var mb = (bytes) => Math.round(bytes / 1024 / 1024);
|
|
1482
|
+
var base64Length = (bytes) => Math.ceil(bytes / 3) * 4;
|
|
1483
|
+
var MAX_INLINE_CHARS = base64Length(MAX_INLINE_ATTACHMENT_BYTES);
|
|
1484
|
+
function tooLarge(name) {
|
|
1485
|
+
return new Error(`"${name}" is too large (max ${mb(MAX_ATTACHMENT_BYTES)} MB)`);
|
|
1486
|
+
}
|
|
1487
|
+
function errorFrom(status, body, name) {
|
|
1488
|
+
let message = "";
|
|
1489
|
+
try {
|
|
1490
|
+
message = String(JSON.parse(body)?.error || "");
|
|
1491
|
+
} catch {
|
|
1492
|
+
}
|
|
1493
|
+
if (status === 413) {
|
|
1494
|
+
return new Error(message || `This server can't take files this big yet ("${name}")`);
|
|
1495
|
+
}
|
|
1496
|
+
if (status === 429) return new Error(message || "Too many uploads: wait a moment and try again");
|
|
1497
|
+
return new Error(message || `The upload of "${name}" failed (${status})`);
|
|
1498
|
+
}
|
|
1499
|
+
async function sendRaw(uploader, att, onProgress) {
|
|
1500
|
+
const query = new URLSearchParams({ mimeType: att.mimeType || "application/octet-stream", name: att.name || "upload" });
|
|
1501
|
+
const url = `${getCoreApiUrl()}/api/artifacts?${query.toString()}`;
|
|
1502
|
+
const attempt = () => {
|
|
1503
|
+
const token = getToken();
|
|
1504
|
+
return uploader.upload({
|
|
1505
|
+
url,
|
|
1506
|
+
uri: att.uri,
|
|
1507
|
+
headers: {
|
|
1508
|
+
"Content-Type": "application/octet-stream",
|
|
1509
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
1510
|
+
},
|
|
1511
|
+
onProgress
|
|
1512
|
+
});
|
|
1513
|
+
};
|
|
1514
|
+
let res = await attempt();
|
|
1515
|
+
if (res.status === 401 && getToken()) {
|
|
1516
|
+
const outcome = await refreshToken();
|
|
1517
|
+
if (outcome.ok === "ok") {
|
|
1518
|
+
res = await attempt();
|
|
1519
|
+
if (res.status === 401 || res.status === 403) {
|
|
1520
|
+
notifyAuthFailure();
|
|
1521
|
+
throw new Error("Session expired: sign in again to upload this file");
|
|
1522
|
+
}
|
|
1523
|
+
} else if (outcome.ok === "auth_failed") {
|
|
1524
|
+
notifyAuthFailure();
|
|
1525
|
+
throw new Error("Session expired: sign in again to upload this file");
|
|
1526
|
+
} else {
|
|
1527
|
+
throw new Error("Could not reach the server to refresh your sign-in: check your connection and try again");
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return res;
|
|
1531
|
+
}
|
|
1532
|
+
async function uploadOne(att, onProgress, budget) {
|
|
1533
|
+
const name = att.name || "attachment";
|
|
1534
|
+
if (att.data !== void 0) return { data: att.data, mimeType: att.mimeType, name: att.name };
|
|
1535
|
+
if (!att.uri) throw new Error(`The attachment "${name}" has no file to send`);
|
|
1536
|
+
if (att.size !== void 0 && att.size > MAX_ATTACHMENT_BYTES) throw tooLarge(name);
|
|
1537
|
+
const uploader = getConfig().fileUploader;
|
|
1538
|
+
if (!uploader) throw new Error("This app cannot upload files yet: initAdas needs a fileUploader");
|
|
1539
|
+
const res = await sendRaw(uploader, att, onProgress);
|
|
1540
|
+
if (res.status >= 200 && res.status < 300) {
|
|
1541
|
+
let parsed = null;
|
|
1542
|
+
try {
|
|
1543
|
+
parsed = JSON.parse(res.body);
|
|
1544
|
+
} catch {
|
|
1545
|
+
}
|
|
1546
|
+
if (parsed?.ok && typeof parsed.hash === "string") {
|
|
1547
|
+
onProgress(1);
|
|
1548
|
+
return { hash: parsed.hash, name: att.name, mimeType: parsed.mimeType || att.mimeType };
|
|
1549
|
+
}
|
|
1550
|
+
throw errorFrom(res.status, res.body, name);
|
|
1551
|
+
}
|
|
1552
|
+
if (res.status === 400) {
|
|
1553
|
+
const size = att.size !== void 0 ? att.size : await uploader.fileSize?.(att.uri);
|
|
1554
|
+
if (size === void 0) {
|
|
1555
|
+
throw new Error(`Cannot tell how big "${name}" is, and this server cannot take large files yet`);
|
|
1556
|
+
}
|
|
1557
|
+
if (base64Length(size) > budget.chars) {
|
|
1558
|
+
throw new Error(`"${name}" is too big for this server, which cannot take more than ${mb(MAX_INLINE_ATTACHMENT_BYTES)} MB of files in one message yet`);
|
|
1559
|
+
}
|
|
1560
|
+
const data = await uploader.readBase64(att.uri);
|
|
1561
|
+
budget.chars -= data.length;
|
|
1562
|
+
onProgress(1);
|
|
1563
|
+
return { data, mimeType: att.mimeType, name: att.name };
|
|
1564
|
+
}
|
|
1565
|
+
throw errorFrom(res.status, res.body, name);
|
|
1566
|
+
}
|
|
1567
|
+
async function prepareAttachments(attachments, onProgress) {
|
|
1568
|
+
const budget = { chars: MAX_INLINE_CHARS - attachments.reduce((n, a) => n + (a.data !== void 0 ? a.data.length : 0), 0) };
|
|
1569
|
+
const out = [];
|
|
1570
|
+
for (let i = 0; i < attachments.length; i++) {
|
|
1571
|
+
out.push(await uploadOne(attachments[i], (f) => onProgress?.((i + f) / attachments.length), budget));
|
|
1572
|
+
}
|
|
1573
|
+
return out;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
// src/chat/blockText.ts
|
|
1577
|
+
var TABLE_BLOCK_OPEN = "\uE100";
|
|
1578
|
+
var TABLE_BLOCK_CLOSE = "\uE101";
|
|
1579
|
+
var DETAILS_BLOCK_OPEN = "\uE102";
|
|
1580
|
+
var DETAILS_BLOCK_CLOSE = "\uE103";
|
|
1581
|
+
var DIAGRAM_BLOCK_OPEN = "\uE104";
|
|
1582
|
+
var DIAGRAM_BLOCK_CLOSE = "\uE105";
|
|
1583
|
+
var SENTINEL_CHARS = /[\uE100-\uE105]/g;
|
|
1584
|
+
var clean = (text) => text.replace(SENTINEL_CHARS, "");
|
|
1585
|
+
function renderTableShape(content) {
|
|
1586
|
+
if (!content || typeof content !== "object") return null;
|
|
1587
|
+
const cols = Array.isArray(content.columns) ? content.columns : null;
|
|
1588
|
+
const rows = Array.isArray(content.rows) ? content.rows : null;
|
|
1589
|
+
if (!cols || !rows) return null;
|
|
1590
|
+
const payload = encodeURIComponent(JSON.stringify({ columns: cols, rows }));
|
|
1591
|
+
return `${TABLE_BLOCK_OPEN}${payload}${TABLE_BLOCK_CLOSE}`;
|
|
1592
|
+
}
|
|
1593
|
+
var DIAGRAM_STATUSES = ["ok", "bad", "warn", "info"];
|
|
1594
|
+
var str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" ? String(v) : "";
|
|
1595
|
+
var statusOf = (v) => DIAGRAM_STATUSES.includes(v) ? v : "";
|
|
1596
|
+
function diagramView(content) {
|
|
1597
|
+
if (!content || typeof content !== "object" || !Array.isArray(content.steps)) return null;
|
|
1598
|
+
const steps = [];
|
|
1599
|
+
for (const s of content.steps) {
|
|
1600
|
+
if (!s || typeof s !== "object") continue;
|
|
1601
|
+
const title = str(s.title);
|
|
1602
|
+
const text = str(s.text);
|
|
1603
|
+
if (!title && !text) continue;
|
|
1604
|
+
const badges = [];
|
|
1605
|
+
for (const b of Array.isArray(s.badges) ? s.badges : []) {
|
|
1606
|
+
const bt = str(b && typeof b === "object" ? b.text : b);
|
|
1607
|
+
if (bt) badges.push({ text: bt, status: statusOf(b && b.status) });
|
|
1608
|
+
}
|
|
1609
|
+
steps.push({ title: title || text, text: title ? text : "", status: statusOf(s.status), badges });
|
|
1610
|
+
}
|
|
1611
|
+
return steps.length < 2 ? null : { title: str(content.title), steps };
|
|
1612
|
+
}
|
|
1613
|
+
function diagramAsText(d) {
|
|
1614
|
+
const lines = d.title ? [d.title] : [];
|
|
1615
|
+
d.steps.forEach((s, i) => {
|
|
1616
|
+
const badges = s.badges.length ? ` [${s.badges.map((b) => b.text).join(", ")}]` : "";
|
|
1617
|
+
lines.push(`${i + 1}. ${s.title}${s.text ? ` \u2014 ${s.text}` : ""}${badges}`);
|
|
1618
|
+
});
|
|
1619
|
+
return lines.join("\n");
|
|
1620
|
+
}
|
|
1621
|
+
function fence(code, language) {
|
|
1622
|
+
const longest = (code.match(/`+/g) || []).reduce((n, run) => Math.max(n, run.length), 0);
|
|
1623
|
+
const ticks = "`".repeat(Math.max(3, longest + 1));
|
|
1624
|
+
return `${ticks}${language}
|
|
1625
|
+
${code}
|
|
1626
|
+
${ticks}`;
|
|
1627
|
+
}
|
|
1628
|
+
function blockText(b) {
|
|
1629
|
+
if (b.kind === "text" || b.kind === "markdown" || b.kind === "description") {
|
|
1630
|
+
return typeof b.content === "string" ? clean(b.content) : "";
|
|
1631
|
+
}
|
|
1632
|
+
if (b.kind === "code") {
|
|
1633
|
+
const nested = b.content && typeof b.content === "object";
|
|
1634
|
+
const code = nested ? b.content.content : b.content;
|
|
1635
|
+
if (typeof code !== "string" || !code.trim()) return "";
|
|
1636
|
+
const lang = clean(String((nested ? b.content.language : b.language) || "").trim());
|
|
1637
|
+
return fence(clean(code), lang && lang.toLowerCase() !== "auto" ? lang : "");
|
|
1638
|
+
}
|
|
1639
|
+
if (b.kind === "table" && b.content && typeof b.content === "object") {
|
|
1640
|
+
const md = renderTableShape(b.content);
|
|
1641
|
+
if (md) return md;
|
|
1642
|
+
}
|
|
1643
|
+
if (b.kind === "diagram") {
|
|
1644
|
+
const view = diagramView(b.content);
|
|
1645
|
+
if (view) return `${DIAGRAM_BLOCK_OPEN}${encodeURIComponent(JSON.stringify(view))}${DIAGRAM_BLOCK_CLOSE}`;
|
|
1646
|
+
}
|
|
1647
|
+
if (b.kind === "json") {
|
|
1648
|
+
const md = renderTableShape(b.content);
|
|
1649
|
+
if (md) return md;
|
|
1650
|
+
const pretty = JSON.stringify(b.content, null, 2);
|
|
1651
|
+
return typeof pretty === "string" ? fence(clean(pretty), "json") : "";
|
|
1652
|
+
}
|
|
1653
|
+
if (b.kind === "html") {
|
|
1654
|
+
return typeof b.content === "string" ? clean(b.content) : "";
|
|
1655
|
+
}
|
|
1656
|
+
if (typeof b.content === "string") return clean(b.content);
|
|
1657
|
+
return b.content === void 0 ? "" : clean(JSON.stringify(b.content) ?? "");
|
|
1658
|
+
}
|
|
1659
|
+
function blocksToText(blocks) {
|
|
1660
|
+
if (!blocks || blocks.length === 0) return "";
|
|
1661
|
+
return blocks.map((b) => {
|
|
1662
|
+
if (!b || typeof b !== "object") return "";
|
|
1663
|
+
const text = blockText(b);
|
|
1664
|
+
if (!text) return "";
|
|
1665
|
+
if (text.startsWith(TABLE_BLOCK_OPEN) || text.startsWith(DIAGRAM_BLOCK_OPEN)) return text;
|
|
1666
|
+
return b.meta?.display === "folded" ? `${DETAILS_BLOCK_OPEN}${encodeURIComponent(text)}${DETAILS_BLOCK_CLOSE}` : text;
|
|
1667
|
+
}).filter(Boolean).join("\n\n");
|
|
1668
|
+
}
|
|
1669
|
+
var PAIRS = [
|
|
1670
|
+
{ kind: "table", open: TABLE_BLOCK_OPEN, close: TABLE_BLOCK_CLOSE },
|
|
1671
|
+
{ kind: "details", open: DETAILS_BLOCK_OPEN, close: DETAILS_BLOCK_CLOSE },
|
|
1672
|
+
{ kind: "diagram", open: DIAGRAM_BLOCK_OPEN, close: DIAGRAM_BLOCK_CLOSE }
|
|
1673
|
+
];
|
|
1674
|
+
function splitBlockSegments(content) {
|
|
1675
|
+
const segments = [];
|
|
1676
|
+
if (!content) return segments;
|
|
1677
|
+
let cursor = 0;
|
|
1678
|
+
while (cursor < content.length) {
|
|
1679
|
+
let found = null;
|
|
1680
|
+
for (const pair of PAIRS) {
|
|
1681
|
+
const index = content.indexOf(pair.open, cursor);
|
|
1682
|
+
if (index !== -1 && (!found || index < found.index)) found = { index, pair };
|
|
1683
|
+
}
|
|
1684
|
+
if (!found) {
|
|
1685
|
+
segments.push({ kind: "md", content: content.slice(cursor) });
|
|
1686
|
+
break;
|
|
1687
|
+
}
|
|
1688
|
+
if (found.index > cursor) {
|
|
1689
|
+
segments.push({ kind: "md", content: content.slice(cursor, found.index) });
|
|
1690
|
+
}
|
|
1691
|
+
const close = content.indexOf(found.pair.close, found.index + found.pair.open.length);
|
|
1692
|
+
if (close === -1) {
|
|
1693
|
+
segments.push({ kind: "md", content: content.slice(found.index) });
|
|
1694
|
+
break;
|
|
1695
|
+
}
|
|
1696
|
+
segments.push({ kind: found.pair.kind, content: content.slice(found.index + found.pair.open.length, close) });
|
|
1697
|
+
cursor = close + found.pair.close.length;
|
|
1698
|
+
}
|
|
1699
|
+
return segments;
|
|
1700
|
+
}
|
|
1701
|
+
function tableAsText(payload) {
|
|
1702
|
+
try {
|
|
1703
|
+
const data = JSON.parse(decodeURIComponent(payload));
|
|
1704
|
+
const cols = Array.isArray(data?.columns) ? data.columns : [];
|
|
1705
|
+
const rows = Array.isArray(data?.rows) ? data.rows : [];
|
|
1706
|
+
const cell = (v) => v == null ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
1707
|
+
const line = (cells) => (Array.isArray(cells) ? cells : [cells]).map(cell).join(" | ");
|
|
1708
|
+
return [line(cols), ...rows.map(line)].join("\n");
|
|
1709
|
+
} catch {
|
|
1710
|
+
return "";
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
function plainTextOf(content) {
|
|
1714
|
+
if (!content) return "";
|
|
1715
|
+
return splitBlockSegments(content).map((seg) => {
|
|
1716
|
+
if (seg.kind === "md") return seg.content;
|
|
1717
|
+
if (seg.kind === "table") return tableAsText(seg.content);
|
|
1718
|
+
if (seg.kind === "diagram") {
|
|
1719
|
+
try {
|
|
1720
|
+
const view = diagramView(JSON.parse(decodeURIComponent(seg.content)));
|
|
1721
|
+
return view ? diagramAsText(view) : "";
|
|
1722
|
+
} catch {
|
|
1723
|
+
return "";
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
try {
|
|
1727
|
+
return decodeURIComponent(seg.content);
|
|
1728
|
+
} catch {
|
|
1729
|
+
return seg.content;
|
|
1730
|
+
}
|
|
1731
|
+
}).join("");
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1464
1734
|
// src/chat/store.ts
|
|
1465
1735
|
function coreHeaders() {
|
|
1466
1736
|
const token = getToken();
|
|
@@ -1540,48 +1810,6 @@ function isTerminalSnapshot(snap) {
|
|
|
1540
1810
|
if (extractPendingQuestion(snap)) return false;
|
|
1541
1811
|
return snap?.done === true || isTerminalStatus(snap?.status);
|
|
1542
1812
|
}
|
|
1543
|
-
var TABLE_BLOCK_OPEN = "\uE100";
|
|
1544
|
-
var TABLE_BLOCK_CLOSE = "\uE101";
|
|
1545
|
-
function renderTableShape(content) {
|
|
1546
|
-
if (!content || typeof content !== "object") return null;
|
|
1547
|
-
const cols = Array.isArray(content.columns) ? content.columns : null;
|
|
1548
|
-
const rows = Array.isArray(content.rows) ? content.rows : null;
|
|
1549
|
-
if (!cols || !rows) return null;
|
|
1550
|
-
const payload = encodeURIComponent(JSON.stringify({ columns: cols, rows }));
|
|
1551
|
-
return `${TABLE_BLOCK_OPEN}${payload}${TABLE_BLOCK_CLOSE}`;
|
|
1552
|
-
}
|
|
1553
|
-
function blocksToText(blocks) {
|
|
1554
|
-
if (!blocks || blocks.length === 0) return "";
|
|
1555
|
-
const hasTextBlock = blocks.some(
|
|
1556
|
-
(b) => b.kind === "text" || b.kind === "markdown" || b.kind === "description"
|
|
1557
|
-
);
|
|
1558
|
-
return blocks.map((b) => {
|
|
1559
|
-
if ((b.kind === "json" || b.kind === "code") && hasTextBlock) return "";
|
|
1560
|
-
if (b.kind === "text" || b.kind === "markdown" || b.kind === "description") {
|
|
1561
|
-
return typeof b.content === "string" ? b.content : "";
|
|
1562
|
-
}
|
|
1563
|
-
if (b.kind === "code") {
|
|
1564
|
-
const code = typeof b.content === "object" ? b.content.content : b.content;
|
|
1565
|
-
return `\`\`\`
|
|
1566
|
-
${code}
|
|
1567
|
-
\`\`\``;
|
|
1568
|
-
}
|
|
1569
|
-
if (b.kind === "table" && b.content && typeof b.content === "object") {
|
|
1570
|
-
const md = renderTableShape(b.content);
|
|
1571
|
-
if (md) return md;
|
|
1572
|
-
}
|
|
1573
|
-
if (b.kind === "json") {
|
|
1574
|
-
if (b.content && typeof b.content === "object" && "pendingQuestion" in b.content) return "";
|
|
1575
|
-
const md = renderTableShape(b.content);
|
|
1576
|
-
if (md) return md;
|
|
1577
|
-
return "```json\n" + JSON.stringify(b.content, null, 2) + "\n```";
|
|
1578
|
-
}
|
|
1579
|
-
if (b.kind === "html") {
|
|
1580
|
-
return typeof b.content === "string" ? b.content : "";
|
|
1581
|
-
}
|
|
1582
|
-
return typeof b.content === "string" ? b.content : JSON.stringify(b.content);
|
|
1583
|
-
}).filter(Boolean).join("\n\n");
|
|
1584
|
-
}
|
|
1585
1813
|
function blocksToAttachments(blocks) {
|
|
1586
1814
|
if (!blocks || blocks.length === 0) return void 0;
|
|
1587
1815
|
const atts = [];
|
|
@@ -1795,8 +2023,11 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
|
|
|
1795
2023
|
attachments: attachments.map((a) => ({
|
|
1796
2024
|
mimeType: a.mimeType,
|
|
1797
2025
|
name: a.name,
|
|
1798
|
-
|
|
1799
|
-
|
|
2026
|
+
// An image on the phone previews from its own file; an inline one from its base64.
|
|
2027
|
+
previewUri: !a.mimeType.startsWith("image/") ? void 0 : a.data !== void 0 ? `data:${a.mimeType};base64,${a.data}` : a.uri
|
|
2028
|
+
})),
|
|
2029
|
+
// A file on the phone is uploaded before the message is posted: the bubble shows how far along it is.
|
|
2030
|
+
...attachments.some((a) => a.uri && a.data === void 0) ? { uploadProgress: 0 } : {}
|
|
1800
2031
|
} : {}
|
|
1801
2032
|
};
|
|
1802
2033
|
set((s) => ({ messages: [...s.messages, userMsg], loading: true, error: null }));
|
|
@@ -1813,7 +2044,15 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
|
|
|
1813
2044
|
}
|
|
1814
2045
|
};
|
|
1815
2046
|
if (skillSlug) body.skillSlug = skillSlug;
|
|
1816
|
-
if (attachments?.length)
|
|
2047
|
+
if (attachments?.length) {
|
|
2048
|
+
let shown = 0;
|
|
2049
|
+
body.attachments = await prepareAttachments(attachments, (f) => {
|
|
2050
|
+
if (f - shown < 0.01 && f < 1) return;
|
|
2051
|
+
shown = f;
|
|
2052
|
+
set((s) => ({ messages: s.messages.map((m) => m.id === userMsg.id && m.uploadProgress !== void 0 ? { ...m, uploadProgress: f } : m) }));
|
|
2053
|
+
});
|
|
2054
|
+
set((s) => ({ messages: s.messages.map((m) => m.id === userMsg.id ? { ...m, uploadProgress: void 0 } : m) }));
|
|
2055
|
+
}
|
|
1817
2056
|
const res = await fetch(`${getCoreApiUrl()}/api/chat`, {
|
|
1818
2057
|
method: "POST",
|
|
1819
2058
|
headers: coreHeaders(),
|
|
@@ -1880,7 +2119,7 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
|
|
|
1880
2119
|
streamJob(jobId, getTenant(), getToken());
|
|
1881
2120
|
} catch (err) {
|
|
1882
2121
|
set((s) => ({
|
|
1883
|
-
messages: [...s.messages, {
|
|
2122
|
+
messages: [...s.messages.map((m) => m.id === userMsg.id && m.uploadProgress !== void 0 ? { ...m, uploadProgress: void 0 } : m), {
|
|
1884
2123
|
id: `error-${Date.now()}`,
|
|
1885
2124
|
role: "system",
|
|
1886
2125
|
content: `Error: ${err.message}`,
|
|
@@ -2338,6 +2577,13 @@ var borderRadius = {
|
|
|
2338
2577
|
};
|
|
2339
2578
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2340
2579
|
0 && (module.exports = {
|
|
2580
|
+
DETAILS_BLOCK_CLOSE,
|
|
2581
|
+
DETAILS_BLOCK_OPEN,
|
|
2582
|
+
DIAGRAM_BLOCK_CLOSE,
|
|
2583
|
+
DIAGRAM_BLOCK_OPEN,
|
|
2584
|
+
DIAGRAM_STATUSES,
|
|
2585
|
+
MAX_ATTACHMENT_BYTES,
|
|
2586
|
+
MAX_INLINE_ATTACHMENT_BYTES,
|
|
2341
2587
|
PluginCommandEmitter,
|
|
2342
2588
|
TABLE_BLOCK_CLOSE,
|
|
2343
2589
|
TABLE_BLOCK_OPEN,
|
|
@@ -2355,6 +2601,8 @@ var borderRadius = {
|
|
|
2355
2601
|
createPushRegistration,
|
|
2356
2602
|
deleteArtifact,
|
|
2357
2603
|
devModeFromCatalog,
|
|
2604
|
+
diagramAsText,
|
|
2605
|
+
diagramView,
|
|
2358
2606
|
disconnectAcsWs,
|
|
2359
2607
|
exchangeHandoff,
|
|
2360
2608
|
fetchConsumerConfig,
|
|
@@ -2396,8 +2644,10 @@ var borderRadius = {
|
|
|
2396
2644
|
parseInviteCode,
|
|
2397
2645
|
patchArtifact,
|
|
2398
2646
|
patchHomeAction,
|
|
2647
|
+
plainTextOf,
|
|
2399
2648
|
pluginCommandEmitter,
|
|
2400
2649
|
postCommandResult,
|
|
2650
|
+
prepareAttachments,
|
|
2401
2651
|
previewInvite,
|
|
2402
2652
|
readDevMode,
|
|
2403
2653
|
recentNotifDispatches,
|
|
@@ -2416,6 +2666,7 @@ var borderRadius = {
|
|
|
2416
2666
|
signInWithApple,
|
|
2417
2667
|
signInWithGoogle,
|
|
2418
2668
|
spacing,
|
|
2669
|
+
splitBlockSegments,
|
|
2419
2670
|
switchTenant,
|
|
2420
2671
|
tenantFromToken,
|
|
2421
2672
|
unlinkNotifChannel,
|