satgate-proxy 0.1.0 → 0.2.0
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 +4 -1
- package/src/bridge.js +39 -6
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "satgate-proxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Budget-enforced MCP proxy — hard-cap your AI agent tool spend",
|
|
5
5
|
"bin": {
|
|
6
6
|
"satgate-proxy": "./bin/satgate-proxy.js"
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://satgate.io",
|
|
15
15
|
"author": "SatGate Inc.",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node --test test/"
|
|
18
|
+
},
|
|
16
19
|
"engines": {
|
|
17
20
|
"node": ">=18"
|
|
18
21
|
},
|
package/src/bridge.js
CHANGED
|
@@ -14,6 +14,12 @@ class Bridge {
|
|
|
14
14
|
this._buffer = '';
|
|
15
15
|
this._pendingRequests = new Map();
|
|
16
16
|
this._sseBuffer = '';
|
|
17
|
+
this._reconnectAttempts = 0;
|
|
18
|
+
this._maxReconnectAttempts = 10;
|
|
19
|
+
this._baseBackoff = 1000;
|
|
20
|
+
this._maxBackoff = 30000;
|
|
21
|
+
this._queue = [];
|
|
22
|
+
this._destroyed = false;
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
log(msg) {
|
|
@@ -69,6 +75,25 @@ class Bridge {
|
|
|
69
75
|
return headers;
|
|
70
76
|
}
|
|
71
77
|
|
|
78
|
+
_scheduleReconnect() {
|
|
79
|
+
if (this._destroyed) return;
|
|
80
|
+
this._reconnectAttempts++;
|
|
81
|
+
if (this._reconnectAttempts > this._maxReconnectAttempts) {
|
|
82
|
+
process.stderr.write(`[satgate-proxy] Max reconnection attempts (${this._maxReconnectAttempts}) exceeded, exiting\n`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const delay = Math.min(this._baseBackoff * Math.pow(2, this._reconnectAttempts - 1), this._maxBackoff);
|
|
88
|
+
process.stderr.write(`[satgate-proxy] Reconnecting (attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts}) in ${delay}ms\n`);
|
|
89
|
+
|
|
90
|
+
// Re-queue in-flight: clear endpoint so new messages queue
|
|
91
|
+
this._postEndpoint = null;
|
|
92
|
+
this._sseBuffer = '';
|
|
93
|
+
|
|
94
|
+
this._reconnectTimer = setTimeout(() => this._connectSSE(), delay);
|
|
95
|
+
}
|
|
96
|
+
|
|
72
97
|
_connectSSE() {
|
|
73
98
|
const url = this._buildUrl('/sse');
|
|
74
99
|
this.log(`Connecting SSE: ${url}`);
|
|
@@ -85,29 +110,30 @@ class Bridge {
|
|
|
85
110
|
res.on('data', (d) => body += d);
|
|
86
111
|
res.on('end', () => {
|
|
87
112
|
if (body) process.stderr.write(`Response: ${body}\n`);
|
|
88
|
-
|
|
113
|
+
this._scheduleReconnect();
|
|
89
114
|
});
|
|
90
115
|
return;
|
|
91
116
|
}
|
|
92
117
|
|
|
93
118
|
this.log('SSE connected');
|
|
119
|
+
this._reconnectAttempts = 0; // Reset backoff on success
|
|
94
120
|
this._sseRes = res;
|
|
95
121
|
res.setEncoding('utf8');
|
|
96
122
|
|
|
97
123
|
res.on('data', (chunk) => this._onSSEData(chunk));
|
|
98
124
|
res.on('end', () => {
|
|
99
|
-
this.log('SSE connection closed');
|
|
100
|
-
|
|
125
|
+
this.log('SSE connection closed by server');
|
|
126
|
+
this._scheduleReconnect();
|
|
101
127
|
});
|
|
102
128
|
res.on('error', (err) => {
|
|
103
129
|
process.stderr.write(`SSE error: ${err.message}\n`);
|
|
104
|
-
|
|
130
|
+
this._scheduleReconnect();
|
|
105
131
|
});
|
|
106
132
|
});
|
|
107
133
|
|
|
108
134
|
req.on('error', (err) => {
|
|
109
135
|
process.stderr.write(`SSE connection error: ${err.message}\n`);
|
|
110
|
-
|
|
136
|
+
this._scheduleReconnect();
|
|
111
137
|
});
|
|
112
138
|
|
|
113
139
|
this._sseReq = req;
|
|
@@ -247,9 +273,16 @@ class Bridge {
|
|
|
247
273
|
req.end();
|
|
248
274
|
}
|
|
249
275
|
|
|
276
|
+
destroy() {
|
|
277
|
+
this._destroyed = true;
|
|
278
|
+
if (this._reconnectTimer) clearTimeout(this._reconnectTimer);
|
|
279
|
+
if (this._sseReq) this._sseReq.destroy();
|
|
280
|
+
this._sseReq = null;
|
|
281
|
+
}
|
|
282
|
+
|
|
250
283
|
_cleanup() {
|
|
251
284
|
this.log('Shutting down');
|
|
252
|
-
|
|
285
|
+
this.destroy();
|
|
253
286
|
process.exit(0);
|
|
254
287
|
}
|
|
255
288
|
}
|
package/src/index.js
CHANGED
|
@@ -43,7 +43,7 @@ function parseArgs(argv) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function printUsage() {
|
|
46
|
-
process.stderr.write(`satgate-proxy v0.
|
|
46
|
+
process.stderr.write(`satgate-proxy v0.2.0 — Budget-enforced MCP proxy
|
|
47
47
|
|
|
48
48
|
USAGE:
|
|
49
49
|
npx satgate-proxy --server <package> [options]
|