@opencode/client 2.0.7 → 2.0.9
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/dist/chunks/pty-handoff-1tbj6z39.js +81 -0
- package/dist/chunks/pty-handoff-4tveyqeh.js +34 -0
- package/dist/chunks/pty-handoff-65kht65h.js +62 -0
- package/dist/chunks/pty-handoff-6mptkzbc.js +0 -0
- package/dist/chunks/pty-handoff-9rqn6x4v.js +16 -0
- package/dist/chunks/pty-handoff-atpwm825.js +1638 -0
- package/dist/chunks/pty-handoff-bssvn03b.js +594 -0
- package/dist/chunks/pty-handoff-frbwqjmf.js +145 -0
- package/dist/chunks/pty-handoff-m2eywc8w.js +0 -0
- package/dist/chunks/pty-handoff-n3c99vt5.js +11 -0
- package/dist/chunks/pty-handoff-nqd0dnpk.js +112 -0
- package/dist/chunks/pty-handoff-qav6mfdz.js +0 -0
- package/dist/chunks/pty-handoff-radw39tv.js +1402 -0
- package/dist/chunks/pty-handoff-sxt88q69.js +12 -0
- package/dist/chunks/pty-handoff-t1xa31vm.js +39 -0
- package/dist/chunks/pty-handoff-txckps9j.js +57 -0
- package/dist/chunks/pty-handoff-vgxtr9hm.js +30 -0
- package/dist/chunks/pty-handoff-vmytr4q8.js +4 -0
- package/dist/chunks/pty-handoff-vyas3vgt.js +0 -0
- package/dist/chunks/pty-handoff-xgnj2w4v.js +20 -0
- package/dist/chunks/pty-handoff-y2etg5bs.js +9 -0
- package/dist/chunks/pty-handoff-ydhz1zrh.js +238 -0
- package/dist/chunks/pty-handoff-yepdgb80.js +44 -0
- package/dist/chunks/pty-handoff-zadn5mwr.js +52 -0
- package/dist/contract.js +12 -1
- package/dist/effect/client.d.ts +4 -4
- package/dist/effect/client.js +15 -29
- package/dist/effect/generated/client-error.js +6 -5
- package/dist/effect/generated/client.d.ts +4 -4
- package/dist/effect/generated/client.js +8 -582
- package/dist/effect/generated/index.js +12 -2
- package/dist/effect/index.js +75 -30
- package/dist/effect/rpc.js +11 -49
- package/dist/effect/service.js +238 -245
- package/dist/promise/client.js +14 -13
- package/dist/promise/generated/client-error.js +6 -8
- package/dist/promise/generated/client.js +7 -1396
- package/dist/promise/generated/index.js +75 -3
- package/dist/promise/generated/types.d.ts +91 -89
- package/dist/promise/generated/types.js +66 -34
- package/dist/promise/index.js +79 -2
- package/dist/promise/rpc.js +7 -86
- package/dist/promise/service.js +230 -227
- package/dist/pty-handoff.js +14 -121
- package/dist/rpc-runtime.js +14 -32
- package/dist/service-contender.js +10 -56
- package/dist/service-timing.d.ts +0 -1
- package/dist/service-timing.js +9 -18
- package/dist/service-version.js +6 -9
- package/dist/service.js +1 -0
- package/dist/shared-events.js +8 -137
- package/dist/solid/connection.js +10 -246
- package/dist/solid/data.js +18 -1769
- package/dist/solid/index.js +32 -3
- package/dist/solid/pty.js +8 -41
- package/package.json +4 -4
package/dist/rpc-runtime.js
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return read(method.errors[error.type], error.data).pipe(Effect.catch((cause) => Effect.die(cause)), Effect.flatMap((data) => Effect.fail(data === undefined
|
|
17
|
-
? { type: error.type, message: error.message }
|
|
18
|
-
: { type: error.type, message: error.message, data })));
|
|
19
|
-
}
|
|
20
|
-
export const event = Effect.fn("Client.Rpc.event")(function* (definition, name, schema, event) {
|
|
21
|
-
const data = yield* read(schema.schema, event.data);
|
|
22
|
-
// SAFETY: The event type was selected by the caller and data was decoded with this event's schema.
|
|
23
|
-
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
|
|
24
|
-
return {
|
|
25
|
-
...event,
|
|
26
|
-
type: eventType(definition, name),
|
|
27
|
-
data,
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
export function eventType(definition, name) {
|
|
31
|
-
return `rpc.${definition.id}.${name}`;
|
|
32
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
read2,
|
|
3
|
+
readError2,
|
|
4
|
+
event2,
|
|
5
|
+
eventType2,
|
|
6
|
+
exports_rpc_runtime
|
|
7
|
+
} from "./chunks/pty-handoff-t1xa31vm.js";
|
|
8
|
+
export {
|
|
9
|
+
exports_rpc_runtime as RpcRuntime,
|
|
10
|
+
event2 as event,
|
|
11
|
+
eventType2 as eventType,
|
|
12
|
+
read2 as read,
|
|
13
|
+
readError2 as readError
|
|
14
|
+
};
|
|
@@ -1,56 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let stderr = Buffer.alloc(0);
|
|
12
|
-
const onStderr = (chunk) => {
|
|
13
|
-
const tail = chunk.subarray(-stderrLimit);
|
|
14
|
-
stderr =
|
|
15
|
-
tail.length === stderrLimit
|
|
16
|
-
? Buffer.from(tail)
|
|
17
|
-
: Buffer.concat([stderr.subarray(-(stderrLimit - tail.length)), tail]);
|
|
18
|
-
};
|
|
19
|
-
child.stderr?.on("data", onStderr);
|
|
20
|
-
if (child.stderr !== null && "unref" in child.stderr && typeof child.stderr.unref === "function")
|
|
21
|
-
child.stderr.unref();
|
|
22
|
-
child.once("error", (cause) => {
|
|
23
|
-
error = new Error("Failed to start server", { cause });
|
|
24
|
-
});
|
|
25
|
-
child.once("close", () => {
|
|
26
|
-
closed = true;
|
|
27
|
-
});
|
|
28
|
-
child.unref();
|
|
29
|
-
return {
|
|
30
|
-
child,
|
|
31
|
-
error: () => error,
|
|
32
|
-
closed: () => closed,
|
|
33
|
-
stderr: () => stderr.toString("utf8").trim(),
|
|
34
|
-
release: () => {
|
|
35
|
-
child.stderr?.off("data", onStderr);
|
|
36
|
-
child.stderr?.resume();
|
|
37
|
-
stderr = Buffer.alloc(0);
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function contenderFailure(contender) {
|
|
42
|
-
const error = contender.error();
|
|
43
|
-
if (error !== undefined)
|
|
44
|
-
return error;
|
|
45
|
-
if (contender.child.exitCode !== null && contender.child.exitCode !== 0)
|
|
46
|
-
return startupError(`Server process exited with code ${contender.child.exitCode}`, contender.stderr());
|
|
47
|
-
if (contender.child.signalCode !== null)
|
|
48
|
-
return startupError(`Server process terminated by ${contender.child.signalCode}`, contender.stderr());
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
export function contenderFinished(contender) {
|
|
52
|
-
return contender.error() !== undefined || contender.closed();
|
|
53
|
-
}
|
|
54
|
-
function startupError(message, stderr) {
|
|
55
|
-
return new Error(stderr ? `${message}\n${stderr}` : message);
|
|
56
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
spawnServiceContender2,
|
|
3
|
+
contenderFailure2,
|
|
4
|
+
contenderFinished2
|
|
5
|
+
} from "./chunks/pty-handoff-txckps9j.js";
|
|
6
|
+
export {
|
|
7
|
+
contenderFailure2 as contenderFailure,
|
|
8
|
+
contenderFinished2 as contenderFinished,
|
|
9
|
+
spawnServiceContender2 as spawnServiceContender
|
|
10
|
+
};
|
package/dist/service-timing.d.ts
CHANGED
package/dist/service-timing.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
stopPollAttempts: 100,
|
|
1
|
+
import {
|
|
2
|
+
defaultEnsureTiming2,
|
|
3
|
+
ensureTiming2,
|
|
4
|
+
withEnsureTiming2
|
|
5
|
+
} from "./chunks/pty-handoff-xgnj2w4v.js";
|
|
6
|
+
export {
|
|
7
|
+
defaultEnsureTiming2 as defaultEnsureTiming,
|
|
8
|
+
ensureTiming2 as ensureTiming,
|
|
9
|
+
withEnsureTiming2 as withEnsureTiming
|
|
11
10
|
};
|
|
12
|
-
export function ensureTiming(options) {
|
|
13
|
-
return timings.get(options) ?? defaultEnsureTiming;
|
|
14
|
-
}
|
|
15
|
-
// Keep test timing out of the public lifecycle option types.
|
|
16
|
-
export function withEnsureTiming(options, overrides) {
|
|
17
|
-
timings.set(options, { ...defaultEnsureTiming, ...overrides });
|
|
18
|
-
return options;
|
|
19
|
-
}
|
package/dist/service-version.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return options.version(version);
|
|
8
|
-
return version === options.version;
|
|
9
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
matchesVersion2
|
|
3
|
+
} from "./chunks/pty-handoff-sxt88q69.js";
|
|
4
|
+
export {
|
|
5
|
+
matchesVersion2 as matchesVersion
|
|
6
|
+
};
|
package/dist/service.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunks/pty-handoff-qav6mfdz.js";
|
package/dist/shared-events.js
CHANGED
|
@@ -1,137 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
current = undefined;
|
|
10
|
-
}
|
|
11
|
-
async function run(connection) {
|
|
12
|
-
let iterator;
|
|
13
|
-
let completion = {};
|
|
14
|
-
try {
|
|
15
|
-
if (connection.controller.signal.aborted)
|
|
16
|
-
return;
|
|
17
|
-
iterator = connect(connection.controller.signal, () => {
|
|
18
|
-
connection.subscribers.forEach((subscriber) => subscriber.activity?.());
|
|
19
|
-
})[Symbol.asyncIterator]();
|
|
20
|
-
while (!connection.controller.signal.aborted) {
|
|
21
|
-
const item = await iterator.next();
|
|
22
|
-
if (item.done || connection.controller.signal.aborted)
|
|
23
|
-
break;
|
|
24
|
-
if (item.value.type === "server.connected")
|
|
25
|
-
connection.connected = item.value;
|
|
26
|
-
connection.subscribers.forEach((subscriber) => subscriber.push(item.value));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
completion = { error };
|
|
31
|
-
}
|
|
32
|
-
finally {
|
|
33
|
-
stop(connection);
|
|
34
|
-
try {
|
|
35
|
-
await iterator?.return?.();
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
if (!("error" in completion))
|
|
39
|
-
completion = { error };
|
|
40
|
-
}
|
|
41
|
-
connection.subscribers.forEach((subscriber) => subscriber.finish(completion));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
subscribe(options) {
|
|
46
|
-
return {
|
|
47
|
-
[Symbol.asyncIterator]() {
|
|
48
|
-
const pending = [];
|
|
49
|
-
const queued = [];
|
|
50
|
-
let started = false;
|
|
51
|
-
let completion;
|
|
52
|
-
let connection;
|
|
53
|
-
function finish(result, discard = true) {
|
|
54
|
-
completion = result;
|
|
55
|
-
if (discard)
|
|
56
|
-
queued.length = 0;
|
|
57
|
-
options?.signal?.removeEventListener("abort", abort);
|
|
58
|
-
if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
|
|
59
|
-
stop(connection);
|
|
60
|
-
pending.splice(0).forEach((request) => {
|
|
61
|
-
if ("error" in result)
|
|
62
|
-
request.reject(result.error);
|
|
63
|
-
else
|
|
64
|
-
request.resolve({ done: true, value: undefined });
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function abort() {
|
|
68
|
-
finish({});
|
|
69
|
-
}
|
|
70
|
-
const subscriber = {
|
|
71
|
-
activity: options?.onActivity,
|
|
72
|
-
finish(result) {
|
|
73
|
-
finish(result, false);
|
|
74
|
-
},
|
|
75
|
-
push(value) {
|
|
76
|
-
if (completion)
|
|
77
|
-
return;
|
|
78
|
-
const request = pending.shift();
|
|
79
|
-
if (request) {
|
|
80
|
-
request.resolve({ done: false, value });
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (queued.length === capacity) {
|
|
84
|
-
finish({ error: new Error(`Event subscriber exceeded its ${capacity}-event capacity`) });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
queued.push(value);
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
function start() {
|
|
91
|
-
if (completion)
|
|
92
|
-
return;
|
|
93
|
-
const fresh = !current;
|
|
94
|
-
connection = current ?? {
|
|
95
|
-
controller: new AbortController(),
|
|
96
|
-
subscribers: new Set(),
|
|
97
|
-
};
|
|
98
|
-
current = connection;
|
|
99
|
-
connection.subscribers.add(subscriber);
|
|
100
|
-
if (connection.connected)
|
|
101
|
-
void subscriber.push(connection.connected);
|
|
102
|
-
if (fresh)
|
|
103
|
-
void run(connection);
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
next() {
|
|
107
|
-
const value = queued.shift();
|
|
108
|
-
if (value)
|
|
109
|
-
return Promise.resolve({ done: false, value });
|
|
110
|
-
if (completion) {
|
|
111
|
-
if ("error" in completion)
|
|
112
|
-
return Promise.reject(completion.error);
|
|
113
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
114
|
-
}
|
|
115
|
-
if (options?.signal?.aborted) {
|
|
116
|
-
abort();
|
|
117
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
118
|
-
}
|
|
119
|
-
const request = Promise.withResolvers();
|
|
120
|
-
pending.push(request);
|
|
121
|
-
if (!started) {
|
|
122
|
-
started = true;
|
|
123
|
-
options?.signal?.addEventListener("abort", abort, { once: true });
|
|
124
|
-
start();
|
|
125
|
-
}
|
|
126
|
-
return request.promise;
|
|
127
|
-
},
|
|
128
|
-
return() {
|
|
129
|
-
finish({});
|
|
130
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
make7,
|
|
3
|
+
exports_shared_events
|
|
4
|
+
} from "./chunks/pty-handoff-frbwqjmf.js";
|
|
5
|
+
export {
|
|
6
|
+
exports_shared_events as SharedEvents,
|
|
7
|
+
make7 as make
|
|
8
|
+
};
|
package/dist/solid/connection.js
CHANGED
|
@@ -1,246 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const abort = new AbortController();
|
|
12
|
-
const history = [];
|
|
13
|
-
const idleTimeout = options.idleTimeout ?? defaultIdleTimeout;
|
|
14
|
-
const [connection, setConnection] = createStore({ status: "connecting", attempt: 0 });
|
|
15
|
-
let api = initialApi;
|
|
16
|
-
let pending = [];
|
|
17
|
-
let flushTimer;
|
|
18
|
-
let stream;
|
|
19
|
-
let current;
|
|
20
|
-
let run;
|
|
21
|
-
let started = false;
|
|
22
|
-
let generation = 0;
|
|
23
|
-
let lastActivity = 0;
|
|
24
|
-
let forced = false;
|
|
25
|
-
function record(status, attempt, error) {
|
|
26
|
-
history.push({ type: "client.connection", created: Date.now(), data: { status, attempt, error } });
|
|
27
|
-
if (history.length > connectionHistoryLimit)
|
|
28
|
-
history.shift();
|
|
29
|
-
}
|
|
30
|
-
function publish(event) {
|
|
31
|
-
pending.push(event);
|
|
32
|
-
if (flushTimer)
|
|
33
|
-
return;
|
|
34
|
-
flushTimer = setTimeout(() => {
|
|
35
|
-
flushTimer = undefined;
|
|
36
|
-
const events = pending;
|
|
37
|
-
pending = [];
|
|
38
|
-
batch(() => events.forEach(options.onEvent));
|
|
39
|
-
}, options.flushInterval ?? 10);
|
|
40
|
-
}
|
|
41
|
-
async function connect(signal, attempt) {
|
|
42
|
-
let connectedAt;
|
|
43
|
-
const request = new AbortController();
|
|
44
|
-
current = request;
|
|
45
|
-
const cancel = () => request.abort(signal.reason);
|
|
46
|
-
const timeout = setTimeout(() => request.abort(new Error("Timed out connecting to server")), connectTimeout);
|
|
47
|
-
signal.addEventListener("abort", cancel, { once: true });
|
|
48
|
-
// Any received bytes, including keepalive comments, push the stall deadline out. A timer whose
|
|
49
|
-
// deadline passed while the page was suspended fires as soon as the page resumes.
|
|
50
|
-
let watchdog;
|
|
51
|
-
const touch = () => {
|
|
52
|
-
lastActivity = Date.now();
|
|
53
|
-
if (connectedAt === undefined)
|
|
54
|
-
return;
|
|
55
|
-
clearTimeout(watchdog);
|
|
56
|
-
watchdog = setTimeout(() => request.abort(new Error("Event stream stalled")), idleTimeout);
|
|
57
|
-
};
|
|
58
|
-
try {
|
|
59
|
-
record(attempt === 0 ? "connecting" : "reconnecting", attempt);
|
|
60
|
-
options.log?.info?.("event stream connecting", { attempt });
|
|
61
|
-
const iterator = api.event.subscribe({ signal: request.signal, onActivity: touch })[Symbol.asyncIterator]();
|
|
62
|
-
const first = await iterator.next();
|
|
63
|
-
if (signal.aborted)
|
|
64
|
-
return { error: undefined, connectedAt };
|
|
65
|
-
if (first.done)
|
|
66
|
-
return {
|
|
67
|
-
error: request.signal.reason instanceof Error ? request.signal.reason : new Error("Event stream disconnected"),
|
|
68
|
-
connectedAt,
|
|
69
|
-
};
|
|
70
|
-
if (first.value.type !== "server.connected")
|
|
71
|
-
return { error: new Error("Event stream did not start with server.connected"), connectedAt };
|
|
72
|
-
clearTimeout(timeout);
|
|
73
|
-
record("connected", attempt);
|
|
74
|
-
connectedAt = Date.now();
|
|
75
|
-
touch();
|
|
76
|
-
options.log?.info?.("event stream connected");
|
|
77
|
-
publish(first.value);
|
|
78
|
-
setConnection({ status: "connected", attempt: 0, error: undefined });
|
|
79
|
-
while (!signal.aborted) {
|
|
80
|
-
const event = await iterator.next();
|
|
81
|
-
if (signal.aborted)
|
|
82
|
-
return { error: undefined, connectedAt };
|
|
83
|
-
if (event.done)
|
|
84
|
-
return {
|
|
85
|
-
error: request.signal.reason instanceof Error ? request.signal.reason : new Error("Event stream disconnected"),
|
|
86
|
-
connectedAt,
|
|
87
|
-
};
|
|
88
|
-
touch();
|
|
89
|
-
if ("durable" in event.value && event.value.durable)
|
|
90
|
-
options.log?.debug?.("event", {
|
|
91
|
-
type: event.value.type,
|
|
92
|
-
aggregateID: event.value.durable.aggregateID,
|
|
93
|
-
seq: event.value.durable.seq,
|
|
94
|
-
});
|
|
95
|
-
publish(event.value);
|
|
96
|
-
}
|
|
97
|
-
return { error: undefined, connectedAt };
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
return { error, connectedAt };
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
request.abort();
|
|
104
|
-
if (current === request)
|
|
105
|
-
current = undefined;
|
|
106
|
-
clearTimeout(timeout);
|
|
107
|
-
clearTimeout(watchdog);
|
|
108
|
-
signal.removeEventListener("abort", cancel);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async function runStream(active) {
|
|
112
|
-
let attempt = 0;
|
|
113
|
-
while (!abort.signal.aborted && started && generation === active) {
|
|
114
|
-
setConnection({ status: attempt === 0 ? "connecting" : "reconnecting", attempt });
|
|
115
|
-
const controller = new AbortController();
|
|
116
|
-
stream = controller;
|
|
117
|
-
const cancel = () => controller.abort(abort.signal.reason);
|
|
118
|
-
abort.signal.addEventListener("abort", cancel);
|
|
119
|
-
const result = await connect(controller.signal, attempt);
|
|
120
|
-
abort.signal.removeEventListener("abort", cancel);
|
|
121
|
-
if (abort.signal.aborted || !started || generation !== active)
|
|
122
|
-
return;
|
|
123
|
-
if (result.connectedAt !== undefined && Date.now() - result.connectedAt >= reconnectDelay)
|
|
124
|
-
attempt = 0;
|
|
125
|
-
attempt += 1;
|
|
126
|
-
const message = errorMessage(result.error);
|
|
127
|
-
record("disconnected", attempt, message);
|
|
128
|
-
options.log?.info?.("event stream disconnected", { attempt, error: message });
|
|
129
|
-
setConnection({ status: "reconnecting", attempt, error: message });
|
|
130
|
-
if (options.reconnect) {
|
|
131
|
-
const next = await options.reconnect(controller.signal).catch((error) => {
|
|
132
|
-
if (!controller.signal.aborted)
|
|
133
|
-
options.log?.info?.("server resolution failed", { attempt, error: errorMessage(error) });
|
|
134
|
-
});
|
|
135
|
-
if (abort.signal.aborted || controller.signal.aborted || !started || generation !== active)
|
|
136
|
-
return;
|
|
137
|
-
if (next) {
|
|
138
|
-
api = next;
|
|
139
|
-
if (attempt === 1)
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// A deliberate resync already knows the old socket is gone; reconnect without backing off.
|
|
144
|
-
if (forced) {
|
|
145
|
-
forced = false;
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
await wait(reconnectDelay, controller.signal);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
function start() {
|
|
152
|
-
if (started)
|
|
153
|
-
return run;
|
|
154
|
-
started = true;
|
|
155
|
-
forced = false;
|
|
156
|
-
const active = ++generation;
|
|
157
|
-
const previous = run;
|
|
158
|
-
const current = (async () => {
|
|
159
|
-
if (previous)
|
|
160
|
-
await previous;
|
|
161
|
-
await runStream(active);
|
|
162
|
-
})().finally(() => {
|
|
163
|
-
if (run !== current)
|
|
164
|
-
return;
|
|
165
|
-
run = undefined;
|
|
166
|
-
});
|
|
167
|
-
run = current;
|
|
168
|
-
return run;
|
|
169
|
-
}
|
|
170
|
-
function stop() {
|
|
171
|
-
if (!started)
|
|
172
|
-
return;
|
|
173
|
-
started = false;
|
|
174
|
-
generation += 1;
|
|
175
|
-
stream?.abort();
|
|
176
|
-
// Nothing is listening once stopped, so consumers must treat their data as stale until start() reconnects.
|
|
177
|
-
setConnection({ status: "connecting", attempt: 0, error: undefined });
|
|
178
|
-
}
|
|
179
|
-
// Drop the live request so the reconnect loop replaces it now instead of waiting for the idle watchdog.
|
|
180
|
-
function resync(reason) {
|
|
181
|
-
if (!started || connection.status !== "connected")
|
|
182
|
-
return;
|
|
183
|
-
options.log?.info?.("event stream resync", { reason, idle: Date.now() - lastActivity });
|
|
184
|
-
forced = true;
|
|
185
|
-
current?.abort(new Error(reason));
|
|
186
|
-
}
|
|
187
|
-
if (options.pageLifecycle) {
|
|
188
|
-
const pagehide = () => stop();
|
|
189
|
-
const pageshow = () => void start();
|
|
190
|
-
// Locking a phone or switching apps hides the document without a pagehide; the socket usually
|
|
191
|
-
// dies while the page is suspended, and the browser may never report that on the hung read.
|
|
192
|
-
const visibility = () => {
|
|
193
|
-
if (document.visibilityState !== "visible")
|
|
194
|
-
return;
|
|
195
|
-
if (Date.now() - lastActivity < foregroundIdleThreshold)
|
|
196
|
-
return;
|
|
197
|
-
resync("Page returned to the foreground after the event stream went quiet");
|
|
198
|
-
};
|
|
199
|
-
const online = () => resync("Network connection restored");
|
|
200
|
-
window.addEventListener("pagehide", pagehide);
|
|
201
|
-
window.addEventListener("pageshow", pageshow);
|
|
202
|
-
window.addEventListener("online", online);
|
|
203
|
-
document.addEventListener("visibilitychange", visibility);
|
|
204
|
-
onCleanup(() => {
|
|
205
|
-
window.removeEventListener("pagehide", pagehide);
|
|
206
|
-
window.removeEventListener("pageshow", pageshow);
|
|
207
|
-
window.removeEventListener("online", online);
|
|
208
|
-
document.removeEventListener("visibilitychange", visibility);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
void start();
|
|
212
|
-
onCleanup(() => {
|
|
213
|
-
stop();
|
|
214
|
-
abort.abort();
|
|
215
|
-
if (flushTimer)
|
|
216
|
-
clearTimeout(flushTimer);
|
|
217
|
-
pending = [];
|
|
218
|
-
});
|
|
219
|
-
return {
|
|
220
|
-
status: () => connection.status,
|
|
221
|
-
attempt: () => connection.attempt,
|
|
222
|
-
error: () => connection.error,
|
|
223
|
-
internal: {
|
|
224
|
-
history: () => history.slice(),
|
|
225
|
-
resync,
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
function errorMessage(error) {
|
|
230
|
-
if (error === undefined)
|
|
231
|
-
return undefined;
|
|
232
|
-
if (error instanceof Error)
|
|
233
|
-
return error.message;
|
|
234
|
-
return String(error);
|
|
235
|
-
}
|
|
236
|
-
function wait(delay, signal) {
|
|
237
|
-
return new Promise((resolve) => {
|
|
238
|
-
const timer = setTimeout(done, delay);
|
|
239
|
-
signal.addEventListener("abort", done, { once: true });
|
|
240
|
-
function done() {
|
|
241
|
-
clearTimeout(timer);
|
|
242
|
-
signal.removeEventListener("abort", done);
|
|
243
|
-
resolve();
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
defaultIdleTimeout2,
|
|
3
|
+
foregroundIdleThreshold2,
|
|
4
|
+
createClientConnection2
|
|
5
|
+
} from "../chunks/pty-handoff-ydhz1zrh.js";
|
|
6
|
+
export {
|
|
7
|
+
createClientConnection2 as createClientConnection,
|
|
8
|
+
defaultIdleTimeout2 as defaultIdleTimeout,
|
|
9
|
+
foregroundIdleThreshold2 as foregroundIdleThreshold
|
|
10
|
+
};
|