@ateam-ai-mobile/core 0.1.0 → 0.1.2

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
@@ -12,8 +12,11 @@ function getConfig() {
12
12
  }
13
13
  return _config;
14
14
  }
15
+ function resolveUrl(src) {
16
+ return (typeof src === "function" ? src() : src).replace(/\/$/, "");
17
+ }
15
18
  function getCoreApiUrl() {
16
- return getConfig().coreUrl.replace(/\/$/, "");
19
+ return resolveUrl(getConfig().coreUrl);
17
20
  }
18
21
  function getCoreWsUrl() {
19
22
  return getCoreApiUrl().replace(/^http/, "ws");
@@ -21,10 +24,16 @@ function getCoreWsUrl() {
21
24
  function getVoiceApiUrl() {
22
25
  const url = getConfig().voiceUrl;
23
26
  if (!url) throw new Error("[adas] voiceUrl not configured");
24
- return url.replace(/\/$/, "");
27
+ return resolveUrl(url);
28
+ }
29
+ function getConsumerAuthApiUrl() {
30
+ const url = getConfig().consumerAuthUrl;
31
+ if (!url) throw new Error("[adas] consumerAuthUrl not configured \u2014 required for switchTenant()");
32
+ return resolveUrl(url);
25
33
  }
26
34
  function getTenant() {
27
- return getConfig().tenant || "";
35
+ const t = getConfig().tenant;
36
+ return (typeof t === "function" ? t() : t) || "";
28
37
  }
29
38
  function getUser() {
30
39
  return getConfig().getUser?.() || null;
@@ -895,6 +904,41 @@ async function pollJob(jobId, token) {
895
904
  });
896
905
  }
897
906
 
907
+ // src/api/tenants.ts
908
+ async function listMyTenants() {
909
+ const data = await apiFetch("/api/tenants/list");
910
+ return data.ok && Array.isArray(data.tenants) ? data.tenants : [];
911
+ }
912
+ async function switchTenant(targetTenantId) {
913
+ const token = getToken();
914
+ if (!token) throw new Error("[adas] switchTenant: not signed in");
915
+ const res = await fetch(`${getConsumerAuthApiUrl()}/platform/consumer/switch-tenant`, {
916
+ method: "POST",
917
+ headers: {
918
+ "Content-Type": "application/json",
919
+ Authorization: `Bearer ${token}`
920
+ },
921
+ body: JSON.stringify({ target_tenant: targetTenantId })
922
+ });
923
+ const data = await res.json().catch(() => null);
924
+ if (!res.ok || !data?.ok || !data.jwt) {
925
+ throw new Error(data?.error || `switchTenant failed (${res.status})`);
926
+ }
927
+ const session = {
928
+ jwt: data.jwt,
929
+ tenant: data.tenant,
930
+ actor: data.actor
931
+ };
932
+ const onSession = getConfig().onSession;
933
+ if (!onSession) {
934
+ throw new Error("[adas] switchTenant: config.onSession is required to persist the new session");
935
+ }
936
+ await onSession(session);
937
+ closeChatStream();
938
+ useChatStore.getState().clearChat();
939
+ return session;
940
+ }
941
+
898
942
  // src/theme/tokens.ts
899
943
  var colors = {
900
944
  dark: {
@@ -994,6 +1038,580 @@ var borderRadius = {
994
1038
  xl: 20,
995
1039
  full: 9999
996
1040
  };
1041
+
1042
+ // src/acs/providers.ts
1043
+ var _reachability = null;
1044
+ function setAcsReachabilityReporter(r) {
1045
+ _reachability = r;
1046
+ }
1047
+ function reportAcsServerUp() {
1048
+ try {
1049
+ _reachability?.up();
1050
+ } catch {
1051
+ }
1052
+ }
1053
+ function reportAcsServerDown() {
1054
+ try {
1055
+ _reachability?.down();
1056
+ } catch {
1057
+ }
1058
+ }
1059
+ var _kv = null;
1060
+ function setAcsCacheStorage(kv) {
1061
+ _kv = kv;
1062
+ }
1063
+ function getAcsCacheStorage() {
1064
+ return _kv;
1065
+ }
1066
+
1067
+ // src/acs/api.ts
1068
+ async function authedFetch(path, init) {
1069
+ const token = getToken();
1070
+ try {
1071
+ const res = await fetch(`${getCoreApiUrl()}${path}`, {
1072
+ ...init,
1073
+ headers: {
1074
+ "Content-Type": "application/json",
1075
+ ...token ? { Authorization: `Bearer ${token}` } : {},
1076
+ ...init?.headers || {}
1077
+ }
1078
+ });
1079
+ reportAcsServerUp();
1080
+ return res;
1081
+ } catch (e) {
1082
+ reportAcsServerDown();
1083
+ throw e;
1084
+ }
1085
+ }
1086
+ async function listSurface(surface, context) {
1087
+ try {
1088
+ const res = await authedFetch("/api/acs/surface", {
1089
+ method: "POST",
1090
+ body: JSON.stringify({ surface, ...context ? { context } : {} })
1091
+ });
1092
+ if (!res.ok) {
1093
+ console.warn(`[acs] /surface ${surface} returned ${res.status}`);
1094
+ return [];
1095
+ }
1096
+ const data = await res.json();
1097
+ return Array.isArray(data?.items) ? data.items : [];
1098
+ } catch (e) {
1099
+ console.warn("[acs] /surface failed:", e?.message || e);
1100
+ return [];
1101
+ }
1102
+ }
1103
+ async function listMadeForYou() {
1104
+ try {
1105
+ const res = await authedFetch("/api/acs/made-for-you", { method: "GET" });
1106
+ if (!res.ok) {
1107
+ console.warn(`[acs] /made-for-you returned ${res.status}`);
1108
+ return [];
1109
+ }
1110
+ const data = await res.json();
1111
+ return Array.isArray(data?.artifacts) ? data.artifacts : [];
1112
+ } catch (e) {
1113
+ console.warn("[acs] /made-for-you failed:", e?.message || e);
1114
+ return [];
1115
+ }
1116
+ }
1117
+ async function deleteArtifact(artifactId, reason = "user_long_press_delete") {
1118
+ try {
1119
+ const res = await authedFetch(
1120
+ `/api/acs/artifacts/${encodeURIComponent(artifactId)}`,
1121
+ { method: "DELETE", body: JSON.stringify({ reason }) }
1122
+ );
1123
+ const data = await res.json().catch(() => ({}));
1124
+ if (res.ok) {
1125
+ return { ok: true, already: !!data?.already, status: res.status };
1126
+ }
1127
+ if (res.status === 404) {
1128
+ return { ok: true, notFound: true, status: 404 };
1129
+ }
1130
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1131
+ } catch (e) {
1132
+ return { ok: false, status: 0, error: e?.message || "network error" };
1133
+ }
1134
+ }
1135
+ async function patchArtifact(artifactId, body, reason) {
1136
+ try {
1137
+ const res = await authedFetch(
1138
+ `/api/acs/artifacts/${encodeURIComponent(artifactId)}`,
1139
+ { method: "PATCH", body: JSON.stringify({ ...body, reason }) }
1140
+ );
1141
+ const data = await res.json().catch(() => ({}));
1142
+ if (res.ok) {
1143
+ return {
1144
+ ok: true,
1145
+ already: !!data?.already,
1146
+ artifact: data?.artifact || void 0,
1147
+ status: res.status
1148
+ };
1149
+ }
1150
+ if (res.status === 404) {
1151
+ return { ok: true, notFound: true, status: 404 };
1152
+ }
1153
+ return {
1154
+ ok: false,
1155
+ status: res.status,
1156
+ error: data?.error || `HTTP ${res.status}`
1157
+ };
1158
+ } catch (e) {
1159
+ return { ok: false, status: 0, error: e?.message || "network error" };
1160
+ }
1161
+ }
1162
+ async function setOrder(pinned) {
1163
+ try {
1164
+ const res = await authedFetch("/api/acs/order", {
1165
+ method: "PUT",
1166
+ body: JSON.stringify({ pinned })
1167
+ });
1168
+ if (res.ok) return { ok: true, status: res.status };
1169
+ const data = await res.json().catch(() => ({}));
1170
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1171
+ } catch (e) {
1172
+ return { ok: false, status: 0, error: e?.message || "network error" };
1173
+ }
1174
+ }
1175
+ async function recordEvent(artifactId, event, surface) {
1176
+ try {
1177
+ await authedFetch("/api/acs/event", {
1178
+ method: "POST",
1179
+ body: JSON.stringify({ artifactId, event, ...surface ? { surface } : {} })
1180
+ });
1181
+ } catch {
1182
+ }
1183
+ }
1184
+ async function listHomeActions() {
1185
+ try {
1186
+ const res = await authedFetch("/api/acs/home-actions", { method: "GET" });
1187
+ if (!res.ok) {
1188
+ console.warn(`[acs] /home-actions returned ${res.status}`);
1189
+ return [];
1190
+ }
1191
+ const data = await res.json();
1192
+ return Array.isArray(data?.actions) ? data.actions : [];
1193
+ } catch (e) {
1194
+ console.warn("[acs] /home-actions failed:", e?.message || e);
1195
+ return [];
1196
+ }
1197
+ }
1198
+ async function patchHomeAction(actionId, body, reason) {
1199
+ try {
1200
+ const res = await authedFetch(
1201
+ `/api/acs/home-actions/${encodeURIComponent(actionId)}`,
1202
+ { method: "PATCH", body: JSON.stringify({ ...body, reason }) }
1203
+ );
1204
+ const data = await res.json().catch(() => ({}));
1205
+ if (res.ok) return { ok: true, action: data?.action || void 0, status: res.status };
1206
+ if (res.status === 404) return { ok: true, status: 404 };
1207
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1208
+ } catch (e) {
1209
+ return { ok: false, status: 0, error: e?.message || "network error" };
1210
+ }
1211
+ }
1212
+ async function setHomeActionOrder(order) {
1213
+ try {
1214
+ const res = await authedFetch("/api/acs/home-actions/order", {
1215
+ method: "PUT",
1216
+ body: JSON.stringify({ order })
1217
+ });
1218
+ if (res.ok) return { ok: true, status: res.status };
1219
+ const data = await res.json().catch(() => ({}));
1220
+ return { ok: false, status: res.status, error: data?.error || `HTTP ${res.status}` };
1221
+ } catch (e) {
1222
+ return { ok: false, status: 0, error: e?.message || "network error" };
1223
+ }
1224
+ }
1225
+
1226
+ // src/acs/widgetsStore.ts
1227
+ import { create as create2 } from "zustand";
1228
+ var useWidgetsStore = create2((set, get) => ({
1229
+ tiles: [],
1230
+ hydrated: false,
1231
+ loading: false,
1232
+ error: null,
1233
+ hydrate: async () => {
1234
+ if (get().hydrated || get().loading) return;
1235
+ await get().refresh();
1236
+ },
1237
+ refresh: async () => {
1238
+ if (get().loading) return;
1239
+ set({ loading: true, error: null });
1240
+ try {
1241
+ const tiles = await listSurface("home");
1242
+ set({ tiles, loading: false, hydrated: true });
1243
+ } catch (e) {
1244
+ set({ loading: false, hydrated: true, error: e?.message || "Failed to load widgets" });
1245
+ }
1246
+ },
1247
+ clear: () => set({ tiles: [], hydrated: false, loading: false, error: null }),
1248
+ remove: async (artifactId, reason = "user_long_press_delete") => {
1249
+ const before = get().tiles;
1250
+ set({ tiles: before.filter((t) => t.id !== artifactId) });
1251
+ const result = await deleteArtifact(artifactId, reason);
1252
+ if (result.ok) {
1253
+ return { ok: true };
1254
+ }
1255
+ set({ tiles: before });
1256
+ return { ok: false, error: result.error || `HTTP ${result.status}` };
1257
+ },
1258
+ hide: async (artifactId) => {
1259
+ const before = get().tiles;
1260
+ set({
1261
+ tiles: before.map(
1262
+ (t) => t.id === artifactId ? { ...t, visibility: "hidden" } : t
1263
+ )
1264
+ });
1265
+ const r = await patchArtifact(artifactId, { visibility: "hidden" }, "user_long_press_hide");
1266
+ if (r.ok) {
1267
+ if (r.artifact) {
1268
+ set({
1269
+ tiles: get().tiles.map((t) => t.id === artifactId ? { ...t, ...r.artifact } : t)
1270
+ });
1271
+ }
1272
+ return { ok: true };
1273
+ }
1274
+ set({ tiles: before });
1275
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1276
+ },
1277
+ unhide: async (artifactId) => {
1278
+ const before = get().tiles;
1279
+ set({
1280
+ tiles: before.map(
1281
+ (t) => t.id === artifactId ? { ...t, visibility: "pinned" } : t
1282
+ )
1283
+ });
1284
+ const r = await patchArtifact(artifactId, { visibility: "pinned" }, "user_long_press_unhide");
1285
+ if (r.ok) {
1286
+ if (r.artifact) {
1287
+ set({
1288
+ tiles: get().tiles.map((t) => t.id === artifactId ? { ...t, ...r.artifact } : t)
1289
+ });
1290
+ }
1291
+ return { ok: true };
1292
+ }
1293
+ set({ tiles: before });
1294
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1295
+ },
1296
+ rename: async (artifactId, name) => {
1297
+ const trimmed = name.trim();
1298
+ if (!trimmed) return { ok: false, error: "Name cannot be empty" };
1299
+ if (trimmed.length > 60) return { ok: false, error: "Name must be 60 characters or less" };
1300
+ const before = get().tiles;
1301
+ set({
1302
+ tiles: before.map((t) => t.id === artifactId ? { ...t, name: trimmed } : t)
1303
+ });
1304
+ const r = await patchArtifact(artifactId, { name: trimmed }, "user_long_press_rename");
1305
+ if (r.ok) {
1306
+ if (r.artifact) {
1307
+ set({
1308
+ tiles: get().tiles.map((t) => t.id === artifactId ? { ...t, ...r.artifact } : t)
1309
+ });
1310
+ }
1311
+ return { ok: true };
1312
+ }
1313
+ set({ tiles: before });
1314
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1315
+ },
1316
+ reorder: async (pinnedIds) => {
1317
+ const before = get().tiles;
1318
+ const idToOrder = new Map(pinnedIds.map((id, i) => [id, i]));
1319
+ set({
1320
+ tiles: before.map((t) => {
1321
+ const o = idToOrder.get(t.id);
1322
+ return o == null ? t : { ...t, pinOrder: o };
1323
+ })
1324
+ });
1325
+ const r = await setOrder(pinnedIds);
1326
+ if (r.ok) return { ok: true };
1327
+ set({ tiles: before });
1328
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1329
+ },
1330
+ applyServerUpdate: (artifact) => {
1331
+ set({
1332
+ tiles: get().tiles.map((t) => t.id === artifact.id ? { ...t, ...artifact } : t)
1333
+ });
1334
+ },
1335
+ applyServerRetire: (artifactId) => {
1336
+ set({ tiles: get().tiles.filter((t) => t.id !== artifactId) });
1337
+ },
1338
+ applyServerOrder: (pinnedIds) => {
1339
+ const idToOrder = new Map(pinnedIds.map((id, i) => [id, i]));
1340
+ set({
1341
+ tiles: get().tiles.map((t) => {
1342
+ const o = idToOrder.get(t.id);
1343
+ return o == null ? t : { ...t, pinOrder: o };
1344
+ })
1345
+ });
1346
+ },
1347
+ track: (artifactId, event) => {
1348
+ recordEvent(artifactId, event, "home");
1349
+ }
1350
+ }));
1351
+
1352
+ // src/acs/homeActionsStore.ts
1353
+ import { create as create3 } from "zustand";
1354
+ var CACHE_KEY = "ateam.homeActions.v1";
1355
+ function persist(actions) {
1356
+ getAcsCacheStorage()?.setItem(CACHE_KEY, JSON.stringify(actions)).catch(() => {
1357
+ });
1358
+ }
1359
+ function sortByPin(a, b) {
1360
+ if (!!a.pinned !== !!b.pinned) return a.pinned ? -1 : 1;
1361
+ const ao = typeof a.pinOrder === "number" ? a.pinOrder : Number.MAX_SAFE_INTEGER;
1362
+ const bo = typeof b.pinOrder === "number" ? b.pinOrder : Number.MAX_SAFE_INTEGER;
1363
+ return ao - bo;
1364
+ }
1365
+ var useHomeActionsStore = create3((set, get) => ({
1366
+ actions: [],
1367
+ hydrated: false,
1368
+ loading: false,
1369
+ hydrate: async () => {
1370
+ if (get().hydrated || get().loading) return;
1371
+ try {
1372
+ const cached = await getAcsCacheStorage()?.getItem(CACHE_KEY);
1373
+ if (cached) {
1374
+ const parsed = JSON.parse(cached);
1375
+ if (Array.isArray(parsed) && parsed.length > 0) {
1376
+ set({ actions: parsed, hydrated: true });
1377
+ }
1378
+ }
1379
+ } catch {
1380
+ }
1381
+ await get().refresh();
1382
+ },
1383
+ refresh: async () => {
1384
+ if (get().loading) return;
1385
+ set({ loading: true });
1386
+ const actions = await listHomeActions();
1387
+ if (actions.length > 0) {
1388
+ set({ actions, loading: false, hydrated: true });
1389
+ persist(actions);
1390
+ } else {
1391
+ set({ loading: false, hydrated: true });
1392
+ }
1393
+ },
1394
+ // clear() wipes in-memory state on sign-out AND drops the disk cache — a
1395
+ // different user must not see the prior user's cards.
1396
+ clear: () => {
1397
+ set({ actions: [], hydrated: false, loading: false });
1398
+ getAcsCacheStorage()?.setItem(CACHE_KEY, "[]").catch(() => {
1399
+ });
1400
+ },
1401
+ dismiss: async (actionId) => {
1402
+ const before = get().actions;
1403
+ const next = before.filter((a) => a.actionId !== actionId);
1404
+ set({ actions: next });
1405
+ persist(next);
1406
+ const r = await patchHomeAction(actionId, { dismissed: true }, "user_dismiss");
1407
+ if (r.ok) return { ok: true };
1408
+ set({ actions: before });
1409
+ persist(before);
1410
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1411
+ },
1412
+ setPinned: async (actionId, pinned) => {
1413
+ const before = get().actions;
1414
+ const next = before.map((a) => a.actionId === actionId ? { ...a, pinned } : a).sort(sortByPin);
1415
+ set({ actions: next });
1416
+ persist(next);
1417
+ const r = await patchHomeAction(actionId, { pinned }, pinned ? "user_pin" : "user_unpin");
1418
+ if (r.ok) {
1419
+ if (r.action) {
1420
+ const merged = get().actions.map((a) => a.actionId === actionId ? { ...a, ...r.action } : a).sort(sortByPin);
1421
+ set({ actions: merged });
1422
+ persist(merged);
1423
+ }
1424
+ return { ok: true };
1425
+ }
1426
+ set({ actions: before });
1427
+ persist(before);
1428
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1429
+ },
1430
+ reorder: async (orderedIds) => {
1431
+ const before = get().actions;
1432
+ const idx = new Map(orderedIds.map((id, i) => [id, i]));
1433
+ const next = before.map((a) => {
1434
+ const o = idx.get(a.actionId);
1435
+ return o == null ? a : { ...a, pinOrder: o };
1436
+ }).sort(sortByPin);
1437
+ set({ actions: next });
1438
+ persist(next);
1439
+ const r = await setHomeActionOrder(orderedIds);
1440
+ if (r.ok) return { ok: true };
1441
+ set({ actions: before });
1442
+ persist(before);
1443
+ return { ok: false, error: r.error || `HTTP ${r.status}` };
1444
+ },
1445
+ applyServerUpsert: (action) => {
1446
+ const rest = get().actions.filter((a) => a.actionId !== action.actionId);
1447
+ const next = [...rest, action].sort(sortByPin);
1448
+ set({ actions: next });
1449
+ persist(next);
1450
+ },
1451
+ applyServerRemove: (actionId) => {
1452
+ const next = get().actions.filter((a) => a.actionId !== actionId);
1453
+ set({ actions: next });
1454
+ persist(next);
1455
+ },
1456
+ applyServerOrder: (orderedIds) => {
1457
+ const idx = new Map(orderedIds.map((id, i) => [id, i]));
1458
+ const next = get().actions.map((a) => {
1459
+ const o = idx.get(a.actionId);
1460
+ return o == null ? a : { ...a, pinOrder: o };
1461
+ }).sort(sortByPin);
1462
+ set({ actions: next });
1463
+ persist(next);
1464
+ }
1465
+ }));
1466
+
1467
+ // src/acs/ws.ts
1468
+ var _ws2 = null;
1469
+ var _wantOpen = false;
1470
+ var _retryAttempt = 0;
1471
+ var _retryTimer = null;
1472
+ var _token = null;
1473
+ var _tenant = null;
1474
+ var TOPIC = "acs.artifacts";
1475
+ var TOPIC_HOME = "acs.home-actions";
1476
+ var MAX_BACKOFF_MS = 3e4;
1477
+ function backoffMs(attempt) {
1478
+ const base = Math.min(MAX_BACKOFF_MS, 500 * Math.pow(2, attempt));
1479
+ const jitter = Math.random() * 250;
1480
+ return base + jitter;
1481
+ }
1482
+ function send(obj) {
1483
+ if (_ws2 && _ws2.readyState === 1) {
1484
+ try {
1485
+ _ws2.send(JSON.stringify(obj));
1486
+ } catch (e) {
1487
+ console.warn("[acsWs] send failed", e);
1488
+ }
1489
+ }
1490
+ }
1491
+ function handleEvent(msg) {
1492
+ if (msg?.event === "subscribed") {
1493
+ console.log("[acsWs] subscribed to", msg?.data?.topic);
1494
+ return;
1495
+ }
1496
+ if (msg?.topic === TOPIC_HOME) {
1497
+ const home = useHomeActionsStore.getState();
1498
+ switch (msg.event) {
1499
+ case "updated":
1500
+ if (msg.action && typeof msg.action.actionId === "string") home.applyServerUpsert(msg.action);
1501
+ break;
1502
+ case "removed":
1503
+ if (typeof msg.actionId === "string") home.applyServerRemove(msg.actionId);
1504
+ break;
1505
+ case "order":
1506
+ if (Array.isArray(msg.order)) home.applyServerOrder(msg.order.filter((id) => typeof id === "string"));
1507
+ break;
1508
+ case "refreshed":
1509
+ home.refresh();
1510
+ break;
1511
+ default:
1512
+ break;
1513
+ }
1514
+ return;
1515
+ }
1516
+ if (msg?.topic !== TOPIC) return;
1517
+ const store = useWidgetsStore.getState();
1518
+ switch (msg.event) {
1519
+ case "updated":
1520
+ if (msg.artifact && typeof msg.artifact.id === "string") {
1521
+ store.applyServerUpdate(msg.artifact);
1522
+ }
1523
+ break;
1524
+ case "retired":
1525
+ if (typeof msg.artifactId === "string") {
1526
+ store.applyServerRetire(msg.artifactId);
1527
+ }
1528
+ break;
1529
+ case "order":
1530
+ if (Array.isArray(msg.pinned)) {
1531
+ store.applyServerOrder(msg.pinned.filter((id) => typeof id === "string"));
1532
+ }
1533
+ break;
1534
+ case "created":
1535
+ if (msg.artifact && typeof msg.artifact.id === "string") {
1536
+ store.applyServerUpdate(msg.artifact);
1537
+ }
1538
+ break;
1539
+ default:
1540
+ break;
1541
+ }
1542
+ }
1543
+ function openSocket() {
1544
+ if (_ws2) return;
1545
+ if (!_token || !_tenant) return;
1546
+ const url = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(_token)}&tenant=${encodeURIComponent(_tenant)}`;
1547
+ console.log(`[acsWs] opening`);
1548
+ const ws = new WebSocket(url);
1549
+ _ws2 = ws;
1550
+ ws.onopen = () => {
1551
+ _retryAttempt = 0;
1552
+ send({ type: "subscribe", topic: TOPIC });
1553
+ send({ type: "subscribe", topic: TOPIC_HOME });
1554
+ };
1555
+ ws.onmessage = (e) => {
1556
+ try {
1557
+ const msg = JSON.parse(typeof e.data === "string" ? e.data : "");
1558
+ handleEvent(msg);
1559
+ } catch (err) {
1560
+ console.warn("[acsWs] parse failed", err);
1561
+ }
1562
+ };
1563
+ ws.onerror = (e) => {
1564
+ console.warn("[acsWs] error", e?.message || e);
1565
+ };
1566
+ ws.onclose = () => {
1567
+ _ws2 = null;
1568
+ if (!_wantOpen) return;
1569
+ const delay = backoffMs(_retryAttempt++);
1570
+ console.log(`[acsWs] closed; reconnecting in ${Math.round(delay)}ms (attempt ${_retryAttempt})`);
1571
+ if (_retryTimer) clearTimeout(_retryTimer);
1572
+ _retryTimer = setTimeout(openSocket, delay);
1573
+ };
1574
+ }
1575
+ function notifyAcsWsForeground() {
1576
+ if (_wantOpen && !_ws2) {
1577
+ if (_retryTimer) {
1578
+ clearTimeout(_retryTimer);
1579
+ _retryTimer = null;
1580
+ }
1581
+ _retryAttempt = 0;
1582
+ openSocket();
1583
+ }
1584
+ }
1585
+ function connectAcsWs(token, tenant) {
1586
+ if (_ws2 && _wantOpen && _token === token && _tenant === tenant) return;
1587
+ if (_ws2) {
1588
+ try {
1589
+ _ws2.close();
1590
+ } catch {
1591
+ }
1592
+ _ws2 = null;
1593
+ }
1594
+ _token = token;
1595
+ _tenant = tenant;
1596
+ _wantOpen = true;
1597
+ openSocket();
1598
+ }
1599
+ function disconnectAcsWs() {
1600
+ _wantOpen = false;
1601
+ _token = null;
1602
+ _tenant = null;
1603
+ if (_retryTimer) {
1604
+ clearTimeout(_retryTimer);
1605
+ _retryTimer = null;
1606
+ }
1607
+ if (_ws2) {
1608
+ try {
1609
+ _ws2.close();
1610
+ } catch {
1611
+ }
1612
+ _ws2 = null;
1613
+ }
1614
+ }
997
1615
  export {
998
1616
  PluginCommandEmitter,
999
1617
  TABLE_BLOCK_CLOSE,
@@ -1005,9 +1623,13 @@ export {
1005
1623
  borderRadius,
1006
1624
  closeChatStream,
1007
1625
  colors,
1626
+ connectAcsWs,
1008
1627
  connectorCall,
1628
+ deleteArtifact,
1629
+ disconnectAcsWs,
1009
1630
  fontSize,
1010
1631
  getConfig,
1632
+ getConsumerAuthApiUrl,
1011
1633
  getCoreApiUrl,
1012
1634
  getCoreWsUrl,
1013
1635
  getTenant,
@@ -1016,12 +1638,27 @@ export {
1016
1638
  getVoiceApiUrl,
1017
1639
  initAdas,
1018
1640
  isAdasInitialized,
1641
+ listHomeActions,
1642
+ listMadeForYou,
1643
+ listMyTenants,
1644
+ listSurface,
1019
1645
  mcpFetch,
1020
1646
  mcpToolCall,
1647
+ notifyAcsWsForeground,
1648
+ patchArtifact,
1649
+ patchHomeAction,
1021
1650
  pluginCommandEmitter,
1022
1651
  postCommandResult,
1652
+ recordEvent,
1653
+ setAcsCacheStorage,
1654
+ setAcsReachabilityReporter,
1655
+ setHomeActionOrder,
1656
+ setOrder,
1023
1657
  spacing,
1658
+ switchTenant,
1024
1659
  unwrapMcpResult,
1025
- useChatStore
1660
+ useChatStore,
1661
+ useHomeActionsStore,
1662
+ useWidgetsStore
1026
1663
  };
1027
1664
  //# sourceMappingURL=index.mjs.map