@limrun/api 0.71.0 → 0.71.1
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 +26 -0
- package/exec-client.d.mts.map +1 -1
- package/exec-client.d.ts.map +1 -1
- package/exec-client.js +1 -5
- package/exec-client.js.map +1 -1
- package/exec-client.mjs +2 -6
- package/exec-client.mjs.map +1 -1
- package/index.d.mts +1 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/instance-client.d.mts +4 -3
- package/instance-client.d.mts.map +1 -1
- package/instance-client.d.ts +4 -3
- package/instance-client.d.ts.map +1 -1
- package/instance-client.js.map +1 -1
- package/instance-client.mjs.map +1 -1
- package/internal/session-stream.d.mts +25 -3
- package/internal/session-stream.d.mts.map +1 -1
- package/internal/session-stream.d.ts +25 -3
- package/internal/session-stream.d.ts.map +1 -1
- package/internal/session-stream.js +39 -5
- package/internal/session-stream.js.map +1 -1
- package/internal/session-stream.mjs +38 -5
- package/internal/session-stream.mjs.map +1 -1
- package/internal/sse-fetch.d.mts +5 -0
- package/internal/sse-fetch.d.mts.map +1 -1
- package/internal/sse-fetch.d.ts +5 -0
- package/internal/sse-fetch.d.ts.map +1 -1
- package/internal/sse-fetch.js +8 -0
- package/internal/sse-fetch.js.map +1 -1
- package/internal/sse-fetch.mjs +7 -0
- package/internal/sse-fetch.mjs.map +1 -1
- package/ios-client.d.mts +31 -7
- package/ios-client.d.mts.map +1 -1
- package/ios-client.d.ts +31 -7
- package/ios-client.d.ts.map +1 -1
- package/ios-client.js +17 -2
- package/ios-client.js.map +1 -1
- package/ios-client.mjs +16 -2
- package/ios-client.mjs.map +1 -1
- package/package.json +1 -1
- package/src/exec-client.ts +2 -8
- package/src/index.ts +1 -1
- package/src/instance-client.ts +4 -3
- package/src/internal/session-stream.ts +54 -7
- package/src/internal/sse-fetch.ts +8 -0
- package/src/ios-client.ts +46 -13
- 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
package/src/index.ts
CHANGED
|
@@ -164,7 +164,7 @@ export {
|
|
|
164
164
|
type PerformanceSample,
|
|
165
165
|
type PerformanceThread,
|
|
166
166
|
} from './resources/session-artifacts';
|
|
167
|
-
export { SessionStreamLostError } from './internal/session-stream';
|
|
167
|
+
export { SessionStreamLostError, SessionStreamRejectedError } from './internal/session-stream';
|
|
168
168
|
export {
|
|
169
169
|
LIMRUN_DIR,
|
|
170
170
|
TRY_IMPORT_LINE,
|
package/src/instance-client.ts
CHANGED
|
@@ -354,9 +354,10 @@ export type InstanceClient = {
|
|
|
354
354
|
* delivers lines as they are captured; a dropped connection reconnects
|
|
355
355
|
* and resumes exactly where it left off, so every line is delivered once.
|
|
356
356
|
* The stream is independent of this client's websocket and survives
|
|
357
|
-
* {@link disconnect}; `onError` fires at most once
|
|
358
|
-
*
|
|
359
|
-
*
|
|
357
|
+
* {@link disconnect}; `onError` fires at most once and the stream is
|
|
358
|
+
* closed: at once with a `SessionStreamRejectedError` when the
|
|
359
|
+
* instance refuses it (404 once the instance is gone), or after it has
|
|
360
|
+
* kept failing for several minutes. Returns a function that closes it.
|
|
360
361
|
*/
|
|
361
362
|
streamAppLogCapture: (handlers: {
|
|
362
363
|
onLine: (line: SessionLogLine) => void;
|
|
@@ -11,17 +11,40 @@
|
|
|
11
11
|
* instance) would otherwise retry silently for good. Proof of life — a
|
|
12
12
|
* delivered entry, a keepalive comment, or a clean connection that stays
|
|
13
13
|
* open healthyConnectionMs — resets the give-up clock; once the stream stays
|
|
14
|
-
* broken past giveUpAfterMs, onError fires once and the stream closes.
|
|
14
|
+
* broken past giveUpAfterMs, onError fires once and the stream closes. Like
|
|
15
|
+
* the exec client, a client error other than 408 and 429, or a 204, closes it
|
|
16
|
+
* at once: the router answers 404 for a missing or terminating instance and
|
|
17
|
+
* 403 for a token that does not match, and a runtime answers 404 for a stream
|
|
18
|
+
* it does not serve.
|
|
15
19
|
*/
|
|
16
20
|
|
|
17
21
|
import { createEventSource, type EventSourceMessage } from 'eventsource-client';
|
|
18
22
|
import { sseStreamPolicy } from '../exec-client';
|
|
19
23
|
import { nodeProxyTransport } from './proxy-transport';
|
|
20
|
-
import { sseFetch } from './sse-fetch';
|
|
24
|
+
import { refusesStream, sseFetch } from './sse-fetch';
|
|
21
25
|
import type { Fetch } from './builtin-types';
|
|
22
26
|
|
|
23
|
-
/** The session stream
|
|
24
|
-
export class SessionStreamLostError extends Error {
|
|
27
|
+
/** The session stream failed for good and has been closed. */
|
|
28
|
+
export class SessionStreamLostError extends Error {
|
|
29
|
+
override name = 'SessionStreamLostError';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The session stream was refused with `status` and has been closed. A 404 means the instance is
|
|
34
|
+
* gone or terminating, or its runtime predates the stream.
|
|
35
|
+
*/
|
|
36
|
+
export class SessionStreamRejectedError extends SessionStreamLostError {
|
|
37
|
+
override name = 'SessionStreamRejectedError';
|
|
38
|
+
constructor(
|
|
39
|
+
message: string,
|
|
40
|
+
readonly status: number,
|
|
41
|
+
) {
|
|
42
|
+
super(message);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The SSE event the iOS runtime sends after replaying its buffer. */
|
|
47
|
+
const REPLAYED_EVENT = 'replayed';
|
|
25
48
|
|
|
26
49
|
export interface SessionStreamOptions<T extends { ts: number }> {
|
|
27
50
|
/** Full URL of the runtime SSE endpoint, without credentials. */
|
|
@@ -30,7 +53,15 @@ export interface SessionStreamOptions<T extends { ts: number }> {
|
|
|
30
53
|
token: string;
|
|
31
54
|
/** Called once per delivered entry, in stream order. */
|
|
32
55
|
onEntry: (entry: T) => void;
|
|
33
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Called after each connection's replay, the first and every reconnect, so later entries are
|
|
58
|
+
* live. Android and older iOS runtimes never call it.
|
|
59
|
+
*/
|
|
60
|
+
onReplayed?: (() => void) | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Called at most once, when the stream closes for good: at once on a refusal, or after the
|
|
63
|
+
* give-up window when it stays unreachable.
|
|
64
|
+
*/
|
|
34
65
|
onError?: ((error: Error) => void) | undefined;
|
|
35
66
|
}
|
|
36
67
|
|
|
@@ -65,8 +96,18 @@ export function streamSessionEntries<T extends { ts: number }>(options: SessionS
|
|
|
65
96
|
// transient refusal does not kill a live stream.
|
|
66
97
|
const fetchWithStreamPolicy: Fetch = async (input, init) => {
|
|
67
98
|
const response = await nodeProxyTransport.fetch(input, init);
|
|
68
|
-
|
|
69
|
-
|
|
99
|
+
const status = response.status;
|
|
100
|
+
if (refusesStream(status)) {
|
|
101
|
+
const reason =
|
|
102
|
+
status === 404 ? ': the instance no longer exists, or its runtime does not serve this stream' : '';
|
|
103
|
+
fail(
|
|
104
|
+
new SessionStreamRejectedError(
|
|
105
|
+
`session stream to ${options.url} answered HTTP ${status}${reason}`,
|
|
106
|
+
status,
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
} else if (!response.ok) {
|
|
110
|
+
lastStreamError = new Error(`server answered HTTP ${status}`);
|
|
70
111
|
}
|
|
71
112
|
cleanResponseThisCycle = response.ok;
|
|
72
113
|
return response;
|
|
@@ -133,9 +174,15 @@ export function streamSessionEntries<T extends { ts: number }>(options: SessionS
|
|
|
133
174
|
}
|
|
134
175
|
},
|
|
135
176
|
onMessage: (message: EventSourceMessage) => {
|
|
177
|
+
// A closed stream can still hand over the rest of the chunk it was parsing.
|
|
178
|
+
if (closed) return;
|
|
136
179
|
deadSince = 0;
|
|
137
180
|
proofOfLifeThisCycle = true;
|
|
138
181
|
lastStreamError = undefined;
|
|
182
|
+
if (message.event === REPLAYED_EVENT) {
|
|
183
|
+
options.onReplayed?.();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
139
186
|
const data = typeof message.data === 'string' ? message.data : String(message.data ?? '');
|
|
140
187
|
let parsed: unknown;
|
|
141
188
|
try {
|
|
@@ -18,3 +18,11 @@ export function sseFetch(fetchImpl: Fetch, onRejected: (err: unknown) => void):
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Whether an SSE response refuses the stream for good: a 204, which makes the EventSource close
|
|
24
|
+
* without reporting it, or a client error other than 408 and 429, which retrying cannot fix.
|
|
25
|
+
*/
|
|
26
|
+
export function refusesStream(status: number): boolean {
|
|
27
|
+
return status === 204 || (status >= 400 && status < 500 && status !== 408 && status !== 429);
|
|
28
|
+
}
|
package/src/ios-client.ts
CHANGED
|
@@ -1069,9 +1069,10 @@ export type InstanceClient = {
|
|
|
1069
1069
|
* delivers lines as they are captured; a dropped connection reconnects
|
|
1070
1070
|
* and resumes exactly where it left off, so every line is delivered once.
|
|
1071
1071
|
* The stream is independent of this client's websocket and survives
|
|
1072
|
-
* {@link disconnect}; `onError` fires at most once
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1072
|
+
* {@link disconnect}; `onError` fires at most once and the stream is
|
|
1073
|
+
* closed: at once with a `SessionStreamRejectedError` when the
|
|
1074
|
+
* instance refuses it (404 once the instance is gone), or after it has
|
|
1075
|
+
* kept failing for several minutes. Returns a function that closes it.
|
|
1075
1076
|
*/
|
|
1076
1077
|
streamAppLogCapture: (handlers: {
|
|
1077
1078
|
onLine: (line: SessionLogLine) => void;
|
|
@@ -1107,10 +1108,7 @@ export type InstanceClient = {
|
|
|
1107
1108
|
* {@link streamAppLogCapture}, except that a gap longer than the replay
|
|
1108
1109
|
* window loses the samples in between.
|
|
1109
1110
|
*/
|
|
1110
|
-
streamPerformance: (handlers:
|
|
1111
|
-
onSample: (sample: PerformanceSample) => void;
|
|
1112
|
-
onError?: (error: Error) => void;
|
|
1113
|
-
}) => () => void;
|
|
1111
|
+
streamPerformance: (handlers: PerformanceStreamHandlers) => () => void;
|
|
1114
1112
|
|
|
1115
1113
|
/**
|
|
1116
1114
|
* Play an audio file as the simulator's microphone input. Stage the file on
|
|
@@ -1795,6 +1793,43 @@ export class SimctlExecution extends EventEmitter {
|
|
|
1795
1793
|
}
|
|
1796
1794
|
}
|
|
1797
1795
|
|
|
1796
|
+
export type PerformanceStreamOptions = {
|
|
1797
|
+
/** The instance's status.apiUrl. */
|
|
1798
|
+
apiUrl: string;
|
|
1799
|
+
/** The instance token. */
|
|
1800
|
+
token: string;
|
|
1801
|
+
onSample: (sample: PerformanceSample) => void;
|
|
1802
|
+
/**
|
|
1803
|
+
* Called after each connection's replay of recent samples, the first and every reconnect, so
|
|
1804
|
+
* later samples are live. Runtimes that predate the signal never call it.
|
|
1805
|
+
*/
|
|
1806
|
+
onReplayed?: (() => void) | undefined;
|
|
1807
|
+
/**
|
|
1808
|
+
* Called at most once, when the stream closes for good: at once with a
|
|
1809
|
+
* SessionStreamRejectedError (status 404 when the instance is gone or its runtime
|
|
1810
|
+
* predates performance), or after the give-up window when it stays unreachable.
|
|
1811
|
+
*/
|
|
1812
|
+
onError?: ((error: Error) => void) | undefined;
|
|
1813
|
+
};
|
|
1814
|
+
|
|
1815
|
+
/** What a performance stream reports to, without the instance's address. */
|
|
1816
|
+
export type PerformanceStreamHandlers = Omit<PerformanceStreamOptions, 'apiUrl' | 'token'>;
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* Tails the running apps' {@link PerformanceSample}s with only the instance's apiUrl and token,
|
|
1820
|
+
* without the WebSocket an {@link InstanceClient} opens. On connect the instance replays its
|
|
1821
|
+
* recent samples, then sends new ones; call the returned function to stop.
|
|
1822
|
+
*/
|
|
1823
|
+
export function streamPerformance(options: PerformanceStreamOptions): () => void {
|
|
1824
|
+
return streamSessionEntries<PerformanceSample>({
|
|
1825
|
+
url: `${options.apiUrl}/session/performance/events`,
|
|
1826
|
+
token: options.token,
|
|
1827
|
+
onEntry: options.onSample,
|
|
1828
|
+
onReplayed: options.onReplayed,
|
|
1829
|
+
onError: options.onError,
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1798
1833
|
/**
|
|
1799
1834
|
* Creates a client for interacting with a Limrun iOS instance
|
|
1800
1835
|
* @param options Configuration options including webrtcUrl, token and log level
|
|
@@ -2378,7 +2413,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2378
2413
|
streamEventCapture,
|
|
2379
2414
|
startPerformanceCapture,
|
|
2380
2415
|
stopPerformanceCapture,
|
|
2381
|
-
streamPerformance,
|
|
2416
|
+
streamPerformance: streamClientPerformance,
|
|
2382
2417
|
playOnMicrophone,
|
|
2383
2418
|
stopMicrophonePlayback,
|
|
2384
2419
|
microphoneStatus,
|
|
@@ -2926,7 +2961,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2926
2961
|
};
|
|
2927
2962
|
|
|
2928
2963
|
const tailSession = <T extends { ts: number }>(
|
|
2929
|
-
stream: 'applogs' | 'events'
|
|
2964
|
+
stream: 'applogs' | 'events',
|
|
2930
2965
|
onEntry: (entry: T) => void,
|
|
2931
2966
|
onError?: (error: Error) => void,
|
|
2932
2967
|
): (() => void) =>
|
|
@@ -2947,10 +2982,8 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2947
2982
|
onError?: (error: Error) => void;
|
|
2948
2983
|
}): (() => void) => tailSession('events', handlers.onEvent, handlers.onError);
|
|
2949
2984
|
|
|
2950
|
-
const
|
|
2951
|
-
|
|
2952
|
-
onError?: (error: Error) => void;
|
|
2953
|
-
}): (() => void) => tailSession('performance', handlers.onSample, handlers.onError);
|
|
2985
|
+
const streamClientPerformance = (handlers: PerformanceStreamHandlers): (() => void) =>
|
|
2986
|
+
streamPerformance({ ...handlers, apiUrl: options.apiUrl, token: options.token });
|
|
2954
2987
|
|
|
2955
2988
|
const stopRecording = async (saveTo: { presignedUrl?: string; localPath?: string }): Promise<string> => {
|
|
2956
2989
|
await sendRequest<void>('stopVideoRecording', {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.71.
|
|
1
|
+
export const VERSION = '0.71.1'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.71.
|
|
1
|
+
export declare const VERSION = "0.71.1";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.71.
|
|
1
|
+
export declare const VERSION = "0.71.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.71.
|
|
1
|
+
export const VERSION = '0.71.1'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|