@ateam-ai-mobile/core 0.1.3 → 0.1.5

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 CHANGED
@@ -129,6 +129,7 @@ declare function getConsumerAuthApiUrl(): string;
129
129
  declare function getTenant(): string;
130
130
  declare function getUser(): AdasUser | null;
131
131
  declare function getToken(): string | null;
132
+ declare function refreshToken(): Promise<RefreshOutcome>;
132
133
 
133
134
  type FetchOptions = RequestInit & {
134
135
  baseUrl?: 'core' | 'voice';
@@ -760,4 +761,4 @@ interface AcsKvStorage {
760
761
  }
761
762
  declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
762
763
 
763
- export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type BufferedCommand, type DeleteResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type JobProgress, type Message, type MessageAttachment, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type RefreshOutcome, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TenantMembership, type TokenProvider, type ToolCall, type UIAction, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, closeChatStream, colors, connectAcsWs, connectorCall, deleteArtifact, disconnectAcsWs, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, notifyAcsWsForeground, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, recordEvent, setAcsCacheStorage, setAcsReachabilityReporter, setHomeActionOrder, setOrder, spacing, switchTenant, unwrapMcpResult, useChatStore, useHomeActionsStore, useWidgetsStore };
764
+ export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type BufferedCommand, type DeleteResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type JobProgress, type Message, type MessageAttachment, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type RefreshOutcome, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TenantMembership, type TokenProvider, type ToolCall, type UIAction, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, closeChatStream, colors, connectAcsWs, connectorCall, deleteArtifact, disconnectAcsWs, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, notifyAcsWsForeground, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, recordEvent, refreshToken, setAcsCacheStorage, setAcsReachabilityReporter, setHomeActionOrder, setOrder, spacing, switchTenant, unwrapMcpResult, useChatStore, useHomeActionsStore, useWidgetsStore };
package/dist/index.d.ts CHANGED
@@ -129,6 +129,7 @@ declare function getConsumerAuthApiUrl(): string;
129
129
  declare function getTenant(): string;
130
130
  declare function getUser(): AdasUser | null;
131
131
  declare function getToken(): string | null;
132
+ declare function refreshToken(): Promise<RefreshOutcome>;
132
133
 
133
134
  type FetchOptions = RequestInit & {
134
135
  baseUrl?: 'core' | 'voice';
@@ -760,4 +761,4 @@ interface AcsKvStorage {
760
761
  }
761
762
  declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
762
763
 
763
- export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type BufferedCommand, type DeleteResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type JobProgress, type Message, type MessageAttachment, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type RefreshOutcome, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TenantMembership, type TokenProvider, type ToolCall, type UIAction, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, closeChatStream, colors, connectAcsWs, connectorCall, deleteArtifact, disconnectAcsWs, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, notifyAcsWsForeground, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, recordEvent, setAcsCacheStorage, setAcsReachabilityReporter, setHomeActionOrder, setOrder, spacing, switchTenant, unwrapMcpResult, useChatStore, useHomeActionsStore, useWidgetsStore };
764
+ export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type BufferedCommand, type DeleteResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type JobProgress, type Message, type MessageAttachment, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type RefreshOutcome, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TenantMembership, type TokenProvider, type ToolCall, type UIAction, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, closeChatStream, colors, connectAcsWs, connectorCall, deleteArtifact, disconnectAcsWs, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, notifyAcsWsForeground, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, recordEvent, refreshToken, setAcsCacheStorage, setAcsReachabilityReporter, setHomeActionOrder, setOrder, spacing, switchTenant, unwrapMcpResult, useChatStore, useHomeActionsStore, useWidgetsStore };
package/dist/index.js CHANGED
@@ -57,6 +57,7 @@ __export(index_exports, {
57
57
  pluginCommandEmitter: () => pluginCommandEmitter,
58
58
  postCommandResult: () => postCommandResult,
59
59
  recordEvent: () => recordEvent,
60
+ refreshToken: () => refreshToken,
60
61
  setAcsCacheStorage: () => setAcsCacheStorage,
61
62
  setAcsReachabilityReporter: () => setAcsReachabilityReporter,
62
63
  setHomeActionOrder: () => setHomeActionOrder,
@@ -528,69 +529,81 @@ var useChatStore = (0, import_zustand.create)((set, get) => ({
528
529
  finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
529
530
  let firstRunning = keptPlaceholders.find((m) => m.jobProgress?.status === "running");
530
531
  try {
531
- const chainRes = await fetch(`${getCoreApiUrl()}/api/chain/current`, {
532
+ let activeChains = [];
533
+ const chainsRes = await fetch(`${getCoreApiUrl()}/api/chains/active`, {
532
534
  headers: coreHeaders()
533
535
  });
534
- if (chainRes.ok) {
535
- const chainBody = await chainRes.json();
536
- const slim = chainBody?.data;
537
- if (slim?.id) {
538
- const chainId = String(slim.id);
539
- const alreadyTracked = finalMessages.some(
540
- (m) => m.role === "assistant" && m.jobProgress?.jobId === chainId
541
- );
542
- if (!alreadyTracked) {
543
- const progress = snapshotToProgress(slim, chainId);
544
- const chainCreatedAt = typeof slim.createdAt === "number" ? slim.createdAt : typeof slim.lastUpdate === "number" ? slim.lastUpdate : Date.now();
545
- const chainLastUpdate = typeof slim.lastUpdate === "number" ? slim.lastUpdate : chainCreatedAt;
546
- const jobProgress = {
547
- jobId: chainId,
548
- actorId: extractActorId(slim),
549
- status: "running",
550
- chainStartedAt: chainCreatedAt,
551
- ...progress
552
- };
553
- const goal = typeof slim.goal === "string" ? slim.goal : "";
554
- const userExists = finalMessages.some(
555
- (m) => m.role === "user" && (m.chainId === chainId || goal && m.content === goal)
556
- );
557
- if (goal && !userExists) {
558
- finalMessages.push({
559
- id: `user-${chainId}`,
560
- role: "user",
561
- content: goal,
562
- timestamp: new Date(chainCreatedAt),
563
- chainId
564
- });
565
- }
566
- let matchIdx = -1;
567
- for (let i = finalMessages.length - 1; i >= 0; i--) {
568
- const m = finalMessages[i];
569
- if (m.role === "assistant" && m.chainId === chainId) {
570
- matchIdx = i;
571
- break;
572
- }
573
- }
574
- if (matchIdx >= 0) {
575
- finalMessages[matchIdx] = { ...finalMessages[matchIdx], jobProgress };
576
- if (jobProgress.status === "running") firstRunning = finalMessages[matchIdx];
577
- } else {
578
- const reattachBubble = {
579
- id: `job-${chainId}`,
580
- role: "assistant",
581
- content: "Working on it...",
582
- timestamp: new Date(chainLastUpdate),
583
- jobProgress,
584
- chainId
585
- };
586
- finalMessages.push(reattachBubble);
587
- if (jobProgress.status === "running") firstRunning = reattachBubble;
588
- }
589
- finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
590
- streamJob(chainId, getTenant(), getToken());
536
+ if (chainsRes.ok) {
537
+ const body = await chainsRes.json();
538
+ activeChains = Array.isArray(body?.chains) ? body.chains : [];
539
+ } else {
540
+ const legacy = await fetch(`${getCoreApiUrl()}/api/chain/current`, {
541
+ headers: coreHeaders()
542
+ });
543
+ if (legacy.ok) {
544
+ const lb = await legacy.json();
545
+ if (lb?.data?.id) activeChains = [lb.data];
546
+ }
547
+ }
548
+ for (const slim of activeChains) {
549
+ if (!slim?.id) continue;
550
+ const chainId = String(slim.id);
551
+ const alreadyTracked = finalMessages.some(
552
+ (m) => m.role === "assistant" && m.jobProgress?.jobId === chainId
553
+ );
554
+ if (alreadyTracked) continue;
555
+ const progress = snapshotToProgress(
556
+ { ...slim, status: slim.chainStatus || slim.status },
557
+ chainId
558
+ );
559
+ const chainCreatedAt = typeof slim.createdAt === "number" ? slim.createdAt : typeof slim.lastUpdate === "number" ? slim.lastUpdate : Date.now();
560
+ const chainLastUpdate = typeof slim.lastUpdate === "number" ? slim.lastUpdate : chainCreatedAt;
561
+ const jobProgress = {
562
+ jobId: chainId,
563
+ actorId: extractActorId(slim),
564
+ status: "running",
565
+ chainStartedAt: chainCreatedAt,
566
+ ...progress
567
+ };
568
+ const goal = typeof slim.goal === "string" ? slim.goal : "";
569
+ const userExists = finalMessages.some(
570
+ (m) => m.role === "user" && (m.chainId === chainId || goal && m.content === goal)
571
+ );
572
+ if (goal && !userExists) {
573
+ finalMessages.push({
574
+ id: `user-${chainId}`,
575
+ role: "user",
576
+ content: goal,
577
+ timestamp: new Date(chainCreatedAt),
578
+ chainId
579
+ });
580
+ }
581
+ let matchIdx = -1;
582
+ for (let i = finalMessages.length - 1; i >= 0; i--) {
583
+ const m = finalMessages[i];
584
+ if (m.role === "assistant" && m.chainId === chainId) {
585
+ matchIdx = i;
586
+ break;
591
587
  }
592
588
  }
589
+ if (matchIdx >= 0) {
590
+ finalMessages[matchIdx] = { ...finalMessages[matchIdx], jobProgress };
591
+ if (jobProgress.status === "running" && !firstRunning) firstRunning = finalMessages[matchIdx];
592
+ } else {
593
+ const reattachBubble = {
594
+ id: `job-${chainId}`,
595
+ role: "assistant",
596
+ content: "Working on it...",
597
+ timestamp: new Date(chainLastUpdate),
598
+ jobProgress,
599
+ chainId
600
+ };
601
+ finalMessages.push(reattachBubble);
602
+ if (jobProgress.status === "running" && !firstRunning) firstRunning = reattachBubble;
603
+ }
604
+ streamJob(chainId, getTenant(), getToken());
593
605
  }
606
+ finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
594
607
  } catch {
595
608
  }
596
609
  set({
@@ -980,8 +993,22 @@ async function pollJob(jobId, token) {
980
993
 
981
994
  // src/api/tenants.ts
982
995
  async function listMyTenants() {
983
- const data = await apiFetch("/api/tenants/list");
984
- return data.ok && Array.isArray(data.tenants) ? data.tenants : [];
996
+ const token = getToken();
997
+ if (!token) return [];
998
+ try {
999
+ const res = await fetch(`${getConsumerAuthApiUrl()}/platform/consumer/my-tenants`, {
1000
+ headers: { Authorization: `Bearer ${token}` }
1001
+ });
1002
+ const data = await res.json().catch(() => null);
1003
+ if (!res.ok || !data?.ok || !Array.isArray(data.tenants)) return [];
1004
+ return data.tenants.map((t) => ({
1005
+ id: t.id,
1006
+ name: t.name || t.id,
1007
+ role: t.role ?? null
1008
+ }));
1009
+ } catch {
1010
+ return [];
1011
+ }
985
1012
  }
986
1013
  async function switchTenant(targetTenantId) {
987
1014
  const token = getToken();
@@ -1725,6 +1752,7 @@ function disconnectAcsWs() {
1725
1752
  pluginCommandEmitter,
1726
1753
  postCommandResult,
1727
1754
  recordEvent,
1755
+ refreshToken,
1728
1756
  setAcsCacheStorage,
1729
1757
  setAcsReachabilityReporter,
1730
1758
  setHomeActionOrder,