@agent-link/server 0.1.24 → 0.1.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-link/server",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "AgentLink relay server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/web/app.js CHANGED
@@ -825,6 +825,12 @@ const App = {
825
825
  });
826
826
 
827
827
  // ── WebSocket ──
828
+ let reconnectAttempts = 0;
829
+ const MAX_RECONNECT_ATTEMPTS = 50;
830
+ const RECONNECT_BASE_DELAY = 1000;
831
+ const RECONNECT_MAX_DELAY = 15000;
832
+ let reconnectTimer = null;
833
+
828
834
  function connect() {
829
835
  const sid = getSessionId();
830
836
  if (!sid) {
@@ -833,12 +839,14 @@ const App = {
833
839
  return;
834
840
  }
835
841
  sessionId.value = sid;
842
+ status.value = 'Connecting...';
843
+ error.value = '';
836
844
 
837
845
  const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
838
846
  const wsUrl = `${protocol}//${window.location.host}/?type=web&sessionId=${sid}`;
839
847
  ws = new WebSocket(wsUrl);
840
848
 
841
- ws.onopen = () => { error.value = ''; };
849
+ ws.onopen = () => { error.value = ''; reconnectAttempts = 0; };
842
850
 
843
851
  ws.onmessage = (event) => {
844
852
  let msg;
@@ -1035,17 +1043,32 @@ const App = {
1035
1043
 
1036
1044
  ws.onclose = () => {
1037
1045
  sessionKey = null;
1038
- if (status.value === 'Connected' || status.value === 'Connecting...') {
1039
- status.value = 'Disconnected';
1040
- error.value = 'Connection to server lost.';
1041
- }
1046
+ const wasConnected = status.value === 'Connected' || status.value === 'Connecting...';
1042
1047
  isProcessing.value = false;
1043
1048
  isCompacting.value = false;
1049
+
1050
+ if (wasConnected || reconnectAttempts > 0) {
1051
+ scheduleReconnect();
1052
+ }
1044
1053
  };
1045
1054
 
1046
1055
  ws.onerror = () => {};
1047
1056
  }
1048
1057
 
1058
+ function scheduleReconnect() {
1059
+ if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
1060
+ status.value = 'Disconnected';
1061
+ error.value = 'Unable to reconnect. Please refresh the page.';
1062
+ return;
1063
+ }
1064
+ const delay = Math.min(RECONNECT_BASE_DELAY * Math.pow(1.5, reconnectAttempts), RECONNECT_MAX_DELAY);
1065
+ reconnectAttempts++;
1066
+ status.value = 'Reconnecting...';
1067
+ error.value = 'Connection lost. Reconnecting... (attempt ' + reconnectAttempts + ')';
1068
+ if (reconnectTimer) clearTimeout(reconnectTimer);
1069
+ reconnectTimer = setTimeout(() => { reconnectTimer = null; connect(); }, delay);
1070
+ }
1071
+
1049
1072
  function handleClaudeOutput(msg) {
1050
1073
  const data = msg.data;
1051
1074
  if (!data) return;
@@ -1111,7 +1134,7 @@ const App = {
1111
1134
  watch(messageCount, () => { nextTick(scheduleHighlight); });
1112
1135
 
1113
1136
  onMounted(() => { connect(); });
1114
- onUnmounted(() => { if (ws) ws.close(); });
1137
+ onUnmounted(() => { if (reconnectTimer) clearTimeout(reconnectTimer); if (ws) ws.close(); });
1115
1138
 
1116
1139
  return {
1117
1140
  status, agentName, hostname, workDir, sessionId, error,
@@ -1158,7 +1181,7 @@ const App = {
1158
1181
  </div>
1159
1182
  </header>
1160
1183
 
1161
- <div v-if="status === 'No Session' || (status !== 'Connected' && status !== 'Connecting...' && messages.length === 0)" class="center-card">
1184
+ <div v-if="status === 'No Session' || (status !== 'Connected' && status !== 'Connecting...' && status !== 'Reconnecting...' && messages.length === 0)" class="center-card">
1162
1185
  <div class="status-card">
1163
1186
  <p class="status">
1164
1187
  <span class="label">Status:</span>
package/web/style.css CHANGED
@@ -191,6 +191,11 @@ body {
191
191
  background: rgba(245, 158, 11, 0.1);
192
192
  }
193
193
 
194
+ .badge.reconnecting\.\.\. {
195
+ color: var(--warning);
196
+ background: rgba(245, 158, 11, 0.1);
197
+ }
198
+
194
199
  .badge.waiting {
195
200
  color: var(--warning);
196
201
  background: rgba(245, 158, 11, 0.1);