@ateam-ai-mobile/core 0.1.29 → 0.1.31
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 +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/tenants.ts +37 -0
- package/src/chat/store.ts +2 -1
- package/src/index.ts +3 -2
- package/src/utils/hostIntents.ts +27 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ateam-ai-mobile/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.31",
|
|
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",
|
package/src/api/tenants.ts
CHANGED
|
@@ -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/chat/store.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { create } from 'zustand';
|
|
15
15
|
import { getCoreApiUrl, openCoreWs, getToken, getTenant, getUser, getConfig } from '../config';
|
|
16
16
|
import { pluginCommandEmitter } from '../utils/emitter';
|
|
17
|
+
import { focusPlugin } from '../utils/hostIntents';
|
|
17
18
|
import type { OutgoingAttachment } from '../storage/types';
|
|
18
19
|
import type { Message, MessageAttachment, JobProgress, UIAction } from './types';
|
|
19
20
|
|
|
@@ -717,7 +718,7 @@ function dispatchPluginCommands(cmds: any[]) {
|
|
|
717
718
|
const pluginId = cmd?.pluginId || cmd?.plugin_id || cmd?.args?.plugin_id;
|
|
718
719
|
if (pluginId) {
|
|
719
720
|
const props = cmd?.props ?? cmd?.args?.props ?? undefined;
|
|
720
|
-
|
|
721
|
+
focusPlugin(pluginId, props);
|
|
721
722
|
}
|
|
722
723
|
}
|
|
723
724
|
}
|
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 {
|
|
@@ -167,6 +167,7 @@ export type {
|
|
|
167
167
|
|
|
168
168
|
// Plugin command bus
|
|
169
169
|
export { pluginCommandEmitter, PluginCommandEmitter } from './utils/emitter';
|
|
170
|
+
export { registerHostIntent, focusPlugin } from './utils/hostIntents';
|
|
170
171
|
export type { BufferedCommand } from './utils/emitter';
|
|
171
172
|
|
|
172
173
|
// Theme tokens
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host intents: a focus request whose plugin id the host handles itself (a "platform:" surface that is an
|
|
3
|
+
* action, not a widget), e.g. platform:workspace {workspace}. ONE function serves both who can ask:
|
|
4
|
+
* - the agent, with sys.focusUiPlugin(plugin_id, props), which arrives down the chat stream;
|
|
5
|
+
* - a widget on screen, with the focus-plugin message (usePluginBridge).
|
|
6
|
+
* Both call `focusPlugin`. An id with a registered intent runs it, silently and locally (no server call of
|
|
7
|
+
* its own); any other id is emitted as 'focus-plugin' for the host to open as a widget, as before.
|
|
8
|
+
*/
|
|
9
|
+
import { pluginCommandEmitter } from './emitter';
|
|
10
|
+
|
|
11
|
+
type Intent = (props: any) => void;
|
|
12
|
+
const intents = new Map<string, Intent>();
|
|
13
|
+
|
|
14
|
+
export function registerHostIntent(pluginId: string, fn: Intent): void {
|
|
15
|
+
intents.set(pluginId, fn);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function focusPlugin(pluginId: string, props?: any): void {
|
|
19
|
+
const intent = intents.get(pluginId);
|
|
20
|
+
if (intent) {
|
|
21
|
+
try { intent(props && typeof props === 'object' ? props : {}); } catch (e: any) {
|
|
22
|
+
console.warn(`[hostIntent] ${pluginId} failed:`, e?.message || e);
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
pluginCommandEmitter.emit('focus-plugin', { pluginId, props });
|
|
27
|
+
}
|