@inerrata/channel 0.3.0 → 0.3.2
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.js +33 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -155,25 +155,42 @@ async function pushNotification(data) {
|
|
|
155
155
|
// ---------------------------------------------------------------------------
|
|
156
156
|
async function pushWelcome() {
|
|
157
157
|
try {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const [meRes, connRes, inboxRes] = await Promise.all([
|
|
159
|
+
apiFetch('/me'),
|
|
160
|
+
apiFetch('/messages/connections'),
|
|
161
|
+
apiFetch('/messages/inbox?limit=50&offset=0'),
|
|
162
|
+
]);
|
|
163
|
+
const me = meRes.ok
|
|
164
|
+
? (await meRes.json()).agent ?? null
|
|
161
165
|
: null;
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
166
|
+
const connections = connRes.ok
|
|
167
|
+
? (await connRes.json()).connections ?? []
|
|
168
|
+
: [];
|
|
169
|
+
const inboxMessages = inboxRes.ok
|
|
170
|
+
? (await inboxRes.json())
|
|
171
|
+
: [];
|
|
172
|
+
const onlineReachable = connections.filter(c => c.online && c.notifyReachable !== false).map(c => c.handle);
|
|
173
|
+
const onlineMcpOnly = connections.filter(c => c.online && c.notifyReachable === false).map(c => c.handle);
|
|
174
|
+
const unreadCount = Array.isArray(inboxMessages) ? inboxMessages.filter(m => !m.read).length : 0;
|
|
175
|
+
if (!me) {
|
|
176
|
+
await server.notification({
|
|
177
|
+
method: 'notifications/claude/channel',
|
|
178
|
+
params: { content: `✦ Connected to inErrata.`, meta: { type: 'welcome' } },
|
|
179
|
+
});
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const level = me.level ?? 1;
|
|
183
|
+
const xp = me.xp ?? 0;
|
|
184
|
+
const unreadLabel = unreadCount > 0 ? ` · 💬${unreadCount}` : '';
|
|
185
|
+
const lines = [`✦ inErrata · @${me.handle} · Lv.${level} · ✨${xp}xp${unreadLabel}`];
|
|
186
|
+
if (onlineReachable.length)
|
|
187
|
+
lines.push(`┃ 🟢 ${onlineReachable.join(', ')}`);
|
|
188
|
+
if (onlineMcpOnly.length)
|
|
189
|
+
lines.push(`┃ 🔵 ${onlineMcpOnly.join(', ')}`);
|
|
190
|
+
lines.push(`✦`);
|
|
174
191
|
await server.notification({
|
|
175
192
|
method: 'notifications/claude/channel',
|
|
176
|
-
params: { content, meta: { type: 'welcome' } },
|
|
193
|
+
params: { content: lines.join('\n'), meta: { type: 'welcome' } },
|
|
177
194
|
});
|
|
178
195
|
}
|
|
179
196
|
catch {
|