@limrun/api 0.48.3 → 0.49.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/CHANGELOG.md +8 -0
- package/client.d.mts +6 -3
- package/client.d.mts.map +1 -1
- package/client.d.ts +6 -3
- package/client.d.ts.map +1 -1
- package/client.js +4 -4
- package/client.js.map +1 -1
- package/client.mjs +2 -2
- package/client.mjs.map +1 -1
- package/destination-tunnel-dialer.d.mts +30 -2
- package/destination-tunnel-dialer.d.mts.map +1 -1
- package/destination-tunnel-dialer.d.ts +30 -2
- package/destination-tunnel-dialer.d.ts.map +1 -1
- package/destination-tunnel-dialer.js +349 -65
- package/destination-tunnel-dialer.js.map +1 -1
- package/destination-tunnel-dialer.mjs +345 -64
- package/destination-tunnel-dialer.mjs.map +1 -1
- package/destination-tunnel-har.d.mts +23 -0
- package/destination-tunnel-har.d.mts.map +1 -0
- package/destination-tunnel-har.d.ts +23 -0
- package/destination-tunnel-har.d.ts.map +1 -0
- package/destination-tunnel-har.js +164 -0
- package/destination-tunnel-har.js.map +1 -0
- package/destination-tunnel-har.mjs +160 -0
- package/destination-tunnel-har.mjs.map +1 -0
- package/destination-tunnel-inspection.d.mts +71 -0
- package/destination-tunnel-inspection.d.mts.map +1 -0
- package/destination-tunnel-inspection.d.ts +71 -0
- package/destination-tunnel-inspection.d.ts.map +1 -0
- package/destination-tunnel-inspection.js +267 -0
- package/destination-tunnel-inspection.js.map +1 -0
- package/destination-tunnel-inspection.mjs +261 -0
- package/destination-tunnel-inspection.mjs.map +1 -0
- package/destination-tunnel.d.mts +119 -14
- package/destination-tunnel.d.mts.map +1 -1
- package/destination-tunnel.d.ts +119 -14
- package/destination-tunnel.d.ts.map +1 -1
- package/destination-tunnel.js +407 -98
- package/destination-tunnel.js.map +1 -1
- package/destination-tunnel.mjs +374 -73
- package/destination-tunnel.mjs.map +1 -1
- package/exec-client.d.mts +1 -0
- package/exec-client.d.mts.map +1 -1
- package/exec-client.d.ts +1 -0
- package/exec-client.d.ts.map +1 -1
- package/exec-client.js.map +1 -1
- package/exec-client.mjs.map +1 -1
- package/index.d.mts +6 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -1
- package/index.js +23 -2
- package/index.js.map +1 -1
- package/index.mjs +5 -0
- package/index.mjs.map +1 -1
- package/instance-client.d.mts +105 -1
- package/instance-client.d.mts.map +1 -1
- package/instance-client.d.ts +105 -1
- package/instance-client.d.ts.map +1 -1
- package/instance-client.js +83 -1
- package/instance-client.js.map +1 -1
- package/instance-client.mjs +83 -1
- package/instance-client.mjs.map +1 -1
- package/internal/destination-tunnel-management.d.mts +4 -3
- package/internal/destination-tunnel-management.d.mts.map +1 -1
- package/internal/destination-tunnel-management.d.ts +4 -3
- package/internal/destination-tunnel-management.d.ts.map +1 -1
- package/internal/destination-tunnel-management.js +64 -46
- package/internal/destination-tunnel-management.js.map +1 -1
- package/internal/destination-tunnel-management.mjs +55 -37
- package/internal/destination-tunnel-management.mjs.map +1 -1
- package/internal/destination-tunnel-url.d.mts +2 -0
- package/internal/destination-tunnel-url.d.mts.map +1 -1
- package/internal/destination-tunnel-url.d.ts +2 -0
- package/internal/destination-tunnel-url.d.ts.map +1 -1
- package/internal/destination-tunnel-url.js +45 -5
- package/internal/destination-tunnel-url.js.map +1 -1
- package/internal/destination-tunnel-url.mjs +44 -5
- package/internal/destination-tunnel-url.mjs.map +1 -1
- package/internal/destination-tunnel-wire-reader.d.mts +23 -0
- package/internal/destination-tunnel-wire-reader.d.mts.map +1 -0
- package/internal/destination-tunnel-wire-reader.d.ts +23 -0
- package/internal/destination-tunnel-wire-reader.d.ts.map +1 -0
- package/internal/destination-tunnel-wire-reader.js +110 -0
- package/internal/destination-tunnel-wire-reader.js.map +1 -0
- package/internal/destination-tunnel-wire-reader.mjs +93 -0
- package/internal/destination-tunnel-wire-reader.mjs.map +1 -0
- package/internal/persist-option.d.mts +14 -0
- package/internal/persist-option.d.mts.map +1 -0
- package/internal/persist-option.d.ts +14 -0
- package/internal/persist-option.d.ts.map +1 -0
- package/internal/persist-option.js +18 -0
- package/internal/persist-option.js.map +1 -0
- package/internal/persist-option.mjs +15 -0
- package/internal/persist-option.mjs.map +1 -0
- package/internal/proxy-transport.d.mts +27 -0
- package/internal/proxy-transport.d.mts.map +1 -1
- package/internal/proxy-transport.d.ts +27 -0
- package/internal/proxy-transport.d.ts.map +1 -1
- package/internal/proxy-transport.js +206 -0
- package/internal/proxy-transport.js.map +1 -1
- package/internal/proxy-transport.mjs +205 -0
- package/internal/proxy-transport.mjs.map +1 -1
- package/internal/session-stream.d.mts +39 -0
- package/internal/session-stream.d.mts.map +1 -0
- package/internal/session-stream.d.ts +39 -0
- package/internal/session-stream.d.ts.map +1 -0
- package/internal/session-stream.js +144 -0
- package/internal/session-stream.js.map +1 -0
- package/internal/session-stream.mjs +139 -0
- package/internal/session-stream.mjs.map +1 -0
- package/internal/tslib.js +4 -4
- package/ios-client.d.mts +61 -4
- package/ios-client.d.mts.map +1 -1
- package/ios-client.d.ts +61 -4
- package/ios-client.d.ts.map +1 -1
- package/ios-client.js +48 -2
- package/ios-client.js.map +1 -1
- package/ios-client.mjs +48 -2
- package/ios-client.mjs.map +1 -1
- package/package.json +22 -1
- package/resources/android-instances-helpers.d.mts +25 -0
- package/resources/android-instances-helpers.d.mts.map +1 -0
- package/resources/android-instances-helpers.d.ts +25 -0
- package/resources/android-instances-helpers.d.ts.map +1 -0
- package/resources/android-instances-helpers.js +37 -0
- package/resources/android-instances-helpers.js.map +1 -0
- package/resources/android-instances-helpers.mjs +33 -0
- package/resources/android-instances-helpers.mjs.map +1 -0
- package/resources/index.d.mts +5 -2
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +5 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -5
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -2
- package/resources/index.mjs.map +1 -1
- package/resources/ios-instances-helpers.d.mts +25 -0
- package/resources/ios-instances-helpers.d.mts.map +1 -0
- package/resources/ios-instances-helpers.d.ts +25 -0
- package/resources/ios-instances-helpers.d.ts.map +1 -0
- package/resources/ios-instances-helpers.js +37 -0
- package/resources/ios-instances-helpers.js.map +1 -0
- package/resources/ios-instances-helpers.mjs +33 -0
- package/resources/ios-instances-helpers.mjs.map +1 -0
- package/resources/session-artifacts.d.mts +70 -0
- package/resources/session-artifacts.d.mts.map +1 -0
- package/resources/session-artifacts.d.ts +70 -0
- package/resources/session-artifacts.d.ts.map +1 -0
- package/resources/session-artifacts.js +8 -0
- package/resources/session-artifacts.js.map +1 -0
- package/resources/session-artifacts.mjs +7 -0
- package/resources/session-artifacts.mjs.map +1 -0
- package/resources/xcode-instances-helpers.d.mts +9 -0
- package/resources/xcode-instances-helpers.d.mts.map +1 -1
- package/resources/xcode-instances-helpers.d.ts +9 -0
- package/resources/xcode-instances-helpers.d.ts.map +1 -1
- package/resources/xcode-instances-helpers.js.map +1 -1
- package/resources/xcode-instances-helpers.mjs.map +1 -1
- package/src/client.ts +4 -2
- package/src/destination-tunnel-dialer.ts +403 -64
- package/src/destination-tunnel-har.ts +200 -0
- package/src/destination-tunnel-inspection.ts +367 -0
- package/src/destination-tunnel.ts +510 -88
- package/src/exec-client.ts +1 -0
- package/src/index.ts +52 -0
- package/src/instance-client.ts +271 -5
- package/src/internal/destination-tunnel-management.ts +67 -43
- package/src/internal/destination-tunnel-url.ts +61 -5
- package/src/internal/destination-tunnel-wire-reader.ts +109 -0
- package/src/internal/persist-option.ts +26 -0
- package/src/internal/proxy-transport.ts +248 -0
- package/src/internal/session-stream.ts +157 -0
- package/src/ios-client.ts +127 -8
- package/src/resources/android-instances-helpers.ts +45 -0
- package/src/resources/index.ts +9 -2
- package/src/resources/ios-instances-helpers.ts +45 -0
- package/src/resources/session-artifacts.ts +95 -0
- package/src/resources/xcode-instances-helpers.ts +9 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import net from 'net';
|
|
2
|
+
import tls from 'tls';
|
|
1
3
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
2
4
|
import { getProxyForUrl } from 'proxy-from-env';
|
|
3
5
|
import { EnvHttpProxyAgent } from 'undici';
|
|
@@ -6,6 +8,7 @@ import { EnvHttpProxyAgent } from 'undici';
|
|
|
6
8
|
// the first to give up. undici's defaults are 300s, which would abort e.g. an
|
|
7
9
|
// instance-side artifact upload that takes longer.
|
|
8
10
|
const longRequestTimeouts = { headersTimeout: 3600000, bodyTimeout: 3600000 };
|
|
11
|
+
const maxConnectResponseHeaderBytes = 64 * 1024;
|
|
9
12
|
class NodeProxyTransport {
|
|
10
13
|
constructor() {
|
|
11
14
|
this.websocketAgents = new Map();
|
|
@@ -49,6 +52,20 @@ class NodeProxyTransport {
|
|
|
49
52
|
}
|
|
50
53
|
return agent;
|
|
51
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Opens a paused TCP stream to a destination, tunneling through the proxy
|
|
57
|
+
* selected by proxy-from-env when applicable. The caller owns the returned
|
|
58
|
+
* socket and must resume it after installing data/end/error handlers.
|
|
59
|
+
*/
|
|
60
|
+
connectTcp(options) {
|
|
61
|
+
const lookupHost = options.proxyLookupHost ?? options.host;
|
|
62
|
+
const lookupUrl = `${options.proxyLookupProtocol}//${formatAuthority(lookupHost, options.port)}`;
|
|
63
|
+
const proxyUrl = getProxyForUrl(lookupUrl);
|
|
64
|
+
if (!proxyUrl) {
|
|
65
|
+
return connectDirect(options);
|
|
66
|
+
}
|
|
67
|
+
return connectThroughProxy(proxyUrl, options);
|
|
68
|
+
}
|
|
52
69
|
getEnvHttpProxyAgent() {
|
|
53
70
|
this.envHttpProxyAgent ?? (this.envHttpProxyAgent = new EnvHttpProxyAgent());
|
|
54
71
|
return this.envHttpProxyAgent;
|
|
@@ -72,4 +89,192 @@ class NodeProxyTransport {
|
|
|
72
89
|
}
|
|
73
90
|
}
|
|
74
91
|
export const nodeProxyTransport = new NodeProxyTransport();
|
|
92
|
+
function connectDirect(options) {
|
|
93
|
+
const startedAt = Date.now();
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
let settled = false;
|
|
96
|
+
const socket = net.createConnection({
|
|
97
|
+
host: options.host,
|
|
98
|
+
port: options.port,
|
|
99
|
+
allowHalfOpen: true,
|
|
100
|
+
});
|
|
101
|
+
const timer = setTimeout(() => {
|
|
102
|
+
fail(codedError(`connection to ${formatAuthority(options.host, options.port)} timed out`, 'ETIMEDOUT'));
|
|
103
|
+
}, options.timeoutMs);
|
|
104
|
+
timer.unref();
|
|
105
|
+
const cleanup = () => {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
socket.removeListener('connect', onConnect);
|
|
108
|
+
socket.removeListener('error', fail);
|
|
109
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
110
|
+
};
|
|
111
|
+
const fail = (error) => {
|
|
112
|
+
if (settled)
|
|
113
|
+
return;
|
|
114
|
+
settled = true;
|
|
115
|
+
cleanup();
|
|
116
|
+
socket.destroy();
|
|
117
|
+
reject(error);
|
|
118
|
+
};
|
|
119
|
+
const onAbort = () => fail(codedError('TCP connection cancelled', 'ECANCELED'));
|
|
120
|
+
const onConnect = () => {
|
|
121
|
+
if (settled)
|
|
122
|
+
return;
|
|
123
|
+
settled = true;
|
|
124
|
+
socket.pause();
|
|
125
|
+
cleanup();
|
|
126
|
+
resolve({
|
|
127
|
+
socket,
|
|
128
|
+
connectMs: Date.now() - startedAt,
|
|
129
|
+
...(socket.remoteAddress === undefined ? {} : { remoteAddress: socket.remoteAddress }),
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
socket.once('connect', onConnect);
|
|
133
|
+
socket.once('error', fail);
|
|
134
|
+
if (options.signal?.aborted) {
|
|
135
|
+
onAbort();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function connectThroughProxy(proxyUrlString, options) {
|
|
143
|
+
const startedAt = Date.now();
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
let settled = false;
|
|
146
|
+
let response = Buffer.alloc(0);
|
|
147
|
+
let proxyUrl;
|
|
148
|
+
try {
|
|
149
|
+
proxyUrl = new URL(proxyUrlString);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
reject(codedError(`invalid proxy URL: ${proxyUrlString}`, 'EPROXY'));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (proxyUrl.protocol !== 'http:' && proxyUrl.protocol !== 'https:') {
|
|
156
|
+
reject(codedError(`unsupported proxy protocol ${proxyUrl.protocol}`, 'EPROXY'));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const proxyPort = proxyUrl.port ? Number(proxyUrl.port)
|
|
160
|
+
: proxyUrl.protocol === 'https:' ? 443
|
|
161
|
+
: 80;
|
|
162
|
+
const proxyHost = unbracketHost(proxyUrl.hostname);
|
|
163
|
+
const socket = proxyUrl.protocol === 'https:' ?
|
|
164
|
+
tls.connect({
|
|
165
|
+
host: proxyHost,
|
|
166
|
+
port: proxyPort,
|
|
167
|
+
rejectUnauthorized: true,
|
|
168
|
+
...(net.isIP(proxyHost) ? {} : { servername: proxyHost }),
|
|
169
|
+
ALPNProtocols: ['http/1.1'],
|
|
170
|
+
})
|
|
171
|
+
: net.createConnection({
|
|
172
|
+
host: proxyHost,
|
|
173
|
+
port: proxyPort,
|
|
174
|
+
allowHalfOpen: true,
|
|
175
|
+
});
|
|
176
|
+
socket.allowHalfOpen = true;
|
|
177
|
+
const connectedEvent = proxyUrl.protocol === 'https:' ? 'secureConnect' : 'connect';
|
|
178
|
+
const timer = setTimeout(() => {
|
|
179
|
+
fail(codedError(`proxy connection to ${formatAuthority(options.host, options.port)} timed out`, 'ETIMEDOUT'));
|
|
180
|
+
}, options.timeoutMs);
|
|
181
|
+
timer.unref();
|
|
182
|
+
const cleanup = () => {
|
|
183
|
+
clearTimeout(timer);
|
|
184
|
+
socket.removeListener(connectedEvent, onProxyConnected);
|
|
185
|
+
socket.removeListener('data', onData);
|
|
186
|
+
socket.removeListener('end', onUnexpectedClose);
|
|
187
|
+
socket.removeListener('close', onUnexpectedClose);
|
|
188
|
+
socket.removeListener('error', fail);
|
|
189
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
190
|
+
};
|
|
191
|
+
const fail = (error) => {
|
|
192
|
+
if (settled)
|
|
193
|
+
return;
|
|
194
|
+
settled = true;
|
|
195
|
+
cleanup();
|
|
196
|
+
socket.destroy();
|
|
197
|
+
reject(error);
|
|
198
|
+
};
|
|
199
|
+
const onAbort = () => fail(codedError('proxy connection cancelled', 'ECANCELED'));
|
|
200
|
+
const onUnexpectedClose = () => fail(codedError('proxy closed before completing CONNECT', 'ECONNRESET'));
|
|
201
|
+
const onProxyConnected = () => {
|
|
202
|
+
const authority = formatAuthority(options.host, options.port);
|
|
203
|
+
const headers = [`CONNECT ${authority} HTTP/1.1`, `Host: ${authority}`, 'Proxy-Connection: Keep-Alive'];
|
|
204
|
+
if (proxyUrl.username || proxyUrl.password) {
|
|
205
|
+
const username = decodeUrlCredential(proxyUrl.username);
|
|
206
|
+
const password = decodeUrlCredential(proxyUrl.password);
|
|
207
|
+
headers.push(`Proxy-Authorization: Basic ${Buffer.from(`${username}:${password}`, 'utf8').toString('base64')}`);
|
|
208
|
+
}
|
|
209
|
+
socket.write(`${headers.join('\r\n')}\r\n\r\n`);
|
|
210
|
+
};
|
|
211
|
+
const onData = (chunk) => {
|
|
212
|
+
response = Buffer.concat([response, chunk]);
|
|
213
|
+
const headerEnd = response.indexOf('\r\n\r\n');
|
|
214
|
+
if (headerEnd < 0) {
|
|
215
|
+
if (response.length > maxConnectResponseHeaderBytes) {
|
|
216
|
+
fail(codedError('proxy CONNECT response headers exceeded 65536 bytes', 'EPROXY'));
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (headerEnd + 4 > maxConnectResponseHeaderBytes) {
|
|
221
|
+
fail(codedError('proxy CONNECT response headers exceeded 65536 bytes', 'EPROXY'));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const statusLineEnd = response.indexOf('\r\n');
|
|
225
|
+
const statusLine = response
|
|
226
|
+
.subarray(0, statusLineEnd < 0 ? headerEnd : statusLineEnd)
|
|
227
|
+
.toString('latin1');
|
|
228
|
+
const statusMatch = /^HTTP\/1\.[01] ([0-9]{3})(?: |$)/.exec(statusLine);
|
|
229
|
+
if (!statusMatch) {
|
|
230
|
+
fail(codedError(`invalid proxy CONNECT response: ${statusLine}`, 'EPROXY'));
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const statusCode = Number(statusMatch[1]);
|
|
234
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
235
|
+
fail(codedError(`proxy CONNECT failed with status ${statusCode}`, statusCode === 407 ? 'EPROXYAUTH' : 'EPROXYCONNECT'));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
settled = true;
|
|
239
|
+
socket.pause();
|
|
240
|
+
cleanup();
|
|
241
|
+
const remainder = response.subarray(headerEnd + 4);
|
|
242
|
+
if (remainder.length > 0)
|
|
243
|
+
socket.unshift(remainder);
|
|
244
|
+
resolve({
|
|
245
|
+
socket,
|
|
246
|
+
connectMs: Date.now() - startedAt,
|
|
247
|
+
remoteAddress: options.host,
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
socket.once(connectedEvent, onProxyConnected);
|
|
251
|
+
socket.on('data', onData);
|
|
252
|
+
socket.once('end', onUnexpectedClose);
|
|
253
|
+
socket.once('close', onUnexpectedClose);
|
|
254
|
+
socket.once('error', fail);
|
|
255
|
+
if (options.signal?.aborted) {
|
|
256
|
+
onAbort();
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function formatAuthority(host, port) {
|
|
264
|
+
return `${net.isIP(host) === 6 ? `[${host}]` : host}:${port}`;
|
|
265
|
+
}
|
|
266
|
+
function unbracketHost(host) {
|
|
267
|
+
return host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;
|
|
268
|
+
}
|
|
269
|
+
function decodeUrlCredential(value) {
|
|
270
|
+
try {
|
|
271
|
+
return decodeURIComponent(value);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function codedError(message, code) {
|
|
278
|
+
return Object.assign(new Error(message), { code });
|
|
279
|
+
}
|
|
75
280
|
//# sourceMappingURL=proxy-transport.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-transport.mjs","sourceRoot":"","sources":["../src/internal/proxy-transport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAI3C,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,mDAAmD;AACnD,MAAM,mBAAmB,GAAG,EAAE,cAAc,EAAE,OAAS,EAAE,WAAW,EAAE,OAAS,EAAE,CAAC;AAElF,MAAM,kBAAkB;IAAxB;QAGU,oBAAe,GAAG,IAAI,GAAG,EAAqB,CAAC;QAEvD,UAAK,GAAU,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACnC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC5B,CAAC;YAED,OAAQ,KAAa,CAAC,KAAK,E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AAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/E,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,OAAe,EAAE,IAAY;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Long-lived tail of a runtime session SSE stream (live app logs or the
|
|
3
|
+
* coalesced event log). The runtime replays its buffer on first connect and
|
|
4
|
+
* tags every entry with a monotonic SSE id; eventsource-client sends
|
|
5
|
+
* Last-Event-ID on reconnect, so the runtime resumes exactly where the
|
|
6
|
+
* stream broke and each entry is delivered exactly once.
|
|
7
|
+
*
|
|
8
|
+
* Stream health follows the exec client's model (and reuses its policy): the
|
|
9
|
+
* EventSource reconnects forever on its own, so a dead stream (deleted
|
|
10
|
+
* instance) would otherwise retry silently for good. Proof of life — a
|
|
11
|
+
* delivered entry, a keepalive comment, or a clean connection that stays
|
|
12
|
+
* open healthyConnectionMs — resets the give-up clock; once the stream stays
|
|
13
|
+
* broken past giveUpAfterMs, onError fires once and the stream closes.
|
|
14
|
+
*/
|
|
15
|
+
/** The session stream kept failing past the give-up window; it has been closed. */
|
|
16
|
+
export declare class SessionStreamLostError extends Error {
|
|
17
|
+
}
|
|
18
|
+
export interface SessionStreamOptions<T extends {
|
|
19
|
+
ts: number;
|
|
20
|
+
}> {
|
|
21
|
+
/** Full URL of the runtime SSE endpoint, without credentials. */
|
|
22
|
+
url: string;
|
|
23
|
+
/** Instance token; sent as a bearer Authorization header. */
|
|
24
|
+
token: string;
|
|
25
|
+
/** Called once per delivered entry, in stream order. */
|
|
26
|
+
onEntry: (entry: T) => void;
|
|
27
|
+
/** Called at most once, when the stream is given up on and closed. */
|
|
28
|
+
onError?: ((error: Error) => void) | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Connects to a session SSE endpoint and delivers parsed entries until the
|
|
32
|
+
* returned function is called (or the stream is given up on). Entries are
|
|
33
|
+
* one JSON object per SSE data frame; frames that do not parse to an object
|
|
34
|
+
* with a numeric `ts` are skipped.
|
|
35
|
+
*/
|
|
36
|
+
export declare function streamSessionEntries<T extends {
|
|
37
|
+
ts: number;
|
|
38
|
+
}>(options: SessionStreamOptions<T>): () => void;
|
|
39
|
+
//# sourceMappingURL=session-stream.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-stream.d.mts","sourceRoot":"","sources":["../src/internal/session-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,mFAAmF;AACnF,qBAAa,sBAAuB,SAAQ,KAAK;CAAG;AAEpD,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE;IAC5D,iEAAiE;IACjE,GAAG,EAAE,MAAM,CAAC;IACZ,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,sEAAsE;IACtE,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAChD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAmH3G"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Long-lived tail of a runtime session SSE stream (live app logs or the
|
|
3
|
+
* coalesced event log). The runtime replays its buffer on first connect and
|
|
4
|
+
* tags every entry with a monotonic SSE id; eventsource-client sends
|
|
5
|
+
* Last-Event-ID on reconnect, so the runtime resumes exactly where the
|
|
6
|
+
* stream broke and each entry is delivered exactly once.
|
|
7
|
+
*
|
|
8
|
+
* Stream health follows the exec client's model (and reuses its policy): the
|
|
9
|
+
* EventSource reconnects forever on its own, so a dead stream (deleted
|
|
10
|
+
* instance) would otherwise retry silently for good. Proof of life — a
|
|
11
|
+
* delivered entry, a keepalive comment, or a clean connection that stays
|
|
12
|
+
* open healthyConnectionMs — resets the give-up clock; once the stream stays
|
|
13
|
+
* broken past giveUpAfterMs, onError fires once and the stream closes.
|
|
14
|
+
*/
|
|
15
|
+
/** The session stream kept failing past the give-up window; it has been closed. */
|
|
16
|
+
export declare class SessionStreamLostError extends Error {
|
|
17
|
+
}
|
|
18
|
+
export interface SessionStreamOptions<T extends {
|
|
19
|
+
ts: number;
|
|
20
|
+
}> {
|
|
21
|
+
/** Full URL of the runtime SSE endpoint, without credentials. */
|
|
22
|
+
url: string;
|
|
23
|
+
/** Instance token; sent as a bearer Authorization header. */
|
|
24
|
+
token: string;
|
|
25
|
+
/** Called once per delivered entry, in stream order. */
|
|
26
|
+
onEntry: (entry: T) => void;
|
|
27
|
+
/** Called at most once, when the stream is given up on and closed. */
|
|
28
|
+
onError?: ((error: Error) => void) | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Connects to a session SSE endpoint and delivers parsed entries until the
|
|
32
|
+
* returned function is called (or the stream is given up on). Entries are
|
|
33
|
+
* one JSON object per SSE data frame; frames that do not parse to an object
|
|
34
|
+
* with a numeric `ts` are skipped.
|
|
35
|
+
*/
|
|
36
|
+
export declare function streamSessionEntries<T extends {
|
|
37
|
+
ts: number;
|
|
38
|
+
}>(options: SessionStreamOptions<T>): () => void;
|
|
39
|
+
//# sourceMappingURL=session-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-stream.d.ts","sourceRoot":"","sources":["../src/internal/session-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,mFAAmF;AACnF,qBAAa,sBAAuB,SAAQ,KAAK;CAAG;AAEpD,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE;IAC5D,iEAAiE;IACjE,GAAG,EAAE,MAAM,CAAC;IACZ,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,sEAAsE;IACtE,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAChD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAmH3G"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Long-lived tail of a runtime session SSE stream (live app logs or the
|
|
4
|
+
* coalesced event log). The runtime replays its buffer on first connect and
|
|
5
|
+
* tags every entry with a monotonic SSE id; eventsource-client sends
|
|
6
|
+
* Last-Event-ID on reconnect, so the runtime resumes exactly where the
|
|
7
|
+
* stream broke and each entry is delivered exactly once.
|
|
8
|
+
*
|
|
9
|
+
* Stream health follows the exec client's model (and reuses its policy): the
|
|
10
|
+
* EventSource reconnects forever on its own, so a dead stream (deleted
|
|
11
|
+
* instance) would otherwise retry silently for good. Proof of life — a
|
|
12
|
+
* delivered entry, a keepalive comment, or a clean connection that stays
|
|
13
|
+
* open healthyConnectionMs — resets the give-up clock; once the stream stays
|
|
14
|
+
* broken past giveUpAfterMs, onError fires once and the stream closes.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SessionStreamLostError = void 0;
|
|
18
|
+
exports.streamSessionEntries = streamSessionEntries;
|
|
19
|
+
const eventsource_client_1 = require("eventsource-client");
|
|
20
|
+
const exec_client_1 = require("../exec-client.js");
|
|
21
|
+
const proxy_transport_1 = require("./proxy-transport.js");
|
|
22
|
+
const sse_fetch_1 = require("./sse-fetch.js");
|
|
23
|
+
/** The session stream kept failing past the give-up window; it has been closed. */
|
|
24
|
+
class SessionStreamLostError extends Error {
|
|
25
|
+
}
|
|
26
|
+
exports.SessionStreamLostError = SessionStreamLostError;
|
|
27
|
+
/**
|
|
28
|
+
* Connects to a session SSE endpoint and delivers parsed entries until the
|
|
29
|
+
* returned function is called (or the stream is given up on). Entries are
|
|
30
|
+
* one JSON object per SSE data frame; frames that do not parse to an object
|
|
31
|
+
* with a numeric `ts` are skipped.
|
|
32
|
+
*/
|
|
33
|
+
function streamSessionEntries(options) {
|
|
34
|
+
let closed = false;
|
|
35
|
+
let connectedAt = 0;
|
|
36
|
+
let deadSince = 0;
|
|
37
|
+
let lastCycleAt = 0;
|
|
38
|
+
let lastCycleMono = 0;
|
|
39
|
+
let proofOfLifeThisCycle = false;
|
|
40
|
+
let cleanResponseThisCycle = false;
|
|
41
|
+
let lastStreamError;
|
|
42
|
+
const fail = (error) => {
|
|
43
|
+
if (closed)
|
|
44
|
+
return;
|
|
45
|
+
closed = true;
|
|
46
|
+
eventSource.close();
|
|
47
|
+
options.onError?.(error);
|
|
48
|
+
};
|
|
49
|
+
// Stream health is judged at the fetch surface, where the response status
|
|
50
|
+
// is visible; the library fires onConnect for error responses too, so an
|
|
51
|
+
// error page held open must not read as a healthy connection. A rejected
|
|
52
|
+
// fetch never reaches onDisconnect (the hazard sseFetch exists for):
|
|
53
|
+
// capture it for the give-up message and let the clock decide, so one
|
|
54
|
+
// transient refusal does not kill a live stream.
|
|
55
|
+
const fetchWithStreamPolicy = async (input, init) => {
|
|
56
|
+
const response = await proxy_transport_1.nodeProxyTransport.fetch(input, init);
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
lastStreamError = new Error(`server answered HTTP ${response.status}`);
|
|
59
|
+
}
|
|
60
|
+
cleanResponseThisCycle = response.ok;
|
|
61
|
+
return response;
|
|
62
|
+
};
|
|
63
|
+
const eventSource = (0, eventsource_client_1.createEventSource)({
|
|
64
|
+
url: options.url,
|
|
65
|
+
fetch: (0, sse_fetch_1.sseFetch)(fetchWithStreamPolicy, (err) => {
|
|
66
|
+
lastStreamError = err instanceof Error ? err : new Error(String(err));
|
|
67
|
+
}),
|
|
68
|
+
headers: { Authorization: `Bearer ${options.token}` },
|
|
69
|
+
onConnect: () => {
|
|
70
|
+
connectedAt = Date.now();
|
|
71
|
+
},
|
|
72
|
+
// Keepalive comments count as proof of life (onMessage never sees them).
|
|
73
|
+
onComment: () => {
|
|
74
|
+
proofOfLifeThisCycle = true;
|
|
75
|
+
},
|
|
76
|
+
// Fires once per broken cycle, before the retry timer is armed, on both
|
|
77
|
+
// failure paths (request rejected, stream ended). This is where the
|
|
78
|
+
// give-up clock runs.
|
|
79
|
+
onScheduleReconnect: () => {
|
|
80
|
+
if (closed)
|
|
81
|
+
return;
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
const mono = performance.now();
|
|
84
|
+
const livedMs = connectedAt > 0 ? now - connectedAt : 0;
|
|
85
|
+
connectedAt = 0;
|
|
86
|
+
// Date.now() is wall clock: a laptop waking from sleep (or a clock
|
|
87
|
+
// step) would arrive with the whole window already "elapsed" and fail
|
|
88
|
+
// on its first attempt. Sleep is the wall clock advancing while the
|
|
89
|
+
// monotonic clock stands still; a large drift between the two restarts
|
|
90
|
+
// the streak.
|
|
91
|
+
if (deadSince > 0 && lastCycleAt > 0) {
|
|
92
|
+
const wallGapMs = now - lastCycleAt;
|
|
93
|
+
const monoGapMs = mono - lastCycleMono;
|
|
94
|
+
if (wallGapMs - monoGapMs > 30000) {
|
|
95
|
+
deadSince = now;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
lastCycleAt = now;
|
|
99
|
+
lastCycleMono = mono;
|
|
100
|
+
const healthy = proofOfLifeThisCycle || (cleanResponseThisCycle && livedMs >= exec_client_1.sseStreamPolicy.healthyConnectionMs);
|
|
101
|
+
proofOfLifeThisCycle = false;
|
|
102
|
+
cleanResponseThisCycle = false;
|
|
103
|
+
if (healthy) {
|
|
104
|
+
deadSince = 0;
|
|
105
|
+
lastStreamError = undefined;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (deadSince === 0) {
|
|
109
|
+
deadSince = now;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (now - deadSince >= exec_client_1.sseStreamPolicy.giveUpAfterMs) {
|
|
113
|
+
const seconds = Math.round((now - deadSince) / 1000);
|
|
114
|
+
const cause = lastStreamError ? `; last error: ${lastStreamError.message}` : '';
|
|
115
|
+
fail(new SessionStreamLostError(`session stream to ${options.url} kept failing for ${seconds}s without delivering entries${cause}; ` +
|
|
116
|
+
'the instance may no longer exist'));
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
onMessage: (message) => {
|
|
120
|
+
deadSince = 0;
|
|
121
|
+
proofOfLifeThisCycle = true;
|
|
122
|
+
lastStreamError = undefined;
|
|
123
|
+
const data = typeof message.data === 'string' ? message.data : String(message.data ?? '');
|
|
124
|
+
let parsed;
|
|
125
|
+
try {
|
|
126
|
+
parsed = JSON.parse(data);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (typeof parsed?.ts !== 'number') {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
options.onEntry(parsed);
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return () => {
|
|
138
|
+
if (closed)
|
|
139
|
+
return;
|
|
140
|
+
closed = true;
|
|
141
|
+
eventSource.close();
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=session-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-stream.js","sourceRoot":"","sources":["../src/internal/session-stream.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AA4BH,oDAmHC;AA7ID,2DAAgF;AAChF,mDAAiD;AACjD,0DAAuD;AACvD,8CAAuC;AAGvC,mFAAmF;AACnF,MAAa,sBAAuB,SAAQ,KAAK;CAAG;AAApD,wDAAoD;AAapD;;;;;GAKG;AACH,SAAgB,oBAAoB,CAA2B,OAAgC;IAC7F,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,oBAAoB,GAAG,KAAK,CAAC;IACjC,IAAI,sBAAsB,GAAG,KAAK,CAAC;IACnC,IAAI,eAAkC,CAAC;IAEvC,MAAM,IAAI,GAAG,CAAC,KAAY,EAAE,EAAE;QAC5B,IAAI,MAAM;YAAE,OAAO;QACnB,MAAM,GAAG,IAAI,CAAC;QACd,WAAW,CAAC,KAAK,EAAE,CAAC;QACpB,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC,CAAC;IAEF,0EAA0E;IAC1E,yEAAyE;IACzE,yEAAyE;IACzE,qEAAqE;IACrE,sEAAsE;IACtE,iDAAiD;IACjD,MAAM,qBAAqB,GAAU,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACzD,MAAM,QAAQ,GAAG,MAAM,oCAAkB,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC7D,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,eAAe,GAAG,IAAI,KAAK,CAAC,wBAAwB,QAA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,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YAC1F,IAAI,MAAe,CAAC;YACpB,IAAI,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO;YACT,CAAC;YACD,IAAI,OAAQ,MAA2B,EAAE,EAAE,KAAK,QAAQ,EAAE,CAAC;gBACzD,OAAO;YACT,CAAC;YACD,OAAO,CAAC,OAAO,CAAC,MAAW,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE;QACV,IAAI,MAAM;YAAE,OAAO;QACnB,MAAM,GAAG,IAAI,CAAC;QACd,WAAW,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Long-lived tail of a runtime session SSE stream (live app logs or the
|
|
3
|
+
* coalesced event log). The runtime replays its buffer on first connect and
|
|
4
|
+
* tags every entry with a monotonic SSE id; eventsource-client sends
|
|
5
|
+
* Last-Event-ID on reconnect, so the runtime resumes exactly where the
|
|
6
|
+
* stream broke and each entry is delivered exactly once.
|
|
7
|
+
*
|
|
8
|
+
* Stream health follows the exec client's model (and reuses its policy): the
|
|
9
|
+
* EventSource reconnects forever on its own, so a dead stream (deleted
|
|
10
|
+
* instance) would otherwise retry silently for good. Proof of life — a
|
|
11
|
+
* delivered entry, a keepalive comment, or a clean connection that stays
|
|
12
|
+
* open healthyConnectionMs — resets the give-up clock; once the stream stays
|
|
13
|
+
* broken past giveUpAfterMs, onError fires once and the stream closes.
|
|
14
|
+
*/
|
|
15
|
+
import { createEventSource } from 'eventsource-client';
|
|
16
|
+
import { sseStreamPolicy } from "../exec-client.mjs";
|
|
17
|
+
import { nodeProxyTransport } from "./proxy-transport.mjs";
|
|
18
|
+
import { sseFetch } from "./sse-fetch.mjs";
|
|
19
|
+
/** The session stream kept failing past the give-up window; it has been closed. */
|
|
20
|
+
export class SessionStreamLostError extends Error {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Connects to a session SSE endpoint and delivers parsed entries until the
|
|
24
|
+
* returned function is called (or the stream is given up on). Entries are
|
|
25
|
+
* one JSON object per SSE data frame; frames that do not parse to an object
|
|
26
|
+
* with a numeric `ts` are skipped.
|
|
27
|
+
*/
|
|
28
|
+
export function streamSessionEntries(options) {
|
|
29
|
+
let closed = false;
|
|
30
|
+
let connectedAt = 0;
|
|
31
|
+
let deadSince = 0;
|
|
32
|
+
let lastCycleAt = 0;
|
|
33
|
+
let lastCycleMono = 0;
|
|
34
|
+
let proofOfLifeThisCycle = false;
|
|
35
|
+
let cleanResponseThisCycle = false;
|
|
36
|
+
let lastStreamError;
|
|
37
|
+
const fail = (error) => {
|
|
38
|
+
if (closed)
|
|
39
|
+
return;
|
|
40
|
+
closed = true;
|
|
41
|
+
eventSource.close();
|
|
42
|
+
options.onError?.(error);
|
|
43
|
+
};
|
|
44
|
+
// Stream health is judged at the fetch surface, where the response status
|
|
45
|
+
// is visible; the library fires onConnect for error responses too, so an
|
|
46
|
+
// error page held open must not read as a healthy connection. A rejected
|
|
47
|
+
// fetch never reaches onDisconnect (the hazard sseFetch exists for):
|
|
48
|
+
// capture it for the give-up message and let the clock decide, so one
|
|
49
|
+
// transient refusal does not kill a live stream.
|
|
50
|
+
const fetchWithStreamPolicy = async (input, init) => {
|
|
51
|
+
const response = await nodeProxyTransport.fetch(input, init);
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
lastStreamError = new Error(`server answered HTTP ${response.status}`);
|
|
54
|
+
}
|
|
55
|
+
cleanResponseThisCycle = response.ok;
|
|
56
|
+
return response;
|
|
57
|
+
};
|
|
58
|
+
const eventSource = createEventSource({
|
|
59
|
+
url: options.url,
|
|
60
|
+
fetch: sseFetch(fetchWithStreamPolicy, (err) => {
|
|
61
|
+
lastStreamError = err instanceof Error ? err : new Error(String(err));
|
|
62
|
+
}),
|
|
63
|
+
headers: { Authorization: `Bearer ${options.token}` },
|
|
64
|
+
onConnect: () => {
|
|
65
|
+
connectedAt = Date.now();
|
|
66
|
+
},
|
|
67
|
+
// Keepalive comments count as proof of life (onMessage never sees them).
|
|
68
|
+
onComment: () => {
|
|
69
|
+
proofOfLifeThisCycle = true;
|
|
70
|
+
},
|
|
71
|
+
// Fires once per broken cycle, before the retry timer is armed, on both
|
|
72
|
+
// failure paths (request rejected, stream ended). This is where the
|
|
73
|
+
// give-up clock runs.
|
|
74
|
+
onScheduleReconnect: () => {
|
|
75
|
+
if (closed)
|
|
76
|
+
return;
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
const mono = performance.now();
|
|
79
|
+
const livedMs = connectedAt > 0 ? now - connectedAt : 0;
|
|
80
|
+
connectedAt = 0;
|
|
81
|
+
// Date.now() is wall clock: a laptop waking from sleep (or a clock
|
|
82
|
+
// step) would arrive with the whole window already "elapsed" and fail
|
|
83
|
+
// on its first attempt. Sleep is the wall clock advancing while the
|
|
84
|
+
// monotonic clock stands still; a large drift between the two restarts
|
|
85
|
+
// the streak.
|
|
86
|
+
if (deadSince > 0 && lastCycleAt > 0) {
|
|
87
|
+
const wallGapMs = now - lastCycleAt;
|
|
88
|
+
const monoGapMs = mono - lastCycleMono;
|
|
89
|
+
if (wallGapMs - monoGapMs > 30000) {
|
|
90
|
+
deadSince = now;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
lastCycleAt = now;
|
|
94
|
+
lastCycleMono = mono;
|
|
95
|
+
const healthy = proofOfLifeThisCycle || (cleanResponseThisCycle && livedMs >= sseStreamPolicy.healthyConnectionMs);
|
|
96
|
+
proofOfLifeThisCycle = false;
|
|
97
|
+
cleanResponseThisCycle = false;
|
|
98
|
+
if (healthy) {
|
|
99
|
+
deadSince = 0;
|
|
100
|
+
lastStreamError = undefined;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (deadSince === 0) {
|
|
104
|
+
deadSince = now;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (now - deadSince >= sseStreamPolicy.giveUpAfterMs) {
|
|
108
|
+
const seconds = Math.round((now - deadSince) / 1000);
|
|
109
|
+
const cause = lastStreamError ? `; last error: ${lastStreamError.message}` : '';
|
|
110
|
+
fail(new SessionStreamLostError(`session stream to ${options.url} kept failing for ${seconds}s without delivering entries${cause}; ` +
|
|
111
|
+
'the instance may no longer exist'));
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
onMessage: (message) => {
|
|
115
|
+
deadSince = 0;
|
|
116
|
+
proofOfLifeThisCycle = true;
|
|
117
|
+
lastStreamError = undefined;
|
|
118
|
+
const data = typeof message.data === 'string' ? message.data : String(message.data ?? '');
|
|
119
|
+
let parsed;
|
|
120
|
+
try {
|
|
121
|
+
parsed = JSON.parse(data);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (typeof parsed?.ts !== 'number') {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
options.onEntry(parsed);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
return () => {
|
|
133
|
+
if (closed)
|
|
134
|
+
return;
|
|
135
|
+
closed = true;
|
|
136
|
+
eventSource.close();
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=session-stream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-stream.mjs","sourceRoot":"","sources":["../src/internal/session-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,iBAAiB,EAA2B,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,2BAAuB;AACjD,OAAO,EAAE,kBAAkB,EAAE,8BAA0B;AACvD,OAAO,EAAE,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