@mandujs/core 0.20.1 → 0.20.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/package.json
CHANGED
package/src/bundler/dev.ts
CHANGED
|
@@ -559,7 +559,7 @@ export function generateHMRClientScript(port: number): string {
|
|
|
559
559
|
|
|
560
560
|
function connect() {
|
|
561
561
|
try {
|
|
562
|
-
ws = new WebSocket('ws://
|
|
562
|
+
ws = new WebSocket('ws://' + window.location.hostname + ':' + HMR_PORT);
|
|
563
563
|
|
|
564
564
|
ws.onopen = function() {
|
|
565
565
|
console.log('[Mandu HMR] Connected');
|
|
@@ -85,12 +85,16 @@ export type MCPConnectionStatus =
|
|
|
85
85
|
// ============================================================================
|
|
86
86
|
|
|
87
87
|
const DEFAULT_OPTIONS: Required<MCPConnectorOptions> = {
|
|
88
|
-
|
|
88
|
+
// #176: 포트 하드코딩 제거 — 현재 페이지의 호스트/포트에서 자동 유추
|
|
89
|
+
serverUrl: typeof window !== 'undefined'
|
|
90
|
+
? `ws://${window.location.hostname}:${window.location.port}/mcp`
|
|
91
|
+
: 'ws://localhost:3333/mcp',
|
|
89
92
|
connectionTimeout: 5000,
|
|
90
93
|
requestTimeout: 30000,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
// #175: MCP 서버가 없을 수 있으므로 기본 비활성화
|
|
95
|
+
autoReconnect: false,
|
|
96
|
+
reconnectInterval: 1000,
|
|
97
|
+
maxReconnectAttempts: 3,
|
|
94
98
|
};
|
|
95
99
|
|
|
96
100
|
// ============================================================================
|
|
@@ -377,10 +381,11 @@ export class MCPConnector {
|
|
|
377
381
|
private handleDisconnect(): void {
|
|
378
382
|
this.ws = null;
|
|
379
383
|
|
|
380
|
-
|
|
384
|
+
// #175: handleConnectionError에서 이미 reconnect 예약한 경우 중복 방지
|
|
385
|
+
if (this.options.autoReconnect && this.status !== 'disconnected' && !this.reconnectTimer) {
|
|
381
386
|
this.setStatus('error');
|
|
382
387
|
this.scheduleReconnect();
|
|
383
|
-
} else {
|
|
388
|
+
} else if (!this.reconnectTimer) {
|
|
384
389
|
this.setStatus('disconnected');
|
|
385
390
|
}
|
|
386
391
|
}
|
|
@@ -389,12 +394,18 @@ export class MCPConnector {
|
|
|
389
394
|
console.warn('[Mandu Kitchen] MCP connection error:', error.message);
|
|
390
395
|
this.setStatus('error');
|
|
391
396
|
|
|
392
|
-
if (this.options.autoReconnect) {
|
|
397
|
+
if (this.options.autoReconnect && !this.reconnectTimer) {
|
|
393
398
|
this.scheduleReconnect();
|
|
394
399
|
}
|
|
395
400
|
}
|
|
396
401
|
|
|
397
402
|
private scheduleReconnect(): void {
|
|
403
|
+
// #175: 기존 타이머 취소 (중복 방지)
|
|
404
|
+
if (this.reconnectTimer) {
|
|
405
|
+
clearTimeout(this.reconnectTimer);
|
|
406
|
+
this.reconnectTimer = null;
|
|
407
|
+
}
|
|
408
|
+
|
|
398
409
|
if (this.reconnectAttempts >= this.options.maxReconnectAttempts) {
|
|
399
410
|
console.warn('[Mandu Kitchen] Max reconnection attempts reached');
|
|
400
411
|
this.setStatus('disconnected');
|
|
@@ -402,15 +413,21 @@ export class MCPConnector {
|
|
|
402
413
|
}
|
|
403
414
|
|
|
404
415
|
this.reconnectAttempts++;
|
|
416
|
+
// #175: exponential backoff (1s → 2s → 4s → ... → max 30s)
|
|
417
|
+
const delay = Math.min(
|
|
418
|
+
this.options.reconnectInterval * Math.pow(2, this.reconnectAttempts - 1),
|
|
419
|
+
30_000,
|
|
420
|
+
);
|
|
405
421
|
console.log(
|
|
406
|
-
`[Mandu Kitchen] Reconnecting in ${
|
|
422
|
+
`[Mandu Kitchen] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts}/${this.options.maxReconnectAttempts})`
|
|
407
423
|
);
|
|
408
424
|
|
|
409
425
|
this.reconnectTimer = setTimeout(() => {
|
|
426
|
+
this.reconnectTimer = null;
|
|
410
427
|
this.connect().catch(() => {
|
|
411
428
|
// 에러는 handleConnectionError에서 처리됨
|
|
412
429
|
});
|
|
413
|
-
},
|
|
430
|
+
}, delay);
|
|
414
431
|
}
|
|
415
432
|
|
|
416
433
|
private async sendRequest<T>(method: string, params: unknown): Promise<T> {
|
package/src/runtime/ssr.ts
CHANGED
|
@@ -372,7 +372,7 @@ window.__MANDU_HMR_PORT__ = ${hmrPort};
|
|
|
372
372
|
|
|
373
373
|
function connect() {
|
|
374
374
|
try {
|
|
375
|
-
ws = new WebSocket('ws://
|
|
375
|
+
ws = new WebSocket('ws://' + window.location.hostname + ':${hmrPort}');
|
|
376
376
|
ws.onopen = function() {
|
|
377
377
|
console.log('[Mandu HMR] Connected');
|
|
378
378
|
reconnectAttempts = 0;
|
|
@@ -618,7 +618,7 @@ window.__MANDU_HMR_PORT__ = ${hmrPort};
|
|
|
618
618
|
|
|
619
619
|
function connect() {
|
|
620
620
|
try {
|
|
621
|
-
ws = new WebSocket('ws://
|
|
621
|
+
ws = new WebSocket('ws://' + window.location.hostname + ':${hmrPort}');
|
|
622
622
|
ws.onopen = function() {
|
|
623
623
|
console.log('[Mandu HMR] Connected');
|
|
624
624
|
reconnectAttempts = 0;
|