@ateam-ai-mobile/core 0.1.0 → 0.1.1

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
@@ -30,7 +30,10 @@ __export(index_exports, {
30
30
  borderRadius: () => borderRadius,
31
31
  closeChatStream: () => closeChatStream,
32
32
  colors: () => colors,
33
+ connectAcsWs: () => connectAcsWs,
33
34
  connectorCall: () => connectorCall,
35
+ deleteArtifact: () => deleteArtifact,
36
+ disconnectAcsWs: () => disconnectAcsWs,
34
37
  fontSize: () => fontSize,
35
38
  getConfig: () => getConfig,
36
39
  getCoreApiUrl: () => getCoreApiUrl,
@@ -41,13 +44,27 @@ __export(index_exports, {
41
44
  getVoiceApiUrl: () => getVoiceApiUrl,
42
45
  initAdas: () => initAdas,
43
46
  isAdasInitialized: () => isAdasInitialized,
47
+ listHomeActions: () => listHomeActions,
48
+ listMadeForYou: () => listMadeForYou,
49
+ listMyTenants: () => listMyTenants,
50
+ listSurface: () => listSurface,
44
51
  mcpFetch: () => mcpFetch,
45
52
  mcpToolCall: () => mcpToolCall,
53
+ notifyAcsWsForeground: () => notifyAcsWsForeground,
54
+ patchArtifact: () => patchArtifact,
55
+ patchHomeAction: () => patchHomeAction,
46
56
  pluginCommandEmitter: () => pluginCommandEmitter,
47
57
  postCommandResult: () => postCommandResult,
58
+ recordEvent: () => recordEvent,
59
+ setAcsCacheStorage: () => setAcsCacheStorage,
60
+ setAcsReachabilityReporter: () => setAcsReachabilityReporter,
61
+ setHomeActionOrder: () => setHomeActionOrder,
62
+ setOrder: () => setOrder,
48
63
  spacing: () => spacing,
49
64
  unwrapMcpResult: () => unwrapMcpResult,
50
- useChatStore: () => useChatStore
65
+ useChatStore: () => useChatStore,
66
+ useHomeActionsStore: () => useHomeActionsStore,
67
+ useWidgetsStore: () => useWidgetsStore
51
68
  });
52
69
  module.exports = __toCommonJS(index_exports);
53
70
 
@@ -65,8 +82,11 @@ function getConfig() {
65
82
  }
66
83
  return _config;
67
84
  }
85
+ function resolveUrl(src) {
86
+ return (typeof src === "function" ? src() : src).replace(/\/$/, "");
87
+ }
68
88
  function getCoreApiUrl() {
69
- return getConfig().coreUrl.replace(/\/$/, "");
89
+ return resolveUrl(getConfig().coreUrl);
70
90
  }
71
91
  function getCoreWsUrl() {
72
92
  return getCoreApiUrl().replace(/^http/, "ws");
@@ -74,10 +94,11 @@ function getCoreWsUrl() {
74
94
  function getVoiceApiUrl() {
75
95
  const url = getConfig().voiceUrl;
76
96
  if (!url) throw new Error("[adas] voiceUrl not configured");
77
- return url.replace(/\/$/, "");
97
+ return resolveUrl(url);
78
98
  }
79
99
  function getTenant() {
80
- return getConfig().tenant || "";
100
+ const t = getConfig().tenant;
101
+ return (typeof t === "function" ? t() : t) || "";
81
102
  }
82
103
  function getUser() {
83
104
  return getConfig().getUser?.() || null;
@@ -214,6 +235,12 @@ function unwrapMcpResult(result) {
214
235
  }
215
236
  }
216
237
 
238
+ // src/api/tenants.ts
239
+ async function listMyTenants() {
240
+ const data = await apiFetch("/api/tenants/list");
241
+ return data.ok && Array.isArray(data.tenants) ? data.tenants : [];
242
+ }
243
+
217
244
  // src/chat/store.ts
218
245
  var import_zustand = require("zustand");
219
246
 
@@ -1047,6 +1074,580 @@ var borderRadius = {
1047
1074
  xl: 20,
1048
1075
  full: 9999
1049
1076
  };
1077
+
1078
+ // src/acs/providers.ts
1079
+ var _reachability = null;
1080
+ function setAcsReachabilityReporter(r) {
1081
+ _reachability = r;
1082
+ }
1083
+ function reportAcsServerUp() {
1084
+ try {
1085
+ _reachability?.up();
1086
+ } catch {
1087
+ }
1088
+ }
1089
+ function reportAcsServerDown() {
1090
+ try {
1091
+ _reachability?.down();
1092
+ } catch {
1093
+ }
1094
+ }
1095
+ var _kv = null;
1096
+ function setAcsCacheStorage(kv) {
1097
+ _kv = kv;
1098
+ }
1099
+ function getAcsCacheStorage() {
1100
+ return _kv;
1101
+ }
1102
+
1103
+ // src/acs/api.ts
1104
+ async function authedFetch(path, init) {
1105
+ const token = getToken();
1106
+ try {
1107
+ const res = await fetch(`${getCoreApiUrl()}${path}`, {
1108
+ ...init,
1109
+ headers: {
1110
+ "Content-Type": "application/json",
1111
+ ...token ? { Authorization: `Bearer ${token}` } : {},
1112
+ ...init?.headers || {}
1113
+ }
1114
+ });
1115
+ reportAcsServerUp();
1116
+ return res;
1117
+ } catch (e) {
1118
+ reportAcsServerDown();
1119
+ throw e;
1120
+ }
1121
+ }
1122
+ async function listSurface(surface, context) {
1123
+ try {
1124
+ const res = await authedFetch("/api/acs/surface", {
1125
+ method: "POST",
1126
+ body: JSON.stringify({ surface, ...context ? { context } : {} })
1127
+ });
1128
+ if (!res.ok) {
1129
+ console.warn(`[acs] /surface ${surface} returned ${res.status}`);
1130
+ return [];
1131
+ }
1132
+ const data = await res.json();
1133
+ return Array.isArray(data?.items) ? data.items : [];
1134
+ } catch (e) {
1135
+ console.warn("[acs] /surface failed:", e?.message || e);
1136
+ return [];
1137
+ }
1138
+ }
1139
+ async function listMadeForYou() {
1140
+ try {
1141
+ const res = await authedFetch("/api/acs/made-for-you", { method: "GET" });
1142
+ if (!res.ok) {
1143
+ console.warn(`[acs] /made-for-you returned ${res.status}`);
1144
+ return [];
1145
+ }
1146
+ const data = await res.json();
1147
+ return Array.isArray(data?.artifacts) ? data.artifacts : [];
1148
+ } catch (e) {
1149
+ console.warn("[acs] /made-for-you failed:", e?.message || e);
1150
+ return [];
1151
+ }
1152
+ }
1153
+ async function deleteArtifact(artifactId, reason = "user_long_press_delete") {
1154
+ try {
1155
+ const res = await authedFetch(
1156
+ `/api/acs/artifacts/${encodeURIComponent(artifactId)}`,
1157
+ { method: "DELETE", body: JSON.stringify({ reason }) }
1158
+ );
1159
+ const data = await res.json().catch(() => ({}));
1160
+ if (res.ok) {
1161
+ return { ok: true, already: !!data?.already, status: res.status };
1162
+ }
1163
+ if (res.status === 404) {
1164
+ return { ok: true, notFound: true, status: 404 };
1165
+ }
1166
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1167
+ } catch (e) {
1168
+ return { ok: false, status: 0, error: e?.message || "network error" };
1169
+ }
1170
+ }
1171
+ async function patchArtifact(artifactId, body, reason) {
1172
+ try {
1173
+ const res = await authedFetch(
1174
+ `/api/acs/artifacts/${encodeURIComponent(artifactId)}`,
1175
+ { method: "PATCH", body: JSON.stringify({ ...body, reason }) }
1176
+ );
1177
+ const data = await res.json().catch(() => ({}));
1178
+ if (res.ok) {
1179
+ return {
1180
+ ok: true,
1181
+ already: !!data?.already,
1182
+ artifact: data?.artifact || void 0,
1183
+ status: res.status
1184
+ };
1185
+ }
1186
+ if (res.status === 404) {
1187
+ return { ok: true, notFound: true, status: 404 };
1188
+ }
1189
+ return {
1190
+ ok: false,
1191
+ status: res.status,
1192
+ error: data?.error || `HTTP ${res.status}`
1193
+ };
1194
+ } catch (e) {
1195
+ return { ok: false, status: 0, error: e?.message || "network error" };
1196
+ }
1197
+ }
1198
+ async function setOrder(pinned) {
1199
+ try {
1200
+ const res = await authedFetch("/api/acs/order", {
1201
+ method: "PUT",
1202
+ body: JSON.stringify({ pinned })
1203
+ });
1204
+ if (res.ok) return { ok: true, status: res.status };
1205
+ const data = await res.json().catch(() => ({}));
1206
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1207
+ } catch (e) {
1208
+ return { ok: false, status: 0, error: e?.message || "network error" };
1209
+ }
1210
+ }
1211
+ async function recordEvent(artifactId, event, surface) {
1212
+ try {
1213
+ await authedFetch("/api/acs/event", {
1214
+ method: "POST",
1215
+ body: JSON.stringify({ artifactId, event, ...surface ? { surface } : {} })
1216
+ });
1217
+ } catch {
1218
+ }
1219
+ }
1220
+ async function listHomeActions() {
1221
+ try {
1222
+ const res = await authedFetch("/api/acs/home-actions", { method: "GET" });
1223
+ if (!res.ok) {
1224
+ console.warn(`[acs] /home-actions returned ${res.status}`);
1225
+ return [];
1226
+ }
1227
+ const data = await res.json();
1228
+ return Array.isArray(data?.actions) ? data.actions : [];
1229
+ } catch (e) {
1230
+ console.warn("[acs] /home-actions failed:", e?.message || e);
1231
+ return [];
1232
+ }
1233
+ }
1234
+ async function patchHomeAction(actionId, body, reason) {
1235
+ try {
1236
+ const res = await authedFetch(
1237
+ `/api/acs/home-actions/${encodeURIComponent(actionId)}`,
1238
+ { method: "PATCH", body: JSON.stringify({ ...body, reason }) }
1239
+ );
1240
+ const data = await res.json().catch(() => ({}));
1241
+ if (res.ok) return { ok: true, action: data?.action || void 0, status: res.status };
1242
+ if (res.status === 404) return { ok: true, status: 404 };
1243
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1244
+ } catch (e) {
1245
+ return { ok: false, status: 0, error: e?.message || "network error" };
1246
+ }
1247
+ }
1248
+ async function setHomeActionOrder(order) {
1249
+ try {
1250
+ const res = await authedFetch("/api/acs/home-actions/order", {
1251
+ method: "PUT",
1252
+ body: JSON.stringify({ order })
1253
+ });
1254
+ if (res.ok) return { ok: true, status: res.status };
1255
+ const data = await res.json().catch(() => ({}));
1256
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1257
+ } catch (e) {
1258
+ return { ok: false, status: 0, error: e?.message || "network error" };
1259
+ }
1260
+ }
1261
+
1262
+ // src/acs/widgetsStore.ts
1263
+ var import_zustand2 = require("zustand");
1264
+ var useWidgetsStore = (0, import_zustand2.create)((set, get) => ({
1265
+ tiles: [],
1266
+ hydrated: false,
1267
+ loading: false,
1268
+ error: null,
1269
+ hydrate: async () => {
1270
+ if (get().hydrated || get().loading) return;
1271
+ await get().refresh();
1272
+ },
1273
+ refresh: async () => {
1274
+ if (get().loading) return;
1275
+ set({ loading: true, error: null });
1276
+ try {
1277
+ const tiles = await listSurface("home");
1278
+ set({ tiles, loading: false, hydrated: true });
1279
+ } catch (e) {
1280
+ set({ loading: false, hydrated: true, error: e?.message || "Failed to load widgets" });
1281
+ }
1282
+ },
1283
+ clear: () => set({ tiles: [], hydrated: false, loading: false, error: null }),
1284
+ remove: async (artifactId, reason = "user_long_press_delete") => {
1285
+ const before = get().tiles;
1286
+ set({ tiles: before.filter((t) => t.id !== artifactId) });
1287
+ const result = await deleteArtifact(artifactId, reason);
1288
+ if (result.ok) {
1289
+ return { ok: true };
1290
+ }
1291
+ set({ tiles: before });
1292
+ return { ok: false, error: result.error || `HTTP ${result.status}` };
1293
+ },
1294
+ hide: async (artifactId) => {
1295
+ const before = get().tiles;
1296
+ set({
1297
+ tiles: before.map(
1298
+ (t) => t.id === artifactId ? { ...t, visibility: "hidden" } : t
1299
+ )
1300
+ });
1301
+ const r = await patchArtifact(artifactId, { visibility: "hidden" }, "user_long_press_hide");
1302
+ if (r.ok) {
1303
+ if (r.artifact) {
1304
+ set({
1305
+ tiles: get().tiles.map((t) => t.id === artifactId ? { ...t, ...r.artifact } : t)
1306
+ });
1307
+ }
1308
+ return { ok: true };
1309
+ }
1310
+ set({ tiles: before });
1311
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1312
+ },
1313
+ unhide: async (artifactId) => {
1314
+ const before = get().tiles;
1315
+ set({
1316
+ tiles: before.map(
1317
+ (t) => t.id === artifactId ? { ...t, visibility: "pinned" } : t
1318
+ )
1319
+ });
1320
+ const r = await patchArtifact(artifactId, { visibility: "pinned" }, "user_long_press_unhide");
1321
+ if (r.ok) {
1322
+ if (r.artifact) {
1323
+ set({
1324
+ tiles: get().tiles.map((t) => t.id === artifactId ? { ...t, ...r.artifact } : t)
1325
+ });
1326
+ }
1327
+ return { ok: true };
1328
+ }
1329
+ set({ tiles: before });
1330
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1331
+ },
1332
+ rename: async (artifactId, name) => {
1333
+ const trimmed = name.trim();
1334
+ if (!trimmed) return { ok: false, error: "Name cannot be empty" };
1335
+ if (trimmed.length > 60) return { ok: false, error: "Name must be 60 characters or less" };
1336
+ const before = get().tiles;
1337
+ set({
1338
+ tiles: before.map((t) => t.id === artifactId ? { ...t, name: trimmed } : t)
1339
+ });
1340
+ const r = await patchArtifact(artifactId, { name: trimmed }, "user_long_press_rename");
1341
+ if (r.ok) {
1342
+ if (r.artifact) {
1343
+ set({
1344
+ tiles: get().tiles.map((t) => t.id === artifactId ? { ...t, ...r.artifact } : t)
1345
+ });
1346
+ }
1347
+ return { ok: true };
1348
+ }
1349
+ set({ tiles: before });
1350
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1351
+ },
1352
+ reorder: async (pinnedIds) => {
1353
+ const before = get().tiles;
1354
+ const idToOrder = new Map(pinnedIds.map((id, i) => [id, i]));
1355
+ set({
1356
+ tiles: before.map((t) => {
1357
+ const o = idToOrder.get(t.id);
1358
+ return o == null ? t : { ...t, pinOrder: o };
1359
+ })
1360
+ });
1361
+ const r = await setOrder(pinnedIds);
1362
+ if (r.ok) return { ok: true };
1363
+ set({ tiles: before });
1364
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1365
+ },
1366
+ applyServerUpdate: (artifact) => {
1367
+ set({
1368
+ tiles: get().tiles.map((t) => t.id === artifact.id ? { ...t, ...artifact } : t)
1369
+ });
1370
+ },
1371
+ applyServerRetire: (artifactId) => {
1372
+ set({ tiles: get().tiles.filter((t) => t.id !== artifactId) });
1373
+ },
1374
+ applyServerOrder: (pinnedIds) => {
1375
+ const idToOrder = new Map(pinnedIds.map((id, i) => [id, i]));
1376
+ set({
1377
+ tiles: get().tiles.map((t) => {
1378
+ const o = idToOrder.get(t.id);
1379
+ return o == null ? t : { ...t, pinOrder: o };
1380
+ })
1381
+ });
1382
+ },
1383
+ track: (artifactId, event) => {
1384
+ recordEvent(artifactId, event, "home");
1385
+ }
1386
+ }));
1387
+
1388
+ // src/acs/homeActionsStore.ts
1389
+ var import_zustand3 = require("zustand");
1390
+ var CACHE_KEY = "ateam.homeActions.v1";
1391
+ function persist(actions) {
1392
+ getAcsCacheStorage()?.setItem(CACHE_KEY, JSON.stringify(actions)).catch(() => {
1393
+ });
1394
+ }
1395
+ function sortByPin(a, b) {
1396
+ if (!!a.pinned !== !!b.pinned) return a.pinned ? -1 : 1;
1397
+ const ao = typeof a.pinOrder === "number" ? a.pinOrder : Number.MAX_SAFE_INTEGER;
1398
+ const bo = typeof b.pinOrder === "number" ? b.pinOrder : Number.MAX_SAFE_INTEGER;
1399
+ return ao - bo;
1400
+ }
1401
+ var useHomeActionsStore = (0, import_zustand3.create)((set, get) => ({
1402
+ actions: [],
1403
+ hydrated: false,
1404
+ loading: false,
1405
+ hydrate: async () => {
1406
+ if (get().hydrated || get().loading) return;
1407
+ try {
1408
+ const cached = await getAcsCacheStorage()?.getItem(CACHE_KEY);
1409
+ if (cached) {
1410
+ const parsed = JSON.parse(cached);
1411
+ if (Array.isArray(parsed) && parsed.length > 0) {
1412
+ set({ actions: parsed, hydrated: true });
1413
+ }
1414
+ }
1415
+ } catch {
1416
+ }
1417
+ await get().refresh();
1418
+ },
1419
+ refresh: async () => {
1420
+ if (get().loading) return;
1421
+ set({ loading: true });
1422
+ const actions = await listHomeActions();
1423
+ if (actions.length > 0) {
1424
+ set({ actions, loading: false, hydrated: true });
1425
+ persist(actions);
1426
+ } else {
1427
+ set({ loading: false, hydrated: true });
1428
+ }
1429
+ },
1430
+ // clear() wipes in-memory state on sign-out AND drops the disk cache — a
1431
+ // different user must not see the prior user's cards.
1432
+ clear: () => {
1433
+ set({ actions: [], hydrated: false, loading: false });
1434
+ getAcsCacheStorage()?.setItem(CACHE_KEY, "[]").catch(() => {
1435
+ });
1436
+ },
1437
+ dismiss: async (actionId) => {
1438
+ const before = get().actions;
1439
+ const next = before.filter((a) => a.actionId !== actionId);
1440
+ set({ actions: next });
1441
+ persist(next);
1442
+ const r = await patchHomeAction(actionId, { dismissed: true }, "user_dismiss");
1443
+ if (r.ok) return { ok: true };
1444
+ set({ actions: before });
1445
+ persist(before);
1446
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1447
+ },
1448
+ setPinned: async (actionId, pinned) => {
1449
+ const before = get().actions;
1450
+ const next = before.map((a) => a.actionId === actionId ? { ...a, pinned } : a).sort(sortByPin);
1451
+ set({ actions: next });
1452
+ persist(next);
1453
+ const r = await patchHomeAction(actionId, { pinned }, pinned ? "user_pin" : "user_unpin");
1454
+ if (r.ok) {
1455
+ if (r.action) {
1456
+ const merged = get().actions.map((a) => a.actionId === actionId ? { ...a, ...r.action } : a).sort(sortByPin);
1457
+ set({ actions: merged });
1458
+ persist(merged);
1459
+ }
1460
+ return { ok: true };
1461
+ }
1462
+ set({ actions: before });
1463
+ persist(before);
1464
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1465
+ },
1466
+ reorder: async (orderedIds) => {
1467
+ const before = get().actions;
1468
+ const idx = new Map(orderedIds.map((id, i) => [id, i]));
1469
+ const next = before.map((a) => {
1470
+ const o = idx.get(a.actionId);
1471
+ return o == null ? a : { ...a, pinOrder: o };
1472
+ }).sort(sortByPin);
1473
+ set({ actions: next });
1474
+ persist(next);
1475
+ const r = await setHomeActionOrder(orderedIds);
1476
+ if (r.ok) return { ok: true };
1477
+ set({ actions: before });
1478
+ persist(before);
1479
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1480
+ },
1481
+ applyServerUpsert: (action) => {
1482
+ const rest = get().actions.filter((a) => a.actionId !== action.actionId);
1483
+ const next = [...rest, action].sort(sortByPin);
1484
+ set({ actions: next });
1485
+ persist(next);
1486
+ },
1487
+ applyServerRemove: (actionId) => {
1488
+ const next = get().actions.filter((a) => a.actionId !== actionId);
1489
+ set({ actions: next });
1490
+ persist(next);
1491
+ },
1492
+ applyServerOrder: (orderedIds) => {
1493
+ const idx = new Map(orderedIds.map((id, i) => [id, i]));
1494
+ const next = get().actions.map((a) => {
1495
+ const o = idx.get(a.actionId);
1496
+ return o == null ? a : { ...a, pinOrder: o };
1497
+ }).sort(sortByPin);
1498
+ set({ actions: next });
1499
+ persist(next);
1500
+ }
1501
+ }));
1502
+
1503
+ // src/acs/ws.ts
1504
+ var _ws2 = null;
1505
+ var _wantOpen = false;
1506
+ var _retryAttempt = 0;
1507
+ var _retryTimer = null;
1508
+ var _token = null;
1509
+ var _tenant = null;
1510
+ var TOPIC = "acs.artifacts";
1511
+ var TOPIC_HOME = "acs.home-actions";
1512
+ var MAX_BACKOFF_MS = 3e4;
1513
+ function backoffMs(attempt) {
1514
+ const base = Math.min(MAX_BACKOFF_MS, 500 * Math.pow(2, attempt));
1515
+ const jitter = Math.random() * 250;
1516
+ return base + jitter;
1517
+ }
1518
+ function send(obj) {
1519
+ if (_ws2 && _ws2.readyState === 1) {
1520
+ try {
1521
+ _ws2.send(JSON.stringify(obj));
1522
+ } catch (e) {
1523
+ console.warn("[acsWs] send failed", e);
1524
+ }
1525
+ }
1526
+ }
1527
+ function handleEvent(msg) {
1528
+ if (msg?.event === "subscribed") {
1529
+ console.log("[acsWs] subscribed to", msg?.data?.topic);
1530
+ return;
1531
+ }
1532
+ if (msg?.topic === TOPIC_HOME) {
1533
+ const home = useHomeActionsStore.getState();
1534
+ switch (msg.event) {
1535
+ case "updated":
1536
+ if (msg.action && typeof msg.action.actionId === "string") home.applyServerUpsert(msg.action);
1537
+ break;
1538
+ case "removed":
1539
+ if (typeof msg.actionId === "string") home.applyServerRemove(msg.actionId);
1540
+ break;
1541
+ case "order":
1542
+ if (Array.isArray(msg.order)) home.applyServerOrder(msg.order.filter((id) => typeof id === "string"));
1543
+ break;
1544
+ case "refreshed":
1545
+ home.refresh();
1546
+ break;
1547
+ default:
1548
+ break;
1549
+ }
1550
+ return;
1551
+ }
1552
+ if (msg?.topic !== TOPIC) return;
1553
+ const store = useWidgetsStore.getState();
1554
+ switch (msg.event) {
1555
+ case "updated":
1556
+ if (msg.artifact && typeof msg.artifact.id === "string") {
1557
+ store.applyServerUpdate(msg.artifact);
1558
+ }
1559
+ break;
1560
+ case "retired":
1561
+ if (typeof msg.artifactId === "string") {
1562
+ store.applyServerRetire(msg.artifactId);
1563
+ }
1564
+ break;
1565
+ case "order":
1566
+ if (Array.isArray(msg.pinned)) {
1567
+ store.applyServerOrder(msg.pinned.filter((id) => typeof id === "string"));
1568
+ }
1569
+ break;
1570
+ case "created":
1571
+ if (msg.artifact && typeof msg.artifact.id === "string") {
1572
+ store.applyServerUpdate(msg.artifact);
1573
+ }
1574
+ break;
1575
+ default:
1576
+ break;
1577
+ }
1578
+ }
1579
+ function openSocket() {
1580
+ if (_ws2) return;
1581
+ if (!_token || !_tenant) return;
1582
+ const url = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(_token)}&tenant=${encodeURIComponent(_tenant)}`;
1583
+ console.log(`[acsWs] opening`);
1584
+ const ws = new WebSocket(url);
1585
+ _ws2 = ws;
1586
+ ws.onopen = () => {
1587
+ _retryAttempt = 0;
1588
+ send({ type: "subscribe", topic: TOPIC });
1589
+ send({ type: "subscribe", topic: TOPIC_HOME });
1590
+ };
1591
+ ws.onmessage = (e) => {
1592
+ try {
1593
+ const msg = JSON.parse(typeof e.data === "string" ? e.data : "");
1594
+ handleEvent(msg);
1595
+ } catch (err) {
1596
+ console.warn("[acsWs] parse failed", err);
1597
+ }
1598
+ };
1599
+ ws.onerror = (e) => {
1600
+ console.warn("[acsWs] error", e?.message || e);
1601
+ };
1602
+ ws.onclose = () => {
1603
+ _ws2 = null;
1604
+ if (!_wantOpen) return;
1605
+ const delay = backoffMs(_retryAttempt++);
1606
+ console.log(`[acsWs] closed; reconnecting in ${Math.round(delay)}ms (attempt ${_retryAttempt})`);
1607
+ if (_retryTimer) clearTimeout(_retryTimer);
1608
+ _retryTimer = setTimeout(openSocket, delay);
1609
+ };
1610
+ }
1611
+ function notifyAcsWsForeground() {
1612
+ if (_wantOpen && !_ws2) {
1613
+ if (_retryTimer) {
1614
+ clearTimeout(_retryTimer);
1615
+ _retryTimer = null;
1616
+ }
1617
+ _retryAttempt = 0;
1618
+ openSocket();
1619
+ }
1620
+ }
1621
+ function connectAcsWs(token, tenant) {
1622
+ if (_ws2 && _wantOpen && _token === token && _tenant === tenant) return;
1623
+ if (_ws2) {
1624
+ try {
1625
+ _ws2.close();
1626
+ } catch {
1627
+ }
1628
+ _ws2 = null;
1629
+ }
1630
+ _token = token;
1631
+ _tenant = tenant;
1632
+ _wantOpen = true;
1633
+ openSocket();
1634
+ }
1635
+ function disconnectAcsWs() {
1636
+ _wantOpen = false;
1637
+ _token = null;
1638
+ _tenant = null;
1639
+ if (_retryTimer) {
1640
+ clearTimeout(_retryTimer);
1641
+ _retryTimer = null;
1642
+ }
1643
+ if (_ws2) {
1644
+ try {
1645
+ _ws2.close();
1646
+ } catch {
1647
+ }
1648
+ _ws2 = null;
1649
+ }
1650
+ }
1050
1651
  // Annotate the CommonJS export names for ESM import in node:
1051
1652
  0 && (module.exports = {
1052
1653
  PluginCommandEmitter,
@@ -1059,7 +1660,10 @@ var borderRadius = {
1059
1660
  borderRadius,
1060
1661
  closeChatStream,
1061
1662
  colors,
1663
+ connectAcsWs,
1062
1664
  connectorCall,
1665
+ deleteArtifact,
1666
+ disconnectAcsWs,
1063
1667
  fontSize,
1064
1668
  getConfig,
1065
1669
  getCoreApiUrl,
@@ -1070,12 +1674,26 @@ var borderRadius = {
1070
1674
  getVoiceApiUrl,
1071
1675
  initAdas,
1072
1676
  isAdasInitialized,
1677
+ listHomeActions,
1678
+ listMadeForYou,
1679
+ listMyTenants,
1680
+ listSurface,
1073
1681
  mcpFetch,
1074
1682
  mcpToolCall,
1683
+ notifyAcsWsForeground,
1684
+ patchArtifact,
1685
+ patchHomeAction,
1075
1686
  pluginCommandEmitter,
1076
1687
  postCommandResult,
1688
+ recordEvent,
1689
+ setAcsCacheStorage,
1690
+ setAcsReachabilityReporter,
1691
+ setHomeActionOrder,
1692
+ setOrder,
1077
1693
  spacing,
1078
1694
  unwrapMcpResult,
1079
- useChatStore
1695
+ useChatStore,
1696
+ useHomeActionsStore,
1697
+ useWidgetsStore
1080
1698
  });
1081
1699
  //# sourceMappingURL=index.js.map