@ateam-ai-mobile/core 0.1.15 → 0.1.17
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 +68 -1
- package/dist/index.d.ts +68 -1
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +21 -0
- package/src/notifications/api.ts +161 -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.17",
|
|
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/index.ts
CHANGED
|
@@ -45,6 +45,27 @@ export {
|
|
|
45
45
|
|
|
46
46
|
// Dev mode — the one per-person switch the chat chip, `/mode dev` and voice share
|
|
47
47
|
export { readDevMode, setDevMode } from './devMode';
|
|
48
|
+
// Notification prefs + push device registration (Core cp.notif_api), headless.
|
|
49
|
+
export {
|
|
50
|
+
getPrefs as getNotifPrefs,
|
|
51
|
+
setPrefs as setNotifPrefs,
|
|
52
|
+
linkTelegram as linkNotifTelegram,
|
|
53
|
+
unlinkChannel as unlinkNotifChannel,
|
|
54
|
+
recentDispatches as recentNotifDispatches,
|
|
55
|
+
getTelegramBotInfo as getNotifTelegramBotInfo,
|
|
56
|
+
registerDevice as registerPushDevice,
|
|
57
|
+
unregisterDevice as unregisterPushDevice,
|
|
58
|
+
} from './notifications/api';
|
|
59
|
+
export type {
|
|
60
|
+
NotifChannel,
|
|
61
|
+
ChannelPrefs,
|
|
62
|
+
QuietHoursPrefs,
|
|
63
|
+
NotifPrefs,
|
|
64
|
+
DispatchRow,
|
|
65
|
+
TelegramBotInfo,
|
|
66
|
+
DevicePlatform,
|
|
67
|
+
RegisterDeviceResponse,
|
|
68
|
+
} from './notifications/api';
|
|
48
69
|
export { devModeFromCatalog } from './devModeState';
|
|
49
70
|
export type { DevModeState } from './devModeState';
|
|
50
71
|
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification preferences & device registration — Core's `cp.notif_api`.
|
|
3
|
+
*
|
|
4
|
+
* Headless: any host (an existing app embedding A-Team) reads and writes the
|
|
5
|
+
* person's notification channels, quiet hours and Telegram link, and registers
|
|
6
|
+
* its push token, without the SDK's UI. actorId and tenant are derived
|
|
7
|
+
* server-side from the JWT; callers cannot pass them.
|
|
8
|
+
*
|
|
9
|
+
* Moved from ateam-mobile src/api/notifApi.ts (2026-10-29). It now rides the
|
|
10
|
+
* SDK's one MCP client (mcpToolCall → apiFetchRaw) instead of its own fetch,
|
|
11
|
+
* so — like every SDK call — it sends no client tenant header.
|
|
12
|
+
*/
|
|
13
|
+
import { mcpToolCall, unwrapMcpResult } from '../api/mcp';
|
|
14
|
+
import { getToken } from '../config';
|
|
15
|
+
|
|
16
|
+
// ── Types ────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
export type NotifChannel = 'chat' | 'push' | 'telegram' | 'whatsapp' | 'email';
|
|
19
|
+
|
|
20
|
+
export interface ChannelPrefs {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Telegram chat id (string or number per backend contract; we keep string here). */
|
|
23
|
+
chatId?: string | number;
|
|
24
|
+
/** Push tokens — populated server-side, app reads but doesn't write. */
|
|
25
|
+
deviceTokens?: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface QuietHoursPrefs {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
/** "HH:mm" 24h, local time of `tz`. */
|
|
31
|
+
start?: string;
|
|
32
|
+
/** "HH:mm" 24h. */
|
|
33
|
+
end?: string;
|
|
34
|
+
/** IANA tz, e.g. "Asia/Jerusalem". */
|
|
35
|
+
tz?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface NotifPrefs {
|
|
39
|
+
channels: Record<NotifChannel, ChannelPrefs>;
|
|
40
|
+
quietHours: QuietHoursPrefs;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DispatchRow {
|
|
44
|
+
_id: string;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
tenant: string;
|
|
47
|
+
actorId: string;
|
|
48
|
+
action:
|
|
49
|
+
| 'notification.dispatched'
|
|
50
|
+
| 'notification.failed'
|
|
51
|
+
| 'notification.chat_only'
|
|
52
|
+
| 'notification.quiet_hours_skipped';
|
|
53
|
+
requestId: string;
|
|
54
|
+
details: {
|
|
55
|
+
channel?: NotifChannel | null;
|
|
56
|
+
urgency?: string;
|
|
57
|
+
jobId?: string;
|
|
58
|
+
skillSlug?: string;
|
|
59
|
+
error?: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── Low-level call ────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
interface CallEnvelope<T> {
|
|
66
|
+
ok: boolean;
|
|
67
|
+
actorId?: string;
|
|
68
|
+
prefs?: T;
|
|
69
|
+
rows?: DispatchRow[];
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function callNotifApi<T = NotifPrefs>(
|
|
74
|
+
method: string,
|
|
75
|
+
params: Record<string, unknown> = {},
|
|
76
|
+
): Promise<CallEnvelope<T>> {
|
|
77
|
+
// Signed out: fail locally, never send (a push token) to Core unauthenticated.
|
|
78
|
+
if (!getToken()) throw new Error('Not authenticated');
|
|
79
|
+
const data = await mcpToolCall('cp.notif_api', { method, params });
|
|
80
|
+
if (data?.error) throw new Error(data.error.message || 'Notif API error');
|
|
81
|
+
const r = data?.result;
|
|
82
|
+
if (r?.structuredContent) return r.structuredContent as CallEnvelope<T>;
|
|
83
|
+
const out = unwrapMcpResult(r);
|
|
84
|
+
if (out && typeof out === 'object' && !Array.isArray(out) && 'ok' in out) return out as CallEnvelope<T>;
|
|
85
|
+
if (typeof out === 'string') throw new Error(`Notif API returned unparseable text: ${out.slice(0, 80)}`);
|
|
86
|
+
throw new Error('Notif API returned no result payload');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ── Public API ───────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
export async function getPrefs(): Promise<NotifPrefs> {
|
|
92
|
+
const res = await callNotifApi<NotifPrefs>('getPrefs');
|
|
93
|
+
if (!res.ok || !res.prefs) throw new Error(res.error || 'Failed to load prefs');
|
|
94
|
+
return res.prefs;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Replaces the prefs document. Read first, mutate, then call this. */
|
|
98
|
+
export async function setPrefs(prefs: NotifPrefs): Promise<NotifPrefs> {
|
|
99
|
+
const res = await callNotifApi<NotifPrefs>('setPrefs', { prefs });
|
|
100
|
+
if (!res.ok || !res.prefs) throw new Error(res.error || 'Failed to save prefs');
|
|
101
|
+
return res.prefs;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function linkTelegram(chatId: string): Promise<NotifPrefs> {
|
|
105
|
+
const res = await callNotifApi<NotifPrefs>('linkTelegram', { chatId });
|
|
106
|
+
if (!res.ok || !res.prefs) throw new Error(res.error || 'Failed to link Telegram');
|
|
107
|
+
return res.prefs;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function unlinkChannel(channel: Exclude<NotifChannel, 'chat'>): Promise<NotifPrefs> {
|
|
111
|
+
const res = await callNotifApi<NotifPrefs>('unlinkChannel', { channel });
|
|
112
|
+
if (!res.ok || !res.prefs) throw new Error(res.error || 'Failed to unlink channel');
|
|
113
|
+
return res.prefs;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function recentDispatches(limit = 50): Promise<DispatchRow[]> {
|
|
117
|
+
const res = await callNotifApi('recentDispatches', { limit });
|
|
118
|
+
return res.rows || [];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ── Telegram bot info ────────────────────────────────────────
|
|
122
|
+
|
|
123
|
+
export interface TelegramBotInfo {
|
|
124
|
+
ok: boolean;
|
|
125
|
+
botName: string | null;
|
|
126
|
+
source: 'global' | 'tenant' | 'none';
|
|
127
|
+
error?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Returns the configured Telegram bot for this tenant. Used by the connect
|
|
132
|
+
* flow to build the deep-link and modal copy. Server never returns the bot
|
|
133
|
+
* token — only the public username.
|
|
134
|
+
*/
|
|
135
|
+
export async function getTelegramBotInfo(): Promise<TelegramBotInfo> {
|
|
136
|
+
const res = await callNotifApi('getTelegramBotInfo');
|
|
137
|
+
return res as unknown as TelegramBotInfo;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ── Device token registration ────────────────────────────────
|
|
141
|
+
|
|
142
|
+
export type DevicePlatform = 'ios' | 'android';
|
|
143
|
+
|
|
144
|
+
export interface RegisterDeviceResponse {
|
|
145
|
+
ok: boolean;
|
|
146
|
+
device?: { token: string; platform: DevicePlatform; lastSeen?: string };
|
|
147
|
+
error?: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function registerDevice(
|
|
151
|
+
token: string,
|
|
152
|
+
platform: DevicePlatform,
|
|
153
|
+
): Promise<RegisterDeviceResponse> {
|
|
154
|
+
const res = await callNotifApi('registerDevice', { token, platform });
|
|
155
|
+
return res as unknown as RegisterDeviceResponse;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export async function unregisterDevice(token: string): Promise<void> {
|
|
159
|
+
const res = await callNotifApi('unregisterDevice', { token });
|
|
160
|
+
if (!res.ok) throw new Error(res.error || 'Failed to unregister device');
|
|
161
|
+
}
|