@lelouchhe/webagent 0.1.6 → 0.1.9
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/README.md +21 -18
- package/config.toml +1 -1
- package/dist/index.html +3 -2
- package/dist/js/app.IXP5KGP6.js +8 -0
- package/dist/{styles.mmlj9sk2.css → styles.01a9ju9l.css} +28 -1
- package/dist/sw.js +1 -1
- package/lib/event-handler.js +15 -6
- package/lib/push-service.js +66 -10
- package/lib/routes.js +816 -89
- package/lib/server.js +12 -10
- package/lib/session-manager.js +79 -2
- package/lib/shared/constants.js +16 -0
- package/lib/sse-manager.js +80 -0
- package/lib/store.js +61 -7
- package/lib/types.js +0 -35
- package/package.json +5 -6
- package/dist/js/app.mmlj9sk2.js +0 -34
- package/dist/js/commands.mmlj9sk2.js +0 -647
- package/dist/js/connection.mmlj9sk2.js +0 -87
- package/dist/js/events.mmlj9sk2.js +0 -674
- package/dist/js/images.mmlj9sk2.js +0 -58
- package/dist/js/input.mmlj9sk2.js +0 -215
- package/dist/js/render.mmlj9sk2.js +0 -200
- package/dist/js/state.mmlj9sk2.js +0 -178
- package/lib/ws-handler.js +0 -280
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// WebSocket connection lifecycle
|
|
2
|
-
|
|
3
|
-
import { state, setBusy, getHashSessionId, requestNewSession, resetSessionUI, setConnectionStatus, clearCancelTimer } from './state.mmlj9sk2.js';
|
|
4
|
-
import { addSystem, finishThinking, finishAssistant, finishBash, scrollToBottom } from './render.mmlj9sk2.js';
|
|
5
|
-
import { handleEvent, loadHistory, loadNewEvents, retryUnconfirmedPermissions } from './events.mmlj9sk2.js';
|
|
6
|
-
|
|
7
|
-
export function connect() {
|
|
8
|
-
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
9
|
-
setConnectionStatus('connecting', 'connecting');
|
|
10
|
-
state.ws = new WebSocket(`${proto}//${location.host}`);
|
|
11
|
-
|
|
12
|
-
state.ws.onopen = async () => {
|
|
13
|
-
setConnectionStatus('connecting', 'session loading');
|
|
14
|
-
// Report actual visibility to server for push notification gating
|
|
15
|
-
state.ws.send(JSON.stringify({ type: 'visibility', visible: !document.hidden }));
|
|
16
|
-
|
|
17
|
-
const existingId = getHashSessionId();
|
|
18
|
-
|
|
19
|
-
// Incremental reconnect: same session still in memory — skip DOM wipe
|
|
20
|
-
if (existingId && existingId === state.sessionId && state.lastEventSeq > 0) {
|
|
21
|
-
await loadNewEvents(existingId);
|
|
22
|
-
retryUnconfirmedPermissions();
|
|
23
|
-
scrollToBottom(false);
|
|
24
|
-
state.ws.send(JSON.stringify({ type: 'resume_session', sessionId: existingId }));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Full load: different session in hash, or first connect to a hash
|
|
29
|
-
if (existingId) {
|
|
30
|
-
resetSessionUI();
|
|
31
|
-
const loaded = await loadHistory(existingId);
|
|
32
|
-
if (loaded) {
|
|
33
|
-
scrollToBottom(true);
|
|
34
|
-
}
|
|
35
|
-
state.ws.send(JSON.stringify({ type: 'resume_session', sessionId: existingId }));
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// No session in URL — try to resume last active session
|
|
40
|
-
try {
|
|
41
|
-
const res = await fetch('/api/sessions');
|
|
42
|
-
const sessions = await res.json();
|
|
43
|
-
if (sessions.length > 0) {
|
|
44
|
-
const last = sessions[0];
|
|
45
|
-
resetSessionUI();
|
|
46
|
-
const loaded = await loadHistory(last.id);
|
|
47
|
-
if (loaded) {
|
|
48
|
-
scrollToBottom(true);
|
|
49
|
-
}
|
|
50
|
-
state.ws.send(JSON.stringify({ type: 'resume_session', sessionId: last.id }));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
} catch {}
|
|
54
|
-
|
|
55
|
-
// No previous sessions — create new
|
|
56
|
-
requestNewSession();
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
state.ws.onclose = () => {
|
|
60
|
-
setConnectionStatus('disconnected', 'disconnected');
|
|
61
|
-
finishThinking();
|
|
62
|
-
finishAssistant();
|
|
63
|
-
if (state.currentBashEl) { finishBash(state.currentBashEl, null, 'disconnected'); }
|
|
64
|
-
state.pendingToolCallIds.clear();
|
|
65
|
-
state.pendingPermissionRequestIds.clear();
|
|
66
|
-
state.pendingPromptDone = false;
|
|
67
|
-
state.turnEnded = false;
|
|
68
|
-
clearCancelTimer();
|
|
69
|
-
setBusy(false);
|
|
70
|
-
setTimeout(connect, 3000);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
state.ws.onerror = () => state.ws.close();
|
|
74
|
-
|
|
75
|
-
state.ws.onmessage = (e) => {
|
|
76
|
-
const msg = JSON.parse(e.data);
|
|
77
|
-
handleEvent(msg);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// --- Visibility reporting for push notifications ---
|
|
82
|
-
|
|
83
|
-
document.addEventListener('visibilitychange', () => {
|
|
84
|
-
if (state.ws && state.ws.readyState === 1) {
|
|
85
|
-
state.ws.send(JSON.stringify({ type: 'visibility', visible: !document.hidden }));
|
|
86
|
-
}
|
|
87
|
-
});
|