@ateam-ai-mobile/core 0.1.2 → 0.1.4

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
@@ -291,6 +291,8 @@ function snapshotToProgress(snap, rootJobId) {
291
291
  };
292
292
  const liveProgress = extractLiveProgress(snap);
293
293
  if (liveProgress) progress.liveProgress = liveProgress;
294
+ if (typeof snap?.humanStatus === "string" && snap.humanStatus) progress.humanStatus = snap.humanStatus;
295
+ if (snap?.humanLabels && typeof snap.humanLabels === "object") progress.humanLabels = snap.humanLabels;
294
296
  if (pq) {
295
297
  progress.pendingQuestion = {
296
298
  inputId: pq.correlation_id || pq.correlationId || pq.inputId || "",
@@ -454,69 +456,81 @@ var useChatStore = create((set, get) => ({
454
456
  finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
455
457
  let firstRunning = keptPlaceholders.find((m) => m.jobProgress?.status === "running");
456
458
  try {
457
- const chainRes = await fetch(`${getCoreApiUrl()}/api/chain/current`, {
459
+ let activeChains = [];
460
+ const chainsRes = await fetch(`${getCoreApiUrl()}/api/chains/active`, {
458
461
  headers: coreHeaders()
459
462
  });
460
- if (chainRes.ok) {
461
- const chainBody = await chainRes.json();
462
- const slim = chainBody?.data;
463
- if (slim?.id) {
464
- const chainId = String(slim.id);
465
- const alreadyTracked = finalMessages.some(
466
- (m) => m.role === "assistant" && m.jobProgress?.jobId === chainId
467
- );
468
- if (!alreadyTracked) {
469
- const progress = snapshotToProgress(slim, chainId);
470
- const chainCreatedAt = typeof slim.createdAt === "number" ? slim.createdAt : typeof slim.lastUpdate === "number" ? slim.lastUpdate : Date.now();
471
- const chainLastUpdate = typeof slim.lastUpdate === "number" ? slim.lastUpdate : chainCreatedAt;
472
- const jobProgress = {
473
- jobId: chainId,
474
- actorId: extractActorId(slim),
475
- status: "running",
476
- chainStartedAt: chainCreatedAt,
477
- ...progress
478
- };
479
- const goal = typeof slim.goal === "string" ? slim.goal : "";
480
- const userExists = finalMessages.some(
481
- (m) => m.role === "user" && (m.chainId === chainId || goal && m.content === goal)
482
- );
483
- if (goal && !userExists) {
484
- finalMessages.push({
485
- id: `user-${chainId}`,
486
- role: "user",
487
- content: goal,
488
- timestamp: new Date(chainCreatedAt),
489
- chainId
490
- });
491
- }
492
- let matchIdx = -1;
493
- for (let i = finalMessages.length - 1; i >= 0; i--) {
494
- const m = finalMessages[i];
495
- if (m.role === "assistant" && m.chainId === chainId) {
496
- matchIdx = i;
497
- break;
498
- }
499
- }
500
- if (matchIdx >= 0) {
501
- finalMessages[matchIdx] = { ...finalMessages[matchIdx], jobProgress };
502
- if (jobProgress.status === "running") firstRunning = finalMessages[matchIdx];
503
- } else {
504
- const reattachBubble = {
505
- id: `job-${chainId}`,
506
- role: "assistant",
507
- content: "Working on it...",
508
- timestamp: new Date(chainLastUpdate),
509
- jobProgress,
510
- chainId
511
- };
512
- finalMessages.push(reattachBubble);
513
- if (jobProgress.status === "running") firstRunning = reattachBubble;
514
- }
515
- finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
516
- streamJob(chainId, getTenant(), getToken());
463
+ if (chainsRes.ok) {
464
+ const body = await chainsRes.json();
465
+ activeChains = Array.isArray(body?.chains) ? body.chains : [];
466
+ } else {
467
+ const legacy = await fetch(`${getCoreApiUrl()}/api/chain/current`, {
468
+ headers: coreHeaders()
469
+ });
470
+ if (legacy.ok) {
471
+ const lb = await legacy.json();
472
+ if (lb?.data?.id) activeChains = [lb.data];
473
+ }
474
+ }
475
+ for (const slim of activeChains) {
476
+ if (!slim?.id) continue;
477
+ const chainId = String(slim.id);
478
+ const alreadyTracked = finalMessages.some(
479
+ (m) => m.role === "assistant" && m.jobProgress?.jobId === chainId
480
+ );
481
+ if (alreadyTracked) continue;
482
+ const progress = snapshotToProgress(
483
+ { ...slim, status: slim.chainStatus || slim.status },
484
+ chainId
485
+ );
486
+ const chainCreatedAt = typeof slim.createdAt === "number" ? slim.createdAt : typeof slim.lastUpdate === "number" ? slim.lastUpdate : Date.now();
487
+ const chainLastUpdate = typeof slim.lastUpdate === "number" ? slim.lastUpdate : chainCreatedAt;
488
+ const jobProgress = {
489
+ jobId: chainId,
490
+ actorId: extractActorId(slim),
491
+ status: "running",
492
+ chainStartedAt: chainCreatedAt,
493
+ ...progress
494
+ };
495
+ const goal = typeof slim.goal === "string" ? slim.goal : "";
496
+ const userExists = finalMessages.some(
497
+ (m) => m.role === "user" && (m.chainId === chainId || goal && m.content === goal)
498
+ );
499
+ if (goal && !userExists) {
500
+ finalMessages.push({
501
+ id: `user-${chainId}`,
502
+ role: "user",
503
+ content: goal,
504
+ timestamp: new Date(chainCreatedAt),
505
+ chainId
506
+ });
507
+ }
508
+ let matchIdx = -1;
509
+ for (let i = finalMessages.length - 1; i >= 0; i--) {
510
+ const m = finalMessages[i];
511
+ if (m.role === "assistant" && m.chainId === chainId) {
512
+ matchIdx = i;
513
+ break;
517
514
  }
518
515
  }
516
+ if (matchIdx >= 0) {
517
+ finalMessages[matchIdx] = { ...finalMessages[matchIdx], jobProgress };
518
+ if (jobProgress.status === "running" && !firstRunning) firstRunning = finalMessages[matchIdx];
519
+ } else {
520
+ const reattachBubble = {
521
+ id: `job-${chainId}`,
522
+ role: "assistant",
523
+ content: "Working on it...",
524
+ timestamp: new Date(chainLastUpdate),
525
+ jobProgress,
526
+ chainId
527
+ };
528
+ finalMessages.push(reattachBubble);
529
+ if (jobProgress.status === "running" && !firstRunning) firstRunning = reattachBubble;
530
+ }
531
+ streamJob(chainId, getTenant(), getToken());
519
532
  }
533
+ finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
520
534
  } catch {
521
535
  }
522
536
  set({
@@ -906,8 +920,22 @@ async function pollJob(jobId, token) {
906
920
 
907
921
  // src/api/tenants.ts
908
922
  async function listMyTenants() {
909
- const data = await apiFetch("/api/tenants/list");
910
- return data.ok && Array.isArray(data.tenants) ? data.tenants : [];
923
+ const token = getToken();
924
+ if (!token) return [];
925
+ try {
926
+ const res = await fetch(`${getConsumerAuthApiUrl()}/platform/consumer/my-tenants`, {
927
+ headers: { Authorization: `Bearer ${token}` }
928
+ });
929
+ const data = await res.json().catch(() => null);
930
+ if (!res.ok || !data?.ok || !Array.isArray(data.tenants)) return [];
931
+ return data.tenants.map((t) => ({
932
+ id: t.id,
933
+ name: t.name || t.id,
934
+ role: t.role ?? null
935
+ }));
936
+ } catch {
937
+ return [];
938
+ }
911
939
  }
912
940
  async function switchTenant(targetTenantId) {
913
941
  const token = getToken();
@@ -1650,6 +1678,7 @@ export {
1650
1678
  pluginCommandEmitter,
1651
1679
  postCommandResult,
1652
1680
  recordEvent,
1681
+ refreshToken,
1653
1682
  setAcsCacheStorage,
1654
1683
  setAcsReachabilityReporter,
1655
1684
  setHomeActionOrder,