@adhdev/session-host-core 1.0.82-rc.26 → 1.0.82-rc.27
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/index.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +71 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/ipc.ts +69 -12
package/dist/index.d.mts
CHANGED
|
@@ -663,6 +663,8 @@ interface SessionHostClientOptions {
|
|
|
663
663
|
endpoint?: SessionHostEndpoint;
|
|
664
664
|
appName?: string;
|
|
665
665
|
requestTimeoutMs?: number;
|
|
666
|
+
/** Join the shared client registry (default true). Disable for short-lived probes. */
|
|
667
|
+
registerAsShared?: boolean;
|
|
666
668
|
}
|
|
667
669
|
/**
|
|
668
670
|
* Why an established session-host connection went away.
|
|
@@ -672,6 +674,7 @@ interface SessionHostClientOptions {
|
|
|
672
674
|
*/
|
|
673
675
|
type SessionHostDisconnectReason = 'error' | 'ended' | 'closed';
|
|
674
676
|
declare function disconnectSessionHostClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
677
|
+
declare function findConnectedSessionHostClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
675
678
|
interface SessionHostDisconnectInfo {
|
|
676
679
|
reason: SessionHostDisconnectReason;
|
|
677
680
|
endpointPath: string;
|
|
@@ -703,6 +706,8 @@ declare class SessionHostClient {
|
|
|
703
706
|
private attachedSessions;
|
|
704
707
|
constructor(options?: SessionHostClientOptions);
|
|
705
708
|
static disconnectClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
709
|
+
static findConnectedClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
710
|
+
isConnected(): boolean;
|
|
706
711
|
/**
|
|
707
712
|
* Fires when an established connection to the session host goes away.
|
|
708
713
|
*
|
|
@@ -718,9 +723,11 @@ declare class SessionHostClient {
|
|
|
718
723
|
onDisconnect(listener: (info: SessionHostDisconnectInfo) => void): () => void;
|
|
719
724
|
private handleDisconnect;
|
|
720
725
|
private sendRawRequestOnSocket;
|
|
721
|
-
connect(): Promise<void>;
|
|
726
|
+
connect(timeoutMs?: number): Promise<void>;
|
|
722
727
|
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
723
|
-
request<T = unknown>(request: SessionHostRequest
|
|
728
|
+
request<T = unknown>(request: SessionHostRequest, options?: {
|
|
729
|
+
timeoutMs?: number;
|
|
730
|
+
}): Promise<SessionHostResponse<T>>;
|
|
724
731
|
disconnect(error?: Error): void;
|
|
725
732
|
close(): Promise<void>;
|
|
726
733
|
}
|
|
@@ -880,4 +887,4 @@ interface SessionHostControlTransport {
|
|
|
880
887
|
*/
|
|
881
888
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
882
889
|
|
|
883
|
-
export { type AcquireWritePayload, type AttachSessionPayload, CLI_CHILD_NICE_ENV, CLI_CHILD_NICE_INCREMENT, CLI_CHILD_SCHEDULING_ENV, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, writeEnvelope };
|
|
890
|
+
export { type AcquireWritePayload, type AttachSessionPayload, CLI_CHILD_NICE_ENV, CLI_CHILD_NICE_INCREMENT, CLI_CHILD_SCHEDULING_ENV, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, findConnectedSessionHostClient, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, writeEnvelope };
|
package/dist/index.d.ts
CHANGED
|
@@ -663,6 +663,8 @@ interface SessionHostClientOptions {
|
|
|
663
663
|
endpoint?: SessionHostEndpoint;
|
|
664
664
|
appName?: string;
|
|
665
665
|
requestTimeoutMs?: number;
|
|
666
|
+
/** Join the shared client registry (default true). Disable for short-lived probes. */
|
|
667
|
+
registerAsShared?: boolean;
|
|
666
668
|
}
|
|
667
669
|
/**
|
|
668
670
|
* Why an established session-host connection went away.
|
|
@@ -672,6 +674,7 @@ interface SessionHostClientOptions {
|
|
|
672
674
|
*/
|
|
673
675
|
type SessionHostDisconnectReason = 'error' | 'ended' | 'closed';
|
|
674
676
|
declare function disconnectSessionHostClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
677
|
+
declare function findConnectedSessionHostClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
675
678
|
interface SessionHostDisconnectInfo {
|
|
676
679
|
reason: SessionHostDisconnectReason;
|
|
677
680
|
endpointPath: string;
|
|
@@ -703,6 +706,8 @@ declare class SessionHostClient {
|
|
|
703
706
|
private attachedSessions;
|
|
704
707
|
constructor(options?: SessionHostClientOptions);
|
|
705
708
|
static disconnectClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
709
|
+
static findConnectedClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
710
|
+
isConnected(): boolean;
|
|
706
711
|
/**
|
|
707
712
|
* Fires when an established connection to the session host goes away.
|
|
708
713
|
*
|
|
@@ -718,9 +723,11 @@ declare class SessionHostClient {
|
|
|
718
723
|
onDisconnect(listener: (info: SessionHostDisconnectInfo) => void): () => void;
|
|
719
724
|
private handleDisconnect;
|
|
720
725
|
private sendRawRequestOnSocket;
|
|
721
|
-
connect(): Promise<void>;
|
|
726
|
+
connect(timeoutMs?: number): Promise<void>;
|
|
722
727
|
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
723
|
-
request<T = unknown>(request: SessionHostRequest
|
|
728
|
+
request<T = unknown>(request: SessionHostRequest, options?: {
|
|
729
|
+
timeoutMs?: number;
|
|
730
|
+
}): Promise<SessionHostResponse<T>>;
|
|
724
731
|
disconnect(error?: Error): void;
|
|
725
732
|
close(): Promise<void>;
|
|
726
733
|
}
|
|
@@ -880,4 +887,4 @@ interface SessionHostControlTransport {
|
|
|
880
887
|
*/
|
|
881
888
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
882
889
|
|
|
883
|
-
export { type AcquireWritePayload, type AttachSessionPayload, CLI_CHILD_NICE_ENV, CLI_CHILD_NICE_INCREMENT, CLI_CHILD_SCHEDULING_ENV, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, writeEnvelope };
|
|
890
|
+
export { type AcquireWritePayload, type AttachSessionPayload, CLI_CHILD_NICE_ENV, CLI_CHILD_NICE_INCREMENT, CLI_CHILD_SCHEDULING_ENV, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, findConnectedSessionHostClient, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, writeEnvelope };
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,7 @@ __export(index_exports, {
|
|
|
52
52
|
createSessionHostControlPlane: () => createSessionHostControlPlane,
|
|
53
53
|
disconnectSessionHostClients: () => disconnectSessionHostClients,
|
|
54
54
|
ensureNodePtySpawnHelperPermissions: () => ensureNodePtySpawnHelperPermissions,
|
|
55
|
+
findConnectedSessionHostClient: () => findConnectedSessionHostClient,
|
|
55
56
|
formatRuntimeOwner: () => formatRuntimeOwner,
|
|
56
57
|
getDefaultSessionHostEndpoint: () => getDefaultSessionHostEndpoint,
|
|
57
58
|
getSessionHostRecoveryLabel: () => getSessionHostRecoveryLabel,
|
|
@@ -818,6 +819,19 @@ function disconnectSessionHostClients(endpoint, error) {
|
|
|
818
819
|
}
|
|
819
820
|
}
|
|
820
821
|
}
|
|
822
|
+
function findConnectedSessionHostClient(endpoint) {
|
|
823
|
+
for (const ref of activeClientRefs) {
|
|
824
|
+
const client = ref.deref();
|
|
825
|
+
if (!client) {
|
|
826
|
+
activeClientRefs.delete(ref);
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
829
|
+
if ((!endpoint || client.endpoint.path === endpoint.path) && client.isConnected()) {
|
|
830
|
+
return client;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
821
835
|
var SessionHostClient = class {
|
|
822
836
|
endpoint;
|
|
823
837
|
socket = null;
|
|
@@ -835,11 +849,17 @@ var SessionHostClient = class {
|
|
|
835
849
|
if (typeof options.requestTimeoutMs === "number" && options.requestTimeoutMs > 0) {
|
|
836
850
|
this.requestTimeoutMs = options.requestTimeoutMs;
|
|
837
851
|
}
|
|
838
|
-
activeClientRefs.add(new WeakRef(this));
|
|
852
|
+
if (options.registerAsShared !== false) activeClientRefs.add(new WeakRef(this));
|
|
839
853
|
}
|
|
840
854
|
static disconnectClients(endpoint, error) {
|
|
841
855
|
disconnectSessionHostClients(endpoint, error);
|
|
842
856
|
}
|
|
857
|
+
static findConnectedClient(endpoint) {
|
|
858
|
+
return findConnectedSessionHostClient(endpoint);
|
|
859
|
+
}
|
|
860
|
+
isConnected() {
|
|
861
|
+
return Boolean(this.socket && !this.socket.destroyed && establishedSockets.has(this.socket));
|
|
862
|
+
}
|
|
843
863
|
/**
|
|
844
864
|
* Fires when an established connection to the session host goes away.
|
|
845
865
|
*
|
|
@@ -901,18 +921,17 @@ var SessionHostClient = class {
|
|
|
901
921
|
}
|
|
902
922
|
}
|
|
903
923
|
}
|
|
904
|
-
sendRawRequestOnSocket(socket, request) {
|
|
924
|
+
sendRawRequestOnSocket(socket, request, timeoutMs = this.requestTimeoutMs) {
|
|
905
925
|
const requestId = generateUUID();
|
|
906
926
|
const envelope = {
|
|
907
927
|
kind: "request",
|
|
908
928
|
requestId,
|
|
909
929
|
request
|
|
910
930
|
};
|
|
911
|
-
const timeoutMs = this.requestTimeoutMs > 0 ? this.requestTimeoutMs : 3e4;
|
|
912
931
|
const timeoutLabel = timeoutMs % 1e3 === 0 ? `${timeoutMs / 1e3}s` : `${timeoutMs}ms`;
|
|
913
932
|
return new Promise((resolve3, reject) => {
|
|
914
933
|
const timeout = setTimeout(() => {
|
|
915
|
-
const timeoutError = new Error(`Session host request timed out after ${timeoutLabel} (${request.type})`);
|
|
934
|
+
const timeoutError = Object.assign(new Error(`Session host request timed out after ${timeoutLabel} (${request.type})`), { code: "SESSION_HOST_REQUEST_TIMEOUT", requestType: request.type });
|
|
916
935
|
if (this.socket === socket) {
|
|
917
936
|
this.disconnect(timeoutError);
|
|
918
937
|
} else {
|
|
@@ -938,7 +957,7 @@ var SessionHostClient = class {
|
|
|
938
957
|
socket.write(serializeEnvelope(envelope));
|
|
939
958
|
});
|
|
940
959
|
}
|
|
941
|
-
async connect() {
|
|
960
|
+
async connect(timeoutMs = this.requestTimeoutMs) {
|
|
942
961
|
if (this.socket && !this.socket.destroyed) {
|
|
943
962
|
if (this.connectPromise) await this.connectPromise;
|
|
944
963
|
return;
|
|
@@ -986,11 +1005,30 @@ var SessionHostClient = class {
|
|
|
986
1005
|
});
|
|
987
1006
|
const connectTask = (async () => {
|
|
988
1007
|
await new Promise((resolve3, reject) => {
|
|
989
|
-
|
|
1008
|
+
const cleanup = () => {
|
|
1009
|
+
clearTimeout(timer);
|
|
1010
|
+
socket.off("connect", connected);
|
|
1011
|
+
socket.off("error", failed);
|
|
1012
|
+
socket.off("close", closed);
|
|
1013
|
+
};
|
|
1014
|
+
const connected = () => {
|
|
1015
|
+
cleanup();
|
|
990
1016
|
establishedSockets.add(socket);
|
|
991
1017
|
resolve3();
|
|
992
|
-
}
|
|
993
|
-
|
|
1018
|
+
};
|
|
1019
|
+
const failed = (error) => {
|
|
1020
|
+
cleanup();
|
|
1021
|
+
reject(error);
|
|
1022
|
+
};
|
|
1023
|
+
const closed = () => failed(new Error("Session host connection closed before connect"));
|
|
1024
|
+
const timer = setTimeout(() => {
|
|
1025
|
+
const error = Object.assign(new Error(`Session host connect timed out after ${timeoutMs}ms`), { code: "SESSION_HOST_CONNECT_TIMEOUT" });
|
|
1026
|
+
failed(error);
|
|
1027
|
+
if (this.socket === socket) this.disconnect(error);
|
|
1028
|
+
}, timeoutMs);
|
|
1029
|
+
socket.once("connect", connected);
|
|
1030
|
+
socket.once("error", failed);
|
|
1031
|
+
socket.once("close", closed);
|
|
994
1032
|
});
|
|
995
1033
|
if (this.attachedSessions.size > 0 && this.socket === socket && !socket.destroyed) {
|
|
996
1034
|
for (const [sessionId, sub] of [...this.attachedSessions.entries()]) {
|
|
@@ -1020,11 +1058,32 @@ var SessionHostClient = class {
|
|
|
1020
1058
|
this.eventListeners.delete(listener);
|
|
1021
1059
|
};
|
|
1022
1060
|
}
|
|
1023
|
-
async request(request) {
|
|
1024
|
-
|
|
1061
|
+
async request(request, options = {}) {
|
|
1062
|
+
const timeoutMs = Math.max(1, options.timeoutMs ?? this.requestTimeoutMs);
|
|
1063
|
+
const deadline = Date.now() + timeoutMs;
|
|
1064
|
+
const alreadyConnected = this.isConnected() && !this.connectPromise;
|
|
1065
|
+
if (options.timeoutMs !== void 0) {
|
|
1066
|
+
let timer;
|
|
1067
|
+
try {
|
|
1068
|
+
await Promise.race([
|
|
1069
|
+
this.connect(timeoutMs),
|
|
1070
|
+
new Promise((_resolve, reject) => {
|
|
1071
|
+
timer = setTimeout(() => {
|
|
1072
|
+
const error = Object.assign(new Error(`Session host connect timed out after ${timeoutMs}ms`), { code: "SESSION_HOST_CONNECT_TIMEOUT" });
|
|
1073
|
+
reject(error);
|
|
1074
|
+
this.disconnect(error);
|
|
1075
|
+
}, timeoutMs);
|
|
1076
|
+
})
|
|
1077
|
+
]);
|
|
1078
|
+
} finally {
|
|
1079
|
+
if (timer) clearTimeout(timer);
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
await this.connect(timeoutMs);
|
|
1083
|
+
}
|
|
1025
1084
|
const requestSocket = this.socket;
|
|
1026
1085
|
if (!requestSocket) throw new Error("Session host socket unavailable");
|
|
1027
|
-
const response = await this.sendRawRequestOnSocket(requestSocket, request);
|
|
1086
|
+
const response = await this.sendRawRequestOnSocket(requestSocket, request, options.timeoutMs === void 0 || alreadyConnected ? timeoutMs : Math.max(1, deadline - Date.now()));
|
|
1028
1087
|
if (response.success) {
|
|
1029
1088
|
if (request.type === "attach_session") {
|
|
1030
1089
|
this.attachedSessions.set(request.payload.sessionId, {
|
|
@@ -1285,6 +1344,7 @@ function createSessionHostControlPlane(transport) {
|
|
|
1285
1344
|
createSessionHostControlPlane,
|
|
1286
1345
|
disconnectSessionHostClients,
|
|
1287
1346
|
ensureNodePtySpawnHelperPermissions,
|
|
1347
|
+
findConnectedSessionHostClient,
|
|
1288
1348
|
formatRuntimeOwner,
|
|
1289
1349
|
getDefaultSessionHostEndpoint,
|
|
1290
1350
|
getSessionHostRecoveryLabel,
|