@ateam-ai-mobile/core 0.1.30 → 0.1.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ateam-ai-mobile/core",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "Headless ADAS SDK core — auth bridge, API client, chat/job streaming, MCP calls, theme tokens. No UI, no Expo dependencies.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -5,6 +5,42 @@ export interface TenantMembership {
5
5
  id: string;
6
6
  name: string;
7
7
  role: string | null;
8
+ /** Id of the cluster master this workspace sits under; set only when the person also has that master. */
9
+ master?: string;
10
+ }
11
+
12
+ export interface TenantRow {
13
+ tenant: TenantMembership;
14
+ /** 0 = top level, 1 = a cluster member shown under its master. */
15
+ depth: 0 | 1;
16
+ /** Last member of its master's group (draws the connector's end). */
17
+ last: boolean;
18
+ /** How many members this row is the master of. */
19
+ memberCount: number;
20
+ }
21
+
22
+ /**
23
+ * Order a membership list for display: cluster members sit right under their master, everything else keeps its
24
+ * order. Pure; every workspace appears exactly once, whatever the links (chains A>B>C all sit one level in).
25
+ * The same rule as the web switcher (WorkspaceSwitcher.jsx nestByMaster) so web and phone read the same.
26
+ */
27
+ export function nestByMaster(tenants: TenantMembership[]): TenantRow[] {
28
+ const ids = new Set(tenants.map(t => t.id));
29
+ const hasMaster = (t: TenantMembership) => !!t.master && t.master !== t.id && ids.has(t.master);
30
+ const kids = new Map<string, TenantMembership[]>();
31
+ for (const t of tenants) if (hasMaster(t)) kids.set(t.master!, [...(kids.get(t.master!) || []), t]);
32
+ const rows: TenantRow[] = [];
33
+ const seen = new Set<string>();
34
+ const add = (t: TenantMembership, depth: 0 | 1, last: boolean) => {
35
+ if (seen.has(t.id)) return;
36
+ seen.add(t.id);
37
+ const k = kids.get(t.id) || [];
38
+ rows.push({ tenant: t, depth, last, memberCount: k.length });
39
+ k.forEach((m, i) => add(m, 1, i === k.length - 1));
40
+ };
41
+ for (const t of tenants) if (!hasMaster(t)) add(t, 0, false);
42
+ for (const t of tenants) add(t, 0, false); // safety net: nothing is ever dropped
43
+ return rows;
8
44
  }
9
45
 
10
46
  /**
@@ -44,6 +80,7 @@ export async function listMyTenants(): Promise<TenantMembership[]> {
44
80
  // a team switcher is unpickable.
45
81
  name: t.name || t.id,
46
82
  role: t.role ?? null,
83
+ ...(typeof t.master === 'string' && t.master ? { master: t.master } : {}),
47
84
  }));
48
85
  } catch {
49
86
  return [];
package/src/index.ts CHANGED
@@ -138,8 +138,8 @@ export type {
138
138
  WorkspaceState,
139
139
  WorkspaceCapabilities,
140
140
  } from './workspace';
141
- export { listMyTenants, switchTenant } from './api/tenants';
142
- export type { TenantMembership } from './api/tenants';
141
+ export { listMyTenants, switchTenant, nestByMaster } from './api/tenants';
142
+ export type { TenantMembership, TenantRow } from './api/tenants';
143
143
 
144
144
  // Chat
145
145
  export {