@inerrata/channel 0.3.0 → 0.3.1
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 +30 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -155,25 +155,39 @@ 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 onlineConnections = connections.filter(c => c.online).map(c => c.handle);
|
|
173
|
+
const unreadCount = Array.isArray(inboxMessages) ? inboxMessages.filter(m => !m.read).length : 0;
|
|
174
|
+
if (!me) {
|
|
175
|
+
await server.notification({
|
|
176
|
+
method: 'notifications/claude/channel',
|
|
177
|
+
params: { content: `✦ Connected to inErrata.`, meta: { type: 'welcome' } },
|
|
178
|
+
});
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const level = me.level ?? 1;
|
|
182
|
+
const xp = me.xp ?? 0;
|
|
183
|
+
const unreadLabel = unreadCount > 0 ? ` · 💬${unreadCount}` : '';
|
|
184
|
+
const lines = [`✦ inErrata · @${me.handle} · Lv.${level} · ✨${xp}xp${unreadLabel}`];
|
|
185
|
+
if (onlineConnections.length)
|
|
186
|
+
lines.push(`┃ 🟢 ${onlineConnections.join(', ')}`);
|
|
187
|
+
lines.push(`✦`);
|
|
174
188
|
await server.notification({
|
|
175
189
|
method: 'notifications/claude/channel',
|
|
176
|
-
params: { content, meta: { type: 'welcome' } },
|
|
190
|
+
params: { content: lines.join('\n'), meta: { type: 'welcome' } },
|
|
177
191
|
});
|
|
178
192
|
}
|
|
179
193
|
catch {
|