@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.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +90 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/api/tenants.ts +16 -3
- package/src/chat/store.ts +97 -73
- package/src/chat/types.ts +6 -0
- package/src/index.ts +1 -0
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';
|
|
@@ -233,6 +234,12 @@ interface JobProgress {
|
|
|
233
234
|
step?: number;
|
|
234
235
|
total?: number;
|
|
235
236
|
};
|
|
237
|
+
/** One warm, present-tense, localized line describing the current action
|
|
238
|
+
* (backend statusI18n). Absent when disabled / not yet cached → fall back
|
|
239
|
+
* to raw tokens. */
|
|
240
|
+
humanStatus?: string;
|
|
241
|
+
/** Lookup { rawToken → friendly phrase } for tokens in this snapshot. */
|
|
242
|
+
humanLabels?: Record<string, string>;
|
|
236
243
|
pendingQuestion?: {
|
|
237
244
|
inputId: string;
|
|
238
245
|
question: string;
|
|
@@ -754,4 +761,4 @@ interface AcsKvStorage {
|
|
|
754
761
|
}
|
|
755
762
|
declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
|
|
756
763
|
|
|
757
|
-
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';
|
|
@@ -233,6 +234,12 @@ interface JobProgress {
|
|
|
233
234
|
step?: number;
|
|
234
235
|
total?: number;
|
|
235
236
|
};
|
|
237
|
+
/** One warm, present-tense, localized line describing the current action
|
|
238
|
+
* (backend statusI18n). Absent when disabled / not yet cached → fall back
|
|
239
|
+
* to raw tokens. */
|
|
240
|
+
humanStatus?: string;
|
|
241
|
+
/** Lookup { rawToken → friendly phrase } for tokens in this snapshot. */
|
|
242
|
+
humanLabels?: Record<string, string>;
|
|
236
243
|
pendingQuestion?: {
|
|
237
244
|
inputId: string;
|
|
238
245
|
question: string;
|
|
@@ -754,4 +761,4 @@ interface AcsKvStorage {
|
|
|
754
761
|
}
|
|
755
762
|
declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
|
|
756
763
|
|
|
757
|
-
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,
|
|
@@ -363,6 +364,8 @@ function snapshotToProgress(snap, rootJobId) {
|
|
|
363
364
|
};
|
|
364
365
|
const liveProgress = extractLiveProgress(snap);
|
|
365
366
|
if (liveProgress) progress.liveProgress = liveProgress;
|
|
367
|
+
if (typeof snap?.humanStatus === "string" && snap.humanStatus) progress.humanStatus = snap.humanStatus;
|
|
368
|
+
if (snap?.humanLabels && typeof snap.humanLabels === "object") progress.humanLabels = snap.humanLabels;
|
|
366
369
|
if (pq) {
|
|
367
370
|
progress.pendingQuestion = {
|
|
368
371
|
inputId: pq.correlation_id || pq.correlationId || pq.inputId || "",
|
|
@@ -526,69 +529,81 @@ var useChatStore = (0, import_zustand.create)((set, get) => ({
|
|
|
526
529
|
finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
|
|
527
530
|
let firstRunning = keptPlaceholders.find((m) => m.jobProgress?.status === "running");
|
|
528
531
|
try {
|
|
529
|
-
|
|
532
|
+
let activeChains = [];
|
|
533
|
+
const chainsRes = await fetch(`${getCoreApiUrl()}/api/chains/active`, {
|
|
530
534
|
headers: coreHeaders()
|
|
531
535
|
});
|
|
532
|
-
if (
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
};
|
|
584
|
-
finalMessages.push(reattachBubble);
|
|
585
|
-
if (jobProgress.status === "running") firstRunning = reattachBubble;
|
|
586
|
-
}
|
|
587
|
-
finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
|
|
588
|
-
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;
|
|
589
587
|
}
|
|
590
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());
|
|
591
605
|
}
|
|
606
|
+
finalMessages.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
|
|
592
607
|
} catch {
|
|
593
608
|
}
|
|
594
609
|
set({
|
|
@@ -978,8 +993,22 @@ async function pollJob(jobId, token) {
|
|
|
978
993
|
|
|
979
994
|
// src/api/tenants.ts
|
|
980
995
|
async function listMyTenants() {
|
|
981
|
-
const
|
|
982
|
-
|
|
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
|
+
}
|
|
983
1012
|
}
|
|
984
1013
|
async function switchTenant(targetTenantId) {
|
|
985
1014
|
const token = getToken();
|
|
@@ -1723,6 +1752,7 @@ function disconnectAcsWs() {
|
|
|
1723
1752
|
pluginCommandEmitter,
|
|
1724
1753
|
postCommandResult,
|
|
1725
1754
|
recordEvent,
|
|
1755
|
+
refreshToken,
|
|
1726
1756
|
setAcsCacheStorage,
|
|
1727
1757
|
setAcsReachabilityReporter,
|
|
1728
1758
|
setHomeActionOrder,
|