@ateam-ai-mobile/core 0.1.37 → 0.1.40

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.js CHANGED
@@ -32,6 +32,7 @@ __export(index_exports, {
32
32
  MAX_ATTACHMENT_BYTES: () => MAX_ATTACHMENT_BYTES,
33
33
  MAX_INLINE_ATTACHMENT_BYTES: () => MAX_INLINE_ATTACHMENT_BYTES,
34
34
  PluginCommandEmitter: () => PluginCommandEmitter,
35
+ SIDE_CHAT_LIMITS: () => SIDE_CHAT_LIMITS,
35
36
  TABLE_BLOCK_CLOSE: () => TABLE_BLOCK_CLOSE,
36
37
  TABLE_BLOCK_OPEN: () => TABLE_BLOCK_OPEN,
37
38
  TIMELINE_BLOCK_CLOSE: () => TIMELINE_BLOCK_CLOSE,
@@ -46,6 +47,7 @@ __export(index_exports, {
46
47
  chartAsText: () => chartAsText,
47
48
  chartScale: () => chartScale,
48
49
  chartView: () => chartView,
50
+ clearSideChats: () => clearSideChats,
49
51
  closeChatStream: () => closeChatStream,
50
52
  colors: () => colors,
51
53
  comparisonAsText: () => comparisonAsText,
@@ -62,6 +64,7 @@ __export(index_exports, {
62
64
  disconnectAcsWs: () => disconnectAcsWs,
63
65
  exchangeHandoff: () => exchangeHandoff,
64
66
  fetchConsumerConfig: () => fetchConsumerConfig,
67
+ fetchLauncherPlaces: () => fetchLauncherPlaces,
65
68
  focusPlugin: () => focusPlugin,
66
69
  fontSize: () => fontSize,
67
70
  getConfig: () => getConfig,
@@ -71,6 +74,7 @@ __export(index_exports, {
71
74
  getNotifPrefs: () => getPrefs,
72
75
  getNotifTelegramBotInfo: () => getTelegramBotInfo,
73
76
  getSession: () => getSession,
77
+ getSideChatStore: () => getSideChatStore,
74
78
  getTenant: () => getTenant,
75
79
  getToken: () => getToken,
76
80
  getUser: () => getUser,
@@ -90,6 +94,7 @@ __export(index_exports, {
90
94
  listSurface: () => listSurface,
91
95
  mcpFetch: () => mcpFetch,
92
96
  mcpToolCall: () => mcpToolCall,
97
+ mergeSideChatHistory: () => mergeSideChatHistory,
93
98
  nestByMaster: () => nestByMaster,
94
99
  notifyAcsWsForeground: () => notifyAcsWsForeground,
95
100
  notifyAppForeground: () => notifyAppForeground,
@@ -110,6 +115,7 @@ __export(index_exports, {
110
115
  readDevMode: () => readDevMode,
111
116
  recentNotifDispatches: () => recentDispatches,
112
117
  recordEvent: () => recordEvent,
118
+ recordWidgetOpen: () => recordWidgetOpen,
113
119
  refreshToken: () => refreshToken,
114
120
  registerHostIntent: () => registerHostIntent,
115
121
  registerPushDevice: () => registerDevice,
@@ -121,6 +127,7 @@ __export(index_exports, {
121
127
  setHomeActionOrder: () => setHomeActionOrder,
122
128
  setNotifPrefs: () => setPrefs,
123
129
  setOrder: () => setOrder,
130
+ sideChatOptions: () => sideChatOptions,
124
131
  signInWithApple: () => signInWithApple,
125
132
  signInWithGoogle: () => signInWithGoogle,
126
133
  spacing: () => spacing,
@@ -129,6 +136,7 @@ __export(index_exports, {
129
136
  tenantFromToken: () => tenantFromToken,
130
137
  timelineAsText: () => timelineAsText,
131
138
  timelineView: () => timelineView,
139
+ topicLabel: () => topicLabel,
132
140
  unlinkNotifChannel: () => unlinkChannel,
133
141
  unregisterPushDevice: () => unregisterDevice,
134
142
  unwrapMcpResult: () => unwrapMcpResult,
@@ -252,8 +260,8 @@ async function apiFetch(path, options = {}) {
252
260
  notifyAuthFailure();
253
261
  throw new Error("Session expired");
254
262
  }
255
- const text = await retryRes.text().catch(() => "");
256
- throw new Error(`API ${retryRes.status}: ${text}`);
263
+ const text2 = await retryRes.text().catch(() => "");
264
+ throw new Error(`API ${retryRes.status}: ${text2}`);
257
265
  }
258
266
  if (outcome.ok === "auth_failed") {
259
267
  console.warn(`[adas] refresh auth_failed on ${path} (${outcome.reason}) \u2014 auth failure`);
@@ -263,8 +271,8 @@ async function apiFetch(path, options = {}) {
263
271
  throw new Error(`API 401: refresh transient (${outcome.reason})`);
264
272
  }
265
273
  if (!res.ok) {
266
- const text = await res.text();
267
- throw new Error(`API ${res.status}: ${text}`);
274
+ const text2 = await res.text();
275
+ throw new Error(`API ${res.status}: ${text2}`);
268
276
  }
269
277
  return res.json();
270
278
  }
@@ -294,8 +302,8 @@ async function connectorCall(connectorId, tool, args = {}) {
294
302
  }
295
303
  );
296
304
  if (!res.ok) {
297
- const text = await res.text();
298
- return { ok: false, result: null, error: `HTTP ${res.status}: ${text}` };
305
+ const text2 = await res.text();
306
+ return { ok: false, result: null, error: `HTTP ${res.status}: ${text2}` };
299
307
  }
300
308
  const data = await res.json();
301
309
  if (data.ok !== void 0) return data;
@@ -311,8 +319,8 @@ async function mcpFetch(body) {
311
319
  body: typeof body === "string" ? body : JSON.stringify(body)
312
320
  });
313
321
  if (!res.ok) {
314
- const text = await res.text();
315
- throw new Error(`MCP fetch failed: HTTP ${res.status}: ${text}`);
322
+ const text2 = await res.text();
323
+ throw new Error(`MCP fetch failed: HTTP ${res.status}: ${text2}`);
316
324
  }
317
325
  return res.json();
318
326
  }
@@ -765,6 +773,26 @@ async function recordEvent(artifactId, event, surface) {
765
773
  } catch {
766
774
  }
767
775
  }
776
+ async function fetchLauncherPlaces() {
777
+ try {
778
+ const res = await authedFetch("/api/acs/launcher", { method: "GET" });
779
+ if (!res.ok) return null;
780
+ const data = await res.json();
781
+ if (!data?.ok) return null;
782
+ return {
783
+ mine: Array.isArray(data.mine) ? data.mine : [],
784
+ resting: Array.isArray(data.resting) ? data.resting : [],
785
+ hidden: Array.isArray(data.hidden) ? data.hidden : []
786
+ };
787
+ } catch (e) {
788
+ console.warn("[acs] /launcher failed:", e?.message || e);
789
+ return null;
790
+ }
791
+ }
792
+ function recordWidgetOpen(pluginId, surface) {
793
+ if (typeof pluginId !== "string" || !pluginId.startsWith("acs:")) return;
794
+ void recordEvent(pluginId.slice(4), "clicked", surface);
795
+ }
768
796
  async function listHomeActions() {
769
797
  try {
770
798
  const res = await authedFetch("/api/acs/home-actions", { method: "GET" });
@@ -1271,30 +1299,30 @@ async function postJson(path, body, jwt) {
1271
1299
  },
1272
1300
  body: JSON.stringify(body)
1273
1301
  });
1274
- const text = await res.text();
1302
+ const text2 = await res.text();
1275
1303
  let parsed = null;
1276
1304
  try {
1277
- parsed = JSON.parse(text);
1305
+ parsed = JSON.parse(text2);
1278
1306
  } catch {
1279
1307
  }
1280
1308
  if (!res.ok || parsed?.ok === false) {
1281
1309
  if (parsed?.error) throw new Error(parsed.error);
1282
- throw new Error(cleanErrorMessage(res.status, text, `consumer-auth ${path} failed`));
1310
+ throw new Error(cleanErrorMessage(res.status, text2, `consumer-auth ${path} failed`));
1283
1311
  }
1284
1312
  return parsed;
1285
1313
  }
1286
1314
  async function fetchConsumerConfig() {
1287
1315
  const url = `${getConsumerAuthApiUrl()}/platform/consumer/config?tenant=${encodeURIComponent(getTenant())}`;
1288
1316
  const res = await fetch(url);
1289
- const text = await res.text();
1317
+ const text2 = await res.text();
1290
1318
  let data = null;
1291
1319
  try {
1292
- data = JSON.parse(text);
1320
+ data = JSON.parse(text2);
1293
1321
  } catch {
1294
1322
  }
1295
1323
  if (!res.ok || !data?.ok) {
1296
1324
  if (data?.error) throw new Error(data.error);
1297
- throw new Error(cleanErrorMessage(res.status, text, "Failed to load sign-in config"));
1325
+ throw new Error(cleanErrorMessage(res.status, text2, "Failed to load sign-in config"));
1298
1326
  }
1299
1327
  return data;
1300
1328
  }
@@ -1316,16 +1344,16 @@ async function exchangeHandoff(code) {
1316
1344
  async function previewInvite(code) {
1317
1345
  const url = `${getConsumerAuthApiUrl()}/platform/consumer/invite/${encodeURIComponent(code)}`;
1318
1346
  const res = await fetch(url);
1319
- const text = await res.text();
1347
+ const text2 = await res.text();
1320
1348
  let data = null;
1321
1349
  try {
1322
- data = JSON.parse(text);
1350
+ data = JSON.parse(text2);
1323
1351
  } catch {
1324
1352
  }
1325
1353
  if (res.status === 404) throw new Error("This invite is invalid or has expired.");
1326
1354
  if (!res.ok || !data?.ok) {
1327
1355
  if (data?.error) throw new Error(data.error);
1328
- throw new Error(cleanErrorMessage(res.status, text, "Could not load invite"));
1356
+ throw new Error(cleanErrorMessage(res.status, text2, "Could not load invite"));
1329
1357
  }
1330
1358
  return data;
1331
1359
  }
@@ -1605,7 +1633,7 @@ var COMPARISON_BLOCK_CLOSE = "\uE109";
1605
1633
  var TIMELINE_BLOCK_OPEN = "\uE10A";
1606
1634
  var TIMELINE_BLOCK_CLOSE = "\uE10B";
1607
1635
  var SENTINEL_CHARS = /[\uE100-\uE10B]/g;
1608
- var clean = (text) => text.replace(SENTINEL_CHARS, "");
1636
+ var clean = (text2) => text2.replace(SENTINEL_CHARS, "");
1609
1637
  function renderTableShape(content) {
1610
1638
  if (!content || typeof content !== "object") return null;
1611
1639
  const cols = Array.isArray(content.columns) ? content.columns : null;
@@ -1626,14 +1654,14 @@ function diagramView(content) {
1626
1654
  kept[i + 1] = 0;
1627
1655
  if (!s || typeof s !== "object") return;
1628
1656
  const title = str(s.title);
1629
- const text = str(s.text);
1630
- if (!title && !text) return;
1657
+ const text2 = str(s.text);
1658
+ if (!title && !text2) return;
1631
1659
  const badges = [];
1632
1660
  for (const b of Array.isArray(s.badges) ? s.badges : []) {
1633
1661
  const bt = str(b && typeof b === "object" ? b.text : b);
1634
1662
  if (bt) badges.push({ text: bt, status: statusOf(b && b.status) });
1635
1663
  }
1636
- steps.push({ title: title || text, text: title ? text : "", status: statusOf(s.status), badges, decision: s.kind === "decision" || s.decision === true, next: null });
1664
+ steps.push({ title: title || text2, text: title ? text2 : "", status: statusOf(s.status), badges, decision: s.kind === "decision" || s.decision === true, next: null });
1637
1665
  rawNext.push(Array.isArray(s.next) ? s.next : null);
1638
1666
  kept[i + 1] = steps.length;
1639
1667
  });
@@ -1809,10 +1837,10 @@ function blocksToText(blocks) {
1809
1837
  if (!blocks || blocks.length === 0) return "";
1810
1838
  return blocks.map((b) => {
1811
1839
  if (!b || typeof b !== "object") return "";
1812
- const text = blockText(b);
1813
- if (!text) return "";
1814
- if (text.startsWith(TABLE_BLOCK_OPEN) || Object.values(VISUALS).some((v) => text.startsWith(v.open))) return text;
1815
- return b.meta?.display === "folded" ? `${DETAILS_BLOCK_OPEN}${encodeURIComponent(text)}${DETAILS_BLOCK_CLOSE}` : text;
1840
+ const text2 = blockText(b);
1841
+ if (!text2) return "";
1842
+ if (text2.startsWith(TABLE_BLOCK_OPEN) || Object.values(VISUALS).some((v) => text2.startsWith(v.open))) return text2;
1843
+ return b.meta?.display === "folded" ? `${DETAILS_BLOCK_OPEN}${encodeURIComponent(text2)}${DETAILS_BLOCK_CLOSE}` : text2;
1816
1844
  }).filter(Boolean).join("\n\n");
1817
1845
  }
1818
1846
  var PAIRS = [
@@ -2158,11 +2186,11 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
2158
2186
  // Send message via Core API
2159
2187
  // POST /api/chat { goal } → { jobId } → stream → fetch turn result
2160
2188
  // -----------------------------------------------------------------------
2161
- sendMessage: async (text, skillSlug, attachments) => {
2189
+ sendMessage: async (text2, skillSlug, attachments) => {
2162
2190
  const userMsg = {
2163
2191
  id: `user-${Date.now()}`,
2164
2192
  role: "user",
2165
- content: text,
2193
+ content: text2,
2166
2194
  timestamp: /* @__PURE__ */ new Date(),
2167
2195
  ...attachments?.length ? {
2168
2196
  attachments: attachments.map((a) => ({
@@ -2179,7 +2207,7 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
2179
2207
  try {
2180
2208
  const actor = getUser();
2181
2209
  const body = {
2182
- goal: text,
2210
+ goal: text2,
2183
2211
  // Opt in to the Chain Additions router (attach/cancel/new while a
2184
2212
  // chain runs). Backend ignores it where not applicable — safe to send.
2185
2213
  chainRouting: true,
@@ -2206,11 +2234,11 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
2206
2234
  if (!res.ok) {
2207
2235
  let errMsg = `Server error (${res.status})`;
2208
2236
  try {
2209
- const text2 = await res.text();
2210
- if (text2.startsWith("<") || text2.startsWith("<!")) {
2237
+ const text3 = await res.text();
2238
+ if (text3.startsWith("<") || text3.startsWith("<!")) {
2211
2239
  errMsg = res.status === 502 ? "Server is temporarily unavailable. Please try again." : `Server error (${res.status})`;
2212
2240
  } else {
2213
- const parsed = JSON.parse(text2);
2241
+ const parsed = JSON.parse(text3);
2214
2242
  errMsg = parsed.error || errMsg;
2215
2243
  }
2216
2244
  } catch {
@@ -2493,12 +2521,12 @@ async function fetchTurnResult(jobId, jobSnap) {
2493
2521
  const turn = items[0];
2494
2522
  if (turn?.assistant || turn?.turn?.assistant) {
2495
2523
  const assistant = turn.assistant || turn.turn?.assistant;
2496
- const text = blocksToText(assistant.blocks);
2524
+ const text2 = blocksToText(assistant.blocks);
2497
2525
  const actions = Array.isArray(assistant.actions) && assistant.actions.length ? assistant.actions : void 0;
2498
- if (text) {
2526
+ if (text2) {
2499
2527
  updateJobProgress(jobId, {
2500
2528
  status,
2501
- resultMessage: text,
2529
+ resultMessage: text2,
2502
2530
  ...actions ? { resultActions: actions } : {}
2503
2531
  });
2504
2532
  return;
@@ -2551,6 +2579,181 @@ async function pollJob(jobId, token) {
2551
2579
  }
2552
2580
  }
2553
2581
 
2582
+ // src/chat/sideChat.ts
2583
+ var import_zustand5 = require("zustand");
2584
+
2585
+ // src/chat/sideChatPure.ts
2586
+ var SIDE_CHAT_LIMITS = { title: 60, header: 40, welcome: 200, placeholder: 60 };
2587
+ var HEX = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
2588
+ var text = (v, max) => typeof v === "string" ? v.replace(/\s+/g, " ").trim().slice(0, max) : "";
2589
+ function sideChatOptions(payload) {
2590
+ const p = payload && typeof payload === "object" ? payload : {};
2591
+ return {
2592
+ title: text(p.title, SIDE_CHAT_LIMITS.title),
2593
+ header: text(p.header, SIDE_CHAT_LIMITS.header),
2594
+ welcome: text(p.welcome, SIDE_CHAT_LIMITS.welcome),
2595
+ placeholder: text(p.placeholder, SIDE_CHAT_LIMITS.placeholder),
2596
+ accent: typeof p.accent === "string" && HEX.test(p.accent.trim()) ? p.accent.trim() : null,
2597
+ side: p.side === "left" ? "left" : "right"
2598
+ };
2599
+ }
2600
+ var SHORT = /* @__PURE__ */ new Set(["ui", "ai", "mcp", "api", "crm", "sms", "pa"]);
2601
+ var nameOf = (slug) => slug.split(/[-_]+/).filter(Boolean).map((w) => SHORT.has(w.toLowerCase()) ? w.toUpperCase() : w[0].toUpperCase() + w.slice(1)).join(" ");
2602
+ function topicLabel(pageId, title) {
2603
+ if (title) return title;
2604
+ const last = String(pageId || "").split(":").pop() || "";
2605
+ return nameOf(last) || "Side chat";
2606
+ }
2607
+ function mergeSideChatHistory(saved, current) {
2608
+ const savedChains = new Set(saved.map((m) => m.chainId).filter(Boolean));
2609
+ const keep = current.filter((m) => m.local && !(m.chainId && savedChains.has(m.chainId)));
2610
+ return [...saved, ...keep];
2611
+ }
2612
+
2613
+ // src/chat/sideChat.ts
2614
+ var HISTORY_TURNS = 20;
2615
+ var stores = /* @__PURE__ */ new Map();
2616
+ function getSideChatStore(pageId) {
2617
+ const key = `${getTenant()}\0${pageId}`;
2618
+ let s = stores.get(key);
2619
+ if (!s) {
2620
+ s = createSideChatStore(pageId);
2621
+ stores.set(key, s);
2622
+ }
2623
+ return s;
2624
+ }
2625
+ function clearSideChats() {
2626
+ stores.clear();
2627
+ }
2628
+ function turnToMessages(turn) {
2629
+ const out = [];
2630
+ const chainId = typeof turn?.chainId === "string" ? turn.chainId : void 0;
2631
+ const base = turn?.jobId || turn?.chainId || `${turn?.startedAt || Date.now()}`;
2632
+ const userText = blocksToText(turn?.user?.blocks);
2633
+ const userAtts = blocksToAttachments(turn?.user?.blocks);
2634
+ if (userText || userAtts) {
2635
+ out.push({ id: `user-${base}`, role: "user", content: userText || "", timestamp: new Date(turn.startedAt || Date.now()), ...userAtts ? { attachments: userAtts } : {}, ...chainId ? { chainId } : {} });
2636
+ }
2637
+ const answer = blocksToText(turn?.assistant?.blocks);
2638
+ const actions = Array.isArray(turn?.assistant?.actions) && turn.assistant.actions.length ? turn.assistant.actions : void 0;
2639
+ if (answer || actions) {
2640
+ out.push({ id: `bot-${base}`, role: "assistant", content: answer || "", timestamp: new Date(turn.finishedAt || turn.startedAt || Date.now()), skillSlug: turn.skillSlug, ...actions ? { actions } : {}, ...chainId ? { chainId } : {} });
2641
+ } else if (turn?.status === "failed") {
2642
+ out.push({ id: `err-${base}`, role: "system", content: turn.failReason || "This turn failed.", timestamp: new Date(turn.finishedAt || turn.startedAt || Date.now()), ...chainId ? { chainId } : {} });
2643
+ }
2644
+ return out;
2645
+ }
2646
+ function createSideChatStore(pageId) {
2647
+ return (0, import_zustand5.create)((set, get) => {
2648
+ const local = (m) => ({ ...m, local: true });
2649
+ const patchJob = (jobId, p) => set((s) => ({ messages: s.messages.map((m) => m.jobProgress?.jobId === jobId ? { ...m, jobProgress: { ...m.jobProgress, ...p } } : m) }));
2650
+ async function follow(jobId, chainId) {
2651
+ let ended = null;
2652
+ for (let i = 0; !ended; i++) {
2653
+ if (i > 0) await new Promise((r) => setTimeout(r, i < 120 ? 1500 : 5e3));
2654
+ if (!get().messages.some((m) => m.jobProgress?.jobId === jobId)) return;
2655
+ try {
2656
+ const res = await fetch(`${getCoreApiUrl()}/api/job/${encodeURIComponent(jobId)}/status`, { headers: coreHeaders() });
2657
+ if (!res.ok) {
2658
+ if (res.status === 404) break;
2659
+ continue;
2660
+ }
2661
+ const snap = await res.json();
2662
+ const handoff = snap?.isHandoff || snap?.state?.handoffTransfer;
2663
+ if (isTerminalSnapshot(snap) && !(normalizeJobStatus(snap) === "done" && handoff)) ended = snap;
2664
+ else patchJob(jobId, snapshotToProgress(snap, jobId));
2665
+ } catch {
2666
+ }
2667
+ }
2668
+ for (let t = 0; t < 5; t++) {
2669
+ await get().load();
2670
+ if (!get().messages.some((m) => m.jobProgress?.jobId === jobId)) {
2671
+ set({ loading: false });
2672
+ return;
2673
+ }
2674
+ await new Promise((r) => setTimeout(r, 800));
2675
+ }
2676
+ const failed = ended ? normalizeJobStatus(ended) === "error" : false;
2677
+ const fallback = ended?.result?.message || ended?.state?.finalReply || (failed ? "Something went wrong. Please try again." : "Done.");
2678
+ set((s) => ({
2679
+ loading: false,
2680
+ messages: s.messages.map((m) => m.jobProgress?.jobId === jobId ? { ...m, id: `done-${jobId}`, content: fallback, jobProgress: { ...m.jobProgress, status: failed ? "error" : "done" }, chainId } : m)
2681
+ }));
2682
+ }
2683
+ return {
2684
+ pageId,
2685
+ messages: [],
2686
+ loading: false,
2687
+ loaded: false,
2688
+ load: async () => {
2689
+ try {
2690
+ const res = await fetch(`${getCoreApiUrl()}/api/conversation?topic=${encodeURIComponent(pageId)}&page_size=${HISTORY_TURNS}`, { headers: coreHeaders() });
2691
+ if (!res.ok) {
2692
+ set({ loaded: true });
2693
+ return;
2694
+ }
2695
+ const json = await res.json();
2696
+ const items = Array.isArray(json?.items) ? [...json.items].reverse() : [];
2697
+ const seen = /* @__PURE__ */ new Set();
2698
+ const saved = items.filter((t) => {
2699
+ const k = t?.jobId;
2700
+ if (!k) return true;
2701
+ if (seen.has(k)) return false;
2702
+ seen.add(k);
2703
+ return true;
2704
+ }).flatMap(turnToMessages);
2705
+ set((s) => ({ messages: mergeSideChatHistory(saved, s.messages), loaded: true }));
2706
+ } catch {
2707
+ set({ loaded: true });
2708
+ }
2709
+ },
2710
+ send: async (text2) => {
2711
+ const t = text2.trim();
2712
+ if (!t || get().loading) return false;
2713
+ const echo = local({ id: `user-${Date.now()}`, role: "user", content: t, timestamp: /* @__PURE__ */ new Date() });
2714
+ set((s) => ({ messages: [...s.messages, echo], loading: true }));
2715
+ const fail = (msg) => set((s) => ({ loading: false, messages: [...s.messages, local({ id: `error-${Date.now()}`, role: "system", content: msg, timestamp: /* @__PURE__ */ new Date() })] }));
2716
+ try {
2717
+ const actor = getUser();
2718
+ const res = await fetch(`${getCoreApiUrl()}/api/chat`, {
2719
+ method: "POST",
2720
+ headers: coreHeaders(),
2721
+ body: JSON.stringify({
2722
+ goal: t,
2723
+ triggerContext: {
2724
+ channel: "mobile",
2725
+ replyContext: { chatId: actor?.actorId || "unknown" },
2726
+ pageContext: { page: pageId, chat: "page" }
2727
+ }
2728
+ })
2729
+ });
2730
+ const json = await res.json().catch(() => null);
2731
+ const jobId = json?.jobId || json?.id;
2732
+ if (!res.ok || !jobId) {
2733
+ fail(json?.error || `Could not start (${res.status}).`);
2734
+ return false;
2735
+ }
2736
+ const chainId = json.job?.chainId || jobId;
2737
+ const bubble = local({
2738
+ id: `job-${jobId}`,
2739
+ role: "assistant",
2740
+ content: "Working on it...",
2741
+ timestamp: /* @__PURE__ */ new Date(),
2742
+ chainId,
2743
+ jobProgress: { jobId, actorId: actor?.actorId, status: "running", subStatus: "Starting...", chainStartedAt: Date.now() }
2744
+ });
2745
+ set((s) => ({ messages: [...s.messages.map((m) => m.id === echo.id ? { ...m, chainId } : m), bubble] }));
2746
+ void follow(jobId, chainId);
2747
+ return true;
2748
+ } catch (e) {
2749
+ fail(`Request failed: ${e?.message || e}`);
2750
+ return false;
2751
+ }
2752
+ }
2753
+ };
2754
+ });
2755
+ }
2756
+
2554
2757
  // src/api/tenants.ts
2555
2758
  function nestByMaster(tenants) {
2556
2759
  const ids = new Set(tenants.map((t) => t.id));
@@ -2618,6 +2821,7 @@ async function switchTenant(targetTenantId) {
2618
2821
  await onSession(session);
2619
2822
  closeChatStream();
2620
2823
  useChatStore.getState().clearChat();
2824
+ clearSideChats();
2621
2825
  return session;
2622
2826
  }
2623
2827
 
@@ -2734,6 +2938,7 @@ var borderRadius = {
2734
2938
  MAX_ATTACHMENT_BYTES,
2735
2939
  MAX_INLINE_ATTACHMENT_BYTES,
2736
2940
  PluginCommandEmitter,
2941
+ SIDE_CHAT_LIMITS,
2737
2942
  TABLE_BLOCK_CLOSE,
2738
2943
  TABLE_BLOCK_OPEN,
2739
2944
  TIMELINE_BLOCK_CLOSE,
@@ -2748,6 +2953,7 @@ var borderRadius = {
2748
2953
  chartAsText,
2749
2954
  chartScale,
2750
2955
  chartView,
2956
+ clearSideChats,
2751
2957
  closeChatStream,
2752
2958
  colors,
2753
2959
  comparisonAsText,
@@ -2764,6 +2970,7 @@ var borderRadius = {
2764
2970
  disconnectAcsWs,
2765
2971
  exchangeHandoff,
2766
2972
  fetchConsumerConfig,
2973
+ fetchLauncherPlaces,
2767
2974
  focusPlugin,
2768
2975
  fontSize,
2769
2976
  getConfig,
@@ -2773,6 +2980,7 @@ var borderRadius = {
2773
2980
  getNotifPrefs,
2774
2981
  getNotifTelegramBotInfo,
2775
2982
  getSession,
2983
+ getSideChatStore,
2776
2984
  getTenant,
2777
2985
  getToken,
2778
2986
  getUser,
@@ -2792,6 +3000,7 @@ var borderRadius = {
2792
3000
  listSurface,
2793
3001
  mcpFetch,
2794
3002
  mcpToolCall,
3003
+ mergeSideChatHistory,
2795
3004
  nestByMaster,
2796
3005
  notifyAcsWsForeground,
2797
3006
  notifyAppForeground,
@@ -2812,6 +3021,7 @@ var borderRadius = {
2812
3021
  readDevMode,
2813
3022
  recentNotifDispatches,
2814
3023
  recordEvent,
3024
+ recordWidgetOpen,
2815
3025
  refreshToken,
2816
3026
  registerHostIntent,
2817
3027
  registerPushDevice,
@@ -2823,6 +3033,7 @@ var borderRadius = {
2823
3033
  setHomeActionOrder,
2824
3034
  setNotifPrefs,
2825
3035
  setOrder,
3036
+ sideChatOptions,
2826
3037
  signInWithApple,
2827
3038
  signInWithGoogle,
2828
3039
  spacing,
@@ -2831,6 +3042,7 @@ var borderRadius = {
2831
3042
  tenantFromToken,
2832
3043
  timelineAsText,
2833
3044
  timelineView,
3045
+ topicLabel,
2834
3046
  unlinkNotifChannel,
2835
3047
  unregisterPushDevice,
2836
3048
  unwrapMcpResult,