@ateam-ai-mobile/core 0.1.1 → 0.1.3

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
@@ -80,6 +80,10 @@ interface AdasConfig {
80
80
  coreUrl: UrlSource;
81
81
  /** Voice service base URL (optional — only voice features need it). */
82
82
  voiceUrl?: UrlSource;
83
+ /** Consumer-auth base URL, e.g. https://consumer-auth.ateam-ai.com. Only
84
+ * needed for `switchTenant()` (re-scoping the session to another tenant
85
+ * the user belongs to). */
86
+ consumerAuthUrl?: UrlSource;
83
87
  tokenProvider: TokenProvider;
84
88
  /** Tenant slug — used for plugin URL resolution and voice, never sent as a
85
89
  * header (the backend derives the tenant from the JWT). Pass a getter when
@@ -93,6 +97,24 @@ interface AdasConfig {
93
97
  * survive app restarts. No-op when omitted (previews live in memory for
94
98
  * the session only). @ateam-ai-mobile/ui ships an Expo/RN implementation. */
95
99
  attachmentCache?: AttachmentCache;
100
+ /** Called by `switchTenant()` with the freshly-minted session for the
101
+ * target tenant. The host MUST persist it here (store the new JWT so
102
+ * tokenProvider.getToken() returns it, and update the active tenant) —
103
+ * the SDK never stores credentials. Awaited before the chat reconnects. */
104
+ onSession?: (session: AdasSession) => void | Promise<void>;
105
+ }
106
+ /** A tenant-scoped session minted by the platform (e.g. via switchTenant). */
107
+ interface AdasSession {
108
+ jwt: string;
109
+ tenant: {
110
+ id: string;
111
+ name: string;
112
+ };
113
+ actor: {
114
+ id: string;
115
+ email: string | null;
116
+ roles: string[];
117
+ };
96
118
  }
97
119
  /** Register the SDK configuration. Call once at app start, before any other
98
120
  * SDK API. Calling again replaces the config (e.g. env switch) — combine
@@ -103,6 +125,7 @@ declare function getConfig(): AdasConfig;
103
125
  declare function getCoreApiUrl(): string;
104
126
  declare function getCoreWsUrl(): string;
105
127
  declare function getVoiceApiUrl(): string;
128
+ declare function getConsumerAuthApiUrl(): string;
106
129
  declare function getTenant(): string;
107
130
  declare function getUser(): AdasUser | null;
108
131
  declare function getToken(): string | null;
@@ -160,14 +183,26 @@ interface TenantMembership {
160
183
  /**
161
184
  * List the tenants the CURRENT user belongs to (GET /api/tenants/list).
162
185
  *
163
- * For consumer JWTs the backend resolves memberships by login identity
164
- * (google/apple oauth or embed id) across active tenants; builder JWTs get
165
- * their user-doc memberships. Returns [] when signed out or unknown.
166
- *
167
- * Note: switching tenant still requires a NEW JWT for that tenant (the
168
- * token is tenant-scoped) — the host owns that re-auth flow.
186
+ * The list is membership-scoped: for consumer JWTs the backend returns ONLY
187
+ * tenants where the user's login identity (google/apple oauth or embed id)
188
+ * has an active actor; builder JWTs get their user-doc memberships. It never
189
+ * leaks the full tenant list. Returns [] when signed out or unknown.
169
190
  */
170
191
  declare function listMyTenants(): Promise<TenantMembership[]>;
192
+ /**
193
+ * Re-scope the whole session to another tenant the user already belongs to.
194
+ *
195
+ * The backend treats the JWT tenant claim as the sole source of truth, so
196
+ * switching = minting a fresh JWT for the target tenant's actor. The SDK
197
+ * owns the call (POST consumer-auth /platform/consumer/switch-tenant, authed
198
+ * by the current token); the HOST persists the new session via
199
+ * `config.onSession` (the SDK never stores credentials). The chat stream is
200
+ * then torn down and cleared so it reconnects against the new tenant.
201
+ *
202
+ * Requires `consumerAuthUrl` and `onSession` in the initAdas() config.
203
+ * Throws on any non-OK response (e.g. not a member of the target tenant).
204
+ */
205
+ declare function switchTenant(targetTenantId: string): Promise<AdasSession>;
171
206
 
172
207
  interface ToolCall {
173
208
  name: string;
@@ -198,6 +233,12 @@ interface JobProgress {
198
233
  step?: number;
199
234
  total?: number;
200
235
  };
236
+ /** One warm, present-tense, localized line describing the current action
237
+ * (backend statusI18n). Absent when disabled / not yet cached → fall back
238
+ * to raw tokens. */
239
+ humanStatus?: string;
240
+ /** Lookup { rawToken → friendly phrase } for tokens in this snapshot. */
241
+ humanLabels?: Record<string, string>;
201
242
  pendingQuestion?: {
202
243
  inputId: string;
203
244
  question: string;
@@ -719,4 +760,4 @@ interface AcsKvStorage {
719
760
  }
720
761
  declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
721
762
 
722
- export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, 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, 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, unwrapMcpResult, useChatStore, useHomeActionsStore, useWidgetsStore };
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 };
package/dist/index.d.ts CHANGED
@@ -80,6 +80,10 @@ interface AdasConfig {
80
80
  coreUrl: UrlSource;
81
81
  /** Voice service base URL (optional — only voice features need it). */
82
82
  voiceUrl?: UrlSource;
83
+ /** Consumer-auth base URL, e.g. https://consumer-auth.ateam-ai.com. Only
84
+ * needed for `switchTenant()` (re-scoping the session to another tenant
85
+ * the user belongs to). */
86
+ consumerAuthUrl?: UrlSource;
83
87
  tokenProvider: TokenProvider;
84
88
  /** Tenant slug — used for plugin URL resolution and voice, never sent as a
85
89
  * header (the backend derives the tenant from the JWT). Pass a getter when
@@ -93,6 +97,24 @@ interface AdasConfig {
93
97
  * survive app restarts. No-op when omitted (previews live in memory for
94
98
  * the session only). @ateam-ai-mobile/ui ships an Expo/RN implementation. */
95
99
  attachmentCache?: AttachmentCache;
100
+ /** Called by `switchTenant()` with the freshly-minted session for the
101
+ * target tenant. The host MUST persist it here (store the new JWT so
102
+ * tokenProvider.getToken() returns it, and update the active tenant) —
103
+ * the SDK never stores credentials. Awaited before the chat reconnects. */
104
+ onSession?: (session: AdasSession) => void | Promise<void>;
105
+ }
106
+ /** A tenant-scoped session minted by the platform (e.g. via switchTenant). */
107
+ interface AdasSession {
108
+ jwt: string;
109
+ tenant: {
110
+ id: string;
111
+ name: string;
112
+ };
113
+ actor: {
114
+ id: string;
115
+ email: string | null;
116
+ roles: string[];
117
+ };
96
118
  }
97
119
  /** Register the SDK configuration. Call once at app start, before any other
98
120
  * SDK API. Calling again replaces the config (e.g. env switch) — combine
@@ -103,6 +125,7 @@ declare function getConfig(): AdasConfig;
103
125
  declare function getCoreApiUrl(): string;
104
126
  declare function getCoreWsUrl(): string;
105
127
  declare function getVoiceApiUrl(): string;
128
+ declare function getConsumerAuthApiUrl(): string;
106
129
  declare function getTenant(): string;
107
130
  declare function getUser(): AdasUser | null;
108
131
  declare function getToken(): string | null;
@@ -160,14 +183,26 @@ interface TenantMembership {
160
183
  /**
161
184
  * List the tenants the CURRENT user belongs to (GET /api/tenants/list).
162
185
  *
163
- * For consumer JWTs the backend resolves memberships by login identity
164
- * (google/apple oauth or embed id) across active tenants; builder JWTs get
165
- * their user-doc memberships. Returns [] when signed out or unknown.
166
- *
167
- * Note: switching tenant still requires a NEW JWT for that tenant (the
168
- * token is tenant-scoped) — the host owns that re-auth flow.
186
+ * The list is membership-scoped: for consumer JWTs the backend returns ONLY
187
+ * tenants where the user's login identity (google/apple oauth or embed id)
188
+ * has an active actor; builder JWTs get their user-doc memberships. It never
189
+ * leaks the full tenant list. Returns [] when signed out or unknown.
169
190
  */
170
191
  declare function listMyTenants(): Promise<TenantMembership[]>;
192
+ /**
193
+ * Re-scope the whole session to another tenant the user already belongs to.
194
+ *
195
+ * The backend treats the JWT tenant claim as the sole source of truth, so
196
+ * switching = minting a fresh JWT for the target tenant's actor. The SDK
197
+ * owns the call (POST consumer-auth /platform/consumer/switch-tenant, authed
198
+ * by the current token); the HOST persists the new session via
199
+ * `config.onSession` (the SDK never stores credentials). The chat stream is
200
+ * then torn down and cleared so it reconnects against the new tenant.
201
+ *
202
+ * Requires `consumerAuthUrl` and `onSession` in the initAdas() config.
203
+ * Throws on any non-OK response (e.g. not a member of the target tenant).
204
+ */
205
+ declare function switchTenant(targetTenantId: string): Promise<AdasSession>;
171
206
 
172
207
  interface ToolCall {
173
208
  name: string;
@@ -198,6 +233,12 @@ interface JobProgress {
198
233
  step?: number;
199
234
  total?: number;
200
235
  };
236
+ /** One warm, present-tense, localized line describing the current action
237
+ * (backend statusI18n). Absent when disabled / not yet cached → fall back
238
+ * to raw tokens. */
239
+ humanStatus?: string;
240
+ /** Lookup { rawToken → friendly phrase } for tokens in this snapshot. */
241
+ humanLabels?: Record<string, string>;
201
242
  pendingQuestion?: {
202
243
  inputId: string;
203
244
  question: string;
@@ -719,4 +760,4 @@ interface AcsKvStorage {
719
760
  }
720
761
  declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
721
762
 
722
- export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, 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, 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, unwrapMcpResult, useChatStore, useHomeActionsStore, useWidgetsStore };
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 };
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  disconnectAcsWs: () => disconnectAcsWs,
37
37
  fontSize: () => fontSize,
38
38
  getConfig: () => getConfig,
39
+ getConsumerAuthApiUrl: () => getConsumerAuthApiUrl,
39
40
  getCoreApiUrl: () => getCoreApiUrl,
40
41
  getCoreWsUrl: () => getCoreWsUrl,
41
42
  getTenant: () => getTenant,
@@ -61,6 +62,7 @@ __export(index_exports, {
61
62
  setHomeActionOrder: () => setHomeActionOrder,
62
63
  setOrder: () => setOrder,
63
64
  spacing: () => spacing,
65
+ switchTenant: () => switchTenant,
64
66
  unwrapMcpResult: () => unwrapMcpResult,
65
67
  useChatStore: () => useChatStore,
66
68
  useHomeActionsStore: () => useHomeActionsStore,
@@ -96,6 +98,11 @@ function getVoiceApiUrl() {
96
98
  if (!url) throw new Error("[adas] voiceUrl not configured");
97
99
  return resolveUrl(url);
98
100
  }
101
+ function getConsumerAuthApiUrl() {
102
+ const url = getConfig().consumerAuthUrl;
103
+ if (!url) throw new Error("[adas] consumerAuthUrl not configured \u2014 required for switchTenant()");
104
+ return resolveUrl(url);
105
+ }
99
106
  function getTenant() {
100
107
  const t = getConfig().tenant;
101
108
  return (typeof t === "function" ? t() : t) || "";
@@ -235,12 +242,6 @@ function unwrapMcpResult(result) {
235
242
  }
236
243
  }
237
244
 
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
-
244
245
  // src/chat/store.ts
245
246
  var import_zustand = require("zustand");
246
247
 
@@ -362,6 +363,8 @@ function snapshotToProgress(snap, rootJobId) {
362
363
  };
363
364
  const liveProgress = extractLiveProgress(snap);
364
365
  if (liveProgress) progress.liveProgress = liveProgress;
366
+ if (typeof snap?.humanStatus === "string" && snap.humanStatus) progress.humanStatus = snap.humanStatus;
367
+ if (snap?.humanLabels && typeof snap.humanLabels === "object") progress.humanLabels = snap.humanLabels;
365
368
  if (pq) {
366
369
  progress.pendingQuestion = {
367
370
  inputId: pq.correlation_id || pq.correlationId || pq.inputId || "",
@@ -975,6 +978,41 @@ async function pollJob(jobId, token) {
975
978
  });
976
979
  }
977
980
 
981
+ // src/api/tenants.ts
982
+ async function listMyTenants() {
983
+ const data = await apiFetch("/api/tenants/list");
984
+ return data.ok && Array.isArray(data.tenants) ? data.tenants : [];
985
+ }
986
+ async function switchTenant(targetTenantId) {
987
+ const token = getToken();
988
+ if (!token) throw new Error("[adas] switchTenant: not signed in");
989
+ const res = await fetch(`${getConsumerAuthApiUrl()}/platform/consumer/switch-tenant`, {
990
+ method: "POST",
991
+ headers: {
992
+ "Content-Type": "application/json",
993
+ Authorization: `Bearer ${token}`
994
+ },
995
+ body: JSON.stringify({ target_tenant: targetTenantId })
996
+ });
997
+ const data = await res.json().catch(() => null);
998
+ if (!res.ok || !data?.ok || !data.jwt) {
999
+ throw new Error(data?.error || `switchTenant failed (${res.status})`);
1000
+ }
1001
+ const session = {
1002
+ jwt: data.jwt,
1003
+ tenant: data.tenant,
1004
+ actor: data.actor
1005
+ };
1006
+ const onSession = getConfig().onSession;
1007
+ if (!onSession) {
1008
+ throw new Error("[adas] switchTenant: config.onSession is required to persist the new session");
1009
+ }
1010
+ await onSession(session);
1011
+ closeChatStream();
1012
+ useChatStore.getState().clearChat();
1013
+ return session;
1014
+ }
1015
+
978
1016
  // src/theme/tokens.ts
979
1017
  var colors = {
980
1018
  dark: {
@@ -1666,6 +1704,7 @@ function disconnectAcsWs() {
1666
1704
  disconnectAcsWs,
1667
1705
  fontSize,
1668
1706
  getConfig,
1707
+ getConsumerAuthApiUrl,
1669
1708
  getCoreApiUrl,
1670
1709
  getCoreWsUrl,
1671
1710
  getTenant,
@@ -1691,6 +1730,7 @@ function disconnectAcsWs() {
1691
1730
  setHomeActionOrder,
1692
1731
  setOrder,
1693
1732
  spacing,
1733
+ switchTenant,
1694
1734
  unwrapMcpResult,
1695
1735
  useChatStore,
1696
1736
  useHomeActionsStore,