@adhdev/session-host-core 0.7.12
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 +293 -0
- package/dist/index.d.ts +293 -0
- package/dist/index.js +523 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +475 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
- package/src/buffer.ts +78 -0
- package/src/index.ts +49 -0
- package/src/ipc.ts +164 -0
- package/src/registry.ts +252 -0
- package/src/runtime-labels.ts +85 -0
- package/src/types.ts +184 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import * as net from 'net';
|
|
2
|
+
|
|
3
|
+
type SessionTransport = 'pty';
|
|
4
|
+
type SessionHostCategory = 'cli' | 'acp' | 'shell';
|
|
5
|
+
type SessionLifecycle = 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted';
|
|
6
|
+
type SessionClientType = 'daemon' | 'web' | 'local-terminal';
|
|
7
|
+
type SessionOwnerType = 'agent' | 'user';
|
|
8
|
+
interface SessionLaunchCommand {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface SessionWriteOwner {
|
|
14
|
+
clientId: string;
|
|
15
|
+
ownerType: SessionOwnerType;
|
|
16
|
+
acquiredAt: number;
|
|
17
|
+
}
|
|
18
|
+
interface SessionAttachedClient {
|
|
19
|
+
clientId: string;
|
|
20
|
+
type: SessionClientType;
|
|
21
|
+
readOnly: boolean;
|
|
22
|
+
attachedAt: number;
|
|
23
|
+
lastSeenAt: number;
|
|
24
|
+
}
|
|
25
|
+
interface SessionBufferSnapshot {
|
|
26
|
+
seq: number;
|
|
27
|
+
text: string;
|
|
28
|
+
truncated: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface SessionBufferState {
|
|
31
|
+
scrollbackBytes: number;
|
|
32
|
+
snapshotSeq: number;
|
|
33
|
+
}
|
|
34
|
+
interface SessionHostRecord {
|
|
35
|
+
sessionId: string;
|
|
36
|
+
runtimeKey: string;
|
|
37
|
+
displayName: string;
|
|
38
|
+
workspaceLabel: string;
|
|
39
|
+
transport: SessionTransport;
|
|
40
|
+
providerType: string;
|
|
41
|
+
category: SessionHostCategory;
|
|
42
|
+
workspace: string;
|
|
43
|
+
launchCommand: SessionLaunchCommand;
|
|
44
|
+
osPid?: number;
|
|
45
|
+
createdAt: number;
|
|
46
|
+
startedAt?: number;
|
|
47
|
+
lastActivityAt: number;
|
|
48
|
+
lifecycle: SessionLifecycle;
|
|
49
|
+
writeOwner: SessionWriteOwner | null;
|
|
50
|
+
attachedClients: SessionAttachedClient[];
|
|
51
|
+
buffer: SessionBufferState;
|
|
52
|
+
meta: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
interface CreateSessionPayload {
|
|
55
|
+
sessionId?: string;
|
|
56
|
+
runtimeKey?: string;
|
|
57
|
+
displayName?: string;
|
|
58
|
+
providerType: string;
|
|
59
|
+
category: SessionHostCategory;
|
|
60
|
+
workspace: string;
|
|
61
|
+
launchCommand: SessionLaunchCommand;
|
|
62
|
+
cols?: number;
|
|
63
|
+
rows?: number;
|
|
64
|
+
clientId?: string;
|
|
65
|
+
clientType?: SessionClientType;
|
|
66
|
+
meta?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
interface AttachSessionPayload {
|
|
69
|
+
sessionId: string;
|
|
70
|
+
clientId: string;
|
|
71
|
+
clientType: SessionClientType;
|
|
72
|
+
readOnly?: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface DetachSessionPayload {
|
|
75
|
+
sessionId: string;
|
|
76
|
+
clientId: string;
|
|
77
|
+
}
|
|
78
|
+
interface SendInputPayload {
|
|
79
|
+
sessionId: string;
|
|
80
|
+
clientId: string;
|
|
81
|
+
data: string;
|
|
82
|
+
}
|
|
83
|
+
interface ResizeSessionPayload {
|
|
84
|
+
sessionId: string;
|
|
85
|
+
cols: number;
|
|
86
|
+
rows: number;
|
|
87
|
+
}
|
|
88
|
+
interface StopSessionPayload {
|
|
89
|
+
sessionId: string;
|
|
90
|
+
}
|
|
91
|
+
interface ResumeSessionPayload {
|
|
92
|
+
sessionId: string;
|
|
93
|
+
}
|
|
94
|
+
interface AcquireWritePayload {
|
|
95
|
+
sessionId: string;
|
|
96
|
+
clientId: string;
|
|
97
|
+
ownerType: SessionOwnerType;
|
|
98
|
+
force?: boolean;
|
|
99
|
+
}
|
|
100
|
+
interface ReleaseWritePayload {
|
|
101
|
+
sessionId: string;
|
|
102
|
+
clientId: string;
|
|
103
|
+
}
|
|
104
|
+
interface GetSnapshotPayload {
|
|
105
|
+
sessionId: string;
|
|
106
|
+
sinceSeq?: number;
|
|
107
|
+
}
|
|
108
|
+
interface ClearSessionBufferPayload {
|
|
109
|
+
sessionId: string;
|
|
110
|
+
}
|
|
111
|
+
type SessionHostRequest = {
|
|
112
|
+
type: 'create_session';
|
|
113
|
+
payload: CreateSessionPayload;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'attach_session';
|
|
116
|
+
payload: AttachSessionPayload;
|
|
117
|
+
} | {
|
|
118
|
+
type: 'detach_session';
|
|
119
|
+
payload: DetachSessionPayload;
|
|
120
|
+
} | {
|
|
121
|
+
type: 'send_input';
|
|
122
|
+
payload: SendInputPayload;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'resize_session';
|
|
125
|
+
payload: ResizeSessionPayload;
|
|
126
|
+
} | {
|
|
127
|
+
type: 'stop_session';
|
|
128
|
+
payload: StopSessionPayload;
|
|
129
|
+
} | {
|
|
130
|
+
type: 'resume_session';
|
|
131
|
+
payload: ResumeSessionPayload;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'acquire_write';
|
|
134
|
+
payload: AcquireWritePayload;
|
|
135
|
+
} | {
|
|
136
|
+
type: 'release_write';
|
|
137
|
+
payload: ReleaseWritePayload;
|
|
138
|
+
} | {
|
|
139
|
+
type: 'get_snapshot';
|
|
140
|
+
payload: GetSnapshotPayload;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'clear_session_buffer';
|
|
143
|
+
payload: ClearSessionBufferPayload;
|
|
144
|
+
} | {
|
|
145
|
+
type: 'list_sessions';
|
|
146
|
+
payload?: {};
|
|
147
|
+
};
|
|
148
|
+
interface SessionHostResponse<T = unknown> {
|
|
149
|
+
success: boolean;
|
|
150
|
+
result?: T;
|
|
151
|
+
error?: string;
|
|
152
|
+
}
|
|
153
|
+
type SessionHostEvent = {
|
|
154
|
+
type: 'session_created';
|
|
155
|
+
sessionId: string;
|
|
156
|
+
record: SessionHostRecord;
|
|
157
|
+
} | {
|
|
158
|
+
type: 'session_started';
|
|
159
|
+
sessionId: string;
|
|
160
|
+
pid?: number;
|
|
161
|
+
} | {
|
|
162
|
+
type: 'session_resumed';
|
|
163
|
+
sessionId: string;
|
|
164
|
+
pid?: number;
|
|
165
|
+
} | {
|
|
166
|
+
type: 'session_output';
|
|
167
|
+
sessionId: string;
|
|
168
|
+
seq: number;
|
|
169
|
+
data: string;
|
|
170
|
+
} | {
|
|
171
|
+
type: 'session_cleared';
|
|
172
|
+
sessionId: string;
|
|
173
|
+
} | {
|
|
174
|
+
type: 'session_exit';
|
|
175
|
+
sessionId: string;
|
|
176
|
+
exitCode: number | null;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'session_stopped';
|
|
179
|
+
sessionId: string;
|
|
180
|
+
} | {
|
|
181
|
+
type: 'session_resized';
|
|
182
|
+
sessionId: string;
|
|
183
|
+
cols: number;
|
|
184
|
+
rows: number;
|
|
185
|
+
} | {
|
|
186
|
+
type: 'write_owner_changed';
|
|
187
|
+
sessionId: string;
|
|
188
|
+
owner: SessionWriteOwner | null;
|
|
189
|
+
} | {
|
|
190
|
+
type: 'client_attached';
|
|
191
|
+
sessionId: string;
|
|
192
|
+
client: SessionAttachedClient;
|
|
193
|
+
} | {
|
|
194
|
+
type: 'client_detached';
|
|
195
|
+
sessionId: string;
|
|
196
|
+
clientId: string;
|
|
197
|
+
};
|
|
198
|
+
interface SessionHostRequestEnvelope {
|
|
199
|
+
kind: 'request';
|
|
200
|
+
requestId: string;
|
|
201
|
+
request: SessionHostRequest;
|
|
202
|
+
}
|
|
203
|
+
interface SessionHostResponseEnvelope {
|
|
204
|
+
kind: 'response';
|
|
205
|
+
requestId: string;
|
|
206
|
+
response: SessionHostResponse;
|
|
207
|
+
}
|
|
208
|
+
interface SessionHostEventEnvelope {
|
|
209
|
+
kind: 'event';
|
|
210
|
+
event: SessionHostEvent;
|
|
211
|
+
}
|
|
212
|
+
type SessionHostWireEnvelope = SessionHostRequestEnvelope | SessionHostResponseEnvelope | SessionHostEventEnvelope;
|
|
213
|
+
|
|
214
|
+
interface SessionRingBufferOptions {
|
|
215
|
+
maxBytes?: number;
|
|
216
|
+
}
|
|
217
|
+
declare class SessionRingBuffer {
|
|
218
|
+
private maxBytes;
|
|
219
|
+
private chunks;
|
|
220
|
+
private nextSeq;
|
|
221
|
+
private totalBytes;
|
|
222
|
+
constructor(options?: SessionRingBufferOptions);
|
|
223
|
+
append(data: string): number;
|
|
224
|
+
snapshot(sinceSeq?: number): SessionBufferSnapshot;
|
|
225
|
+
getState(): {
|
|
226
|
+
scrollbackBytes: number;
|
|
227
|
+
snapshotSeq: number;
|
|
228
|
+
};
|
|
229
|
+
clear(): void;
|
|
230
|
+
restore(snapshot: {
|
|
231
|
+
seq: number;
|
|
232
|
+
text: string;
|
|
233
|
+
}): void;
|
|
234
|
+
private trim;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
declare class SessionHostRegistry {
|
|
238
|
+
private sessions;
|
|
239
|
+
createSession(payload: CreateSessionPayload): SessionHostRecord;
|
|
240
|
+
restoreSession(record: SessionHostRecord, snapshot?: {
|
|
241
|
+
seq: number;
|
|
242
|
+
text: string;
|
|
243
|
+
} | null): SessionHostRecord;
|
|
244
|
+
listSessions(): SessionHostRecord[];
|
|
245
|
+
getSession(sessionId: string): SessionHostRecord | null;
|
|
246
|
+
attachClient(payload: AttachSessionPayload): SessionHostRecord;
|
|
247
|
+
detachClient(payload: DetachSessionPayload): SessionHostRecord;
|
|
248
|
+
acquireWrite(payload: AcquireWritePayload): SessionHostRecord;
|
|
249
|
+
releaseWrite(payload: ReleaseWritePayload): SessionHostRecord;
|
|
250
|
+
appendOutput(sessionId: string, data: string): {
|
|
251
|
+
record: SessionHostRecord;
|
|
252
|
+
seq: number;
|
|
253
|
+
};
|
|
254
|
+
getSnapshot(sessionId: string, sinceSeq?: number): SessionBufferSnapshot;
|
|
255
|
+
clearBuffer(sessionId: string): SessionHostRecord;
|
|
256
|
+
markStarted(sessionId: string, pid?: number): SessionHostRecord;
|
|
257
|
+
markStopped(sessionId: string, lifecycle?: 'stopped' | 'failed'): SessionHostRecord;
|
|
258
|
+
setLifecycle(sessionId: string, lifecycle: 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted'): SessionHostRecord;
|
|
259
|
+
private requireSession;
|
|
260
|
+
private cloneRecord;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
declare function getWorkspaceLabel(workspace: string): string;
|
|
264
|
+
declare function buildRuntimeDisplayName(payload: Pick<CreateSessionPayload, 'displayName' | 'providerType' | 'workspace'>): string;
|
|
265
|
+
declare function buildRuntimeKey(payload: Pick<CreateSessionPayload, 'runtimeKey' | 'displayName' | 'providerType' | 'workspace'>, existingKeys: Iterable<string>): string;
|
|
266
|
+
declare function resolveRuntimeRecord(records: SessionHostRecord[], identifier: string): SessionHostRecord;
|
|
267
|
+
declare function formatRuntimeOwner(record: Pick<SessionHostRecord, 'writeOwner'>): string;
|
|
268
|
+
|
|
269
|
+
interface SessionHostEndpoint {
|
|
270
|
+
kind: 'unix' | 'pipe';
|
|
271
|
+
path: string;
|
|
272
|
+
}
|
|
273
|
+
declare function getDefaultSessionHostEndpoint(appName?: string): SessionHostEndpoint;
|
|
274
|
+
declare function createLineParser(onEnvelope: (envelope: SessionHostWireEnvelope) => void): (chunk: Buffer | string) => void;
|
|
275
|
+
interface SessionHostClientOptions {
|
|
276
|
+
endpoint?: SessionHostEndpoint;
|
|
277
|
+
appName?: string;
|
|
278
|
+
}
|
|
279
|
+
declare class SessionHostClient {
|
|
280
|
+
readonly endpoint: SessionHostEndpoint;
|
|
281
|
+
private socket;
|
|
282
|
+
private requestWaiters;
|
|
283
|
+
private eventListeners;
|
|
284
|
+
constructor(options?: SessionHostClientOptions);
|
|
285
|
+
connect(): Promise<void>;
|
|
286
|
+
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
287
|
+
request<T = unknown>(request: SessionHostRequest): Promise<SessionHostResponse<T>>;
|
|
288
|
+
close(): Promise<void>;
|
|
289
|
+
}
|
|
290
|
+
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
291
|
+
declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: SessionHostWireEnvelope): void;
|
|
292
|
+
|
|
293
|
+
export { type AcquireWritePayload, type AttachSessionPayload, type ClearSessionBufferPayload, type CreateSessionPayload, type DetachSessionPayload, type GetSnapshotPayload, type ReleaseWritePayload, type ResizeSessionPayload, type ResumeSessionPayload, type SendInputPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostEndpoint, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, buildRuntimeDisplayName, buildRuntimeKey, createLineParser, createResponseEnvelope, formatRuntimeOwner, getDefaultSessionHostEndpoint, getWorkspaceLabel, resolveRuntimeRecord, writeEnvelope };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import * as net from 'net';
|
|
2
|
+
|
|
3
|
+
type SessionTransport = 'pty';
|
|
4
|
+
type SessionHostCategory = 'cli' | 'acp' | 'shell';
|
|
5
|
+
type SessionLifecycle = 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted';
|
|
6
|
+
type SessionClientType = 'daemon' | 'web' | 'local-terminal';
|
|
7
|
+
type SessionOwnerType = 'agent' | 'user';
|
|
8
|
+
interface SessionLaunchCommand {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface SessionWriteOwner {
|
|
14
|
+
clientId: string;
|
|
15
|
+
ownerType: SessionOwnerType;
|
|
16
|
+
acquiredAt: number;
|
|
17
|
+
}
|
|
18
|
+
interface SessionAttachedClient {
|
|
19
|
+
clientId: string;
|
|
20
|
+
type: SessionClientType;
|
|
21
|
+
readOnly: boolean;
|
|
22
|
+
attachedAt: number;
|
|
23
|
+
lastSeenAt: number;
|
|
24
|
+
}
|
|
25
|
+
interface SessionBufferSnapshot {
|
|
26
|
+
seq: number;
|
|
27
|
+
text: string;
|
|
28
|
+
truncated: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface SessionBufferState {
|
|
31
|
+
scrollbackBytes: number;
|
|
32
|
+
snapshotSeq: number;
|
|
33
|
+
}
|
|
34
|
+
interface SessionHostRecord {
|
|
35
|
+
sessionId: string;
|
|
36
|
+
runtimeKey: string;
|
|
37
|
+
displayName: string;
|
|
38
|
+
workspaceLabel: string;
|
|
39
|
+
transport: SessionTransport;
|
|
40
|
+
providerType: string;
|
|
41
|
+
category: SessionHostCategory;
|
|
42
|
+
workspace: string;
|
|
43
|
+
launchCommand: SessionLaunchCommand;
|
|
44
|
+
osPid?: number;
|
|
45
|
+
createdAt: number;
|
|
46
|
+
startedAt?: number;
|
|
47
|
+
lastActivityAt: number;
|
|
48
|
+
lifecycle: SessionLifecycle;
|
|
49
|
+
writeOwner: SessionWriteOwner | null;
|
|
50
|
+
attachedClients: SessionAttachedClient[];
|
|
51
|
+
buffer: SessionBufferState;
|
|
52
|
+
meta: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
interface CreateSessionPayload {
|
|
55
|
+
sessionId?: string;
|
|
56
|
+
runtimeKey?: string;
|
|
57
|
+
displayName?: string;
|
|
58
|
+
providerType: string;
|
|
59
|
+
category: SessionHostCategory;
|
|
60
|
+
workspace: string;
|
|
61
|
+
launchCommand: SessionLaunchCommand;
|
|
62
|
+
cols?: number;
|
|
63
|
+
rows?: number;
|
|
64
|
+
clientId?: string;
|
|
65
|
+
clientType?: SessionClientType;
|
|
66
|
+
meta?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
interface AttachSessionPayload {
|
|
69
|
+
sessionId: string;
|
|
70
|
+
clientId: string;
|
|
71
|
+
clientType: SessionClientType;
|
|
72
|
+
readOnly?: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface DetachSessionPayload {
|
|
75
|
+
sessionId: string;
|
|
76
|
+
clientId: string;
|
|
77
|
+
}
|
|
78
|
+
interface SendInputPayload {
|
|
79
|
+
sessionId: string;
|
|
80
|
+
clientId: string;
|
|
81
|
+
data: string;
|
|
82
|
+
}
|
|
83
|
+
interface ResizeSessionPayload {
|
|
84
|
+
sessionId: string;
|
|
85
|
+
cols: number;
|
|
86
|
+
rows: number;
|
|
87
|
+
}
|
|
88
|
+
interface StopSessionPayload {
|
|
89
|
+
sessionId: string;
|
|
90
|
+
}
|
|
91
|
+
interface ResumeSessionPayload {
|
|
92
|
+
sessionId: string;
|
|
93
|
+
}
|
|
94
|
+
interface AcquireWritePayload {
|
|
95
|
+
sessionId: string;
|
|
96
|
+
clientId: string;
|
|
97
|
+
ownerType: SessionOwnerType;
|
|
98
|
+
force?: boolean;
|
|
99
|
+
}
|
|
100
|
+
interface ReleaseWritePayload {
|
|
101
|
+
sessionId: string;
|
|
102
|
+
clientId: string;
|
|
103
|
+
}
|
|
104
|
+
interface GetSnapshotPayload {
|
|
105
|
+
sessionId: string;
|
|
106
|
+
sinceSeq?: number;
|
|
107
|
+
}
|
|
108
|
+
interface ClearSessionBufferPayload {
|
|
109
|
+
sessionId: string;
|
|
110
|
+
}
|
|
111
|
+
type SessionHostRequest = {
|
|
112
|
+
type: 'create_session';
|
|
113
|
+
payload: CreateSessionPayload;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'attach_session';
|
|
116
|
+
payload: AttachSessionPayload;
|
|
117
|
+
} | {
|
|
118
|
+
type: 'detach_session';
|
|
119
|
+
payload: DetachSessionPayload;
|
|
120
|
+
} | {
|
|
121
|
+
type: 'send_input';
|
|
122
|
+
payload: SendInputPayload;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'resize_session';
|
|
125
|
+
payload: ResizeSessionPayload;
|
|
126
|
+
} | {
|
|
127
|
+
type: 'stop_session';
|
|
128
|
+
payload: StopSessionPayload;
|
|
129
|
+
} | {
|
|
130
|
+
type: 'resume_session';
|
|
131
|
+
payload: ResumeSessionPayload;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'acquire_write';
|
|
134
|
+
payload: AcquireWritePayload;
|
|
135
|
+
} | {
|
|
136
|
+
type: 'release_write';
|
|
137
|
+
payload: ReleaseWritePayload;
|
|
138
|
+
} | {
|
|
139
|
+
type: 'get_snapshot';
|
|
140
|
+
payload: GetSnapshotPayload;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'clear_session_buffer';
|
|
143
|
+
payload: ClearSessionBufferPayload;
|
|
144
|
+
} | {
|
|
145
|
+
type: 'list_sessions';
|
|
146
|
+
payload?: {};
|
|
147
|
+
};
|
|
148
|
+
interface SessionHostResponse<T = unknown> {
|
|
149
|
+
success: boolean;
|
|
150
|
+
result?: T;
|
|
151
|
+
error?: string;
|
|
152
|
+
}
|
|
153
|
+
type SessionHostEvent = {
|
|
154
|
+
type: 'session_created';
|
|
155
|
+
sessionId: string;
|
|
156
|
+
record: SessionHostRecord;
|
|
157
|
+
} | {
|
|
158
|
+
type: 'session_started';
|
|
159
|
+
sessionId: string;
|
|
160
|
+
pid?: number;
|
|
161
|
+
} | {
|
|
162
|
+
type: 'session_resumed';
|
|
163
|
+
sessionId: string;
|
|
164
|
+
pid?: number;
|
|
165
|
+
} | {
|
|
166
|
+
type: 'session_output';
|
|
167
|
+
sessionId: string;
|
|
168
|
+
seq: number;
|
|
169
|
+
data: string;
|
|
170
|
+
} | {
|
|
171
|
+
type: 'session_cleared';
|
|
172
|
+
sessionId: string;
|
|
173
|
+
} | {
|
|
174
|
+
type: 'session_exit';
|
|
175
|
+
sessionId: string;
|
|
176
|
+
exitCode: number | null;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'session_stopped';
|
|
179
|
+
sessionId: string;
|
|
180
|
+
} | {
|
|
181
|
+
type: 'session_resized';
|
|
182
|
+
sessionId: string;
|
|
183
|
+
cols: number;
|
|
184
|
+
rows: number;
|
|
185
|
+
} | {
|
|
186
|
+
type: 'write_owner_changed';
|
|
187
|
+
sessionId: string;
|
|
188
|
+
owner: SessionWriteOwner | null;
|
|
189
|
+
} | {
|
|
190
|
+
type: 'client_attached';
|
|
191
|
+
sessionId: string;
|
|
192
|
+
client: SessionAttachedClient;
|
|
193
|
+
} | {
|
|
194
|
+
type: 'client_detached';
|
|
195
|
+
sessionId: string;
|
|
196
|
+
clientId: string;
|
|
197
|
+
};
|
|
198
|
+
interface SessionHostRequestEnvelope {
|
|
199
|
+
kind: 'request';
|
|
200
|
+
requestId: string;
|
|
201
|
+
request: SessionHostRequest;
|
|
202
|
+
}
|
|
203
|
+
interface SessionHostResponseEnvelope {
|
|
204
|
+
kind: 'response';
|
|
205
|
+
requestId: string;
|
|
206
|
+
response: SessionHostResponse;
|
|
207
|
+
}
|
|
208
|
+
interface SessionHostEventEnvelope {
|
|
209
|
+
kind: 'event';
|
|
210
|
+
event: SessionHostEvent;
|
|
211
|
+
}
|
|
212
|
+
type SessionHostWireEnvelope = SessionHostRequestEnvelope | SessionHostResponseEnvelope | SessionHostEventEnvelope;
|
|
213
|
+
|
|
214
|
+
interface SessionRingBufferOptions {
|
|
215
|
+
maxBytes?: number;
|
|
216
|
+
}
|
|
217
|
+
declare class SessionRingBuffer {
|
|
218
|
+
private maxBytes;
|
|
219
|
+
private chunks;
|
|
220
|
+
private nextSeq;
|
|
221
|
+
private totalBytes;
|
|
222
|
+
constructor(options?: SessionRingBufferOptions);
|
|
223
|
+
append(data: string): number;
|
|
224
|
+
snapshot(sinceSeq?: number): SessionBufferSnapshot;
|
|
225
|
+
getState(): {
|
|
226
|
+
scrollbackBytes: number;
|
|
227
|
+
snapshotSeq: number;
|
|
228
|
+
};
|
|
229
|
+
clear(): void;
|
|
230
|
+
restore(snapshot: {
|
|
231
|
+
seq: number;
|
|
232
|
+
text: string;
|
|
233
|
+
}): void;
|
|
234
|
+
private trim;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
declare class SessionHostRegistry {
|
|
238
|
+
private sessions;
|
|
239
|
+
createSession(payload: CreateSessionPayload): SessionHostRecord;
|
|
240
|
+
restoreSession(record: SessionHostRecord, snapshot?: {
|
|
241
|
+
seq: number;
|
|
242
|
+
text: string;
|
|
243
|
+
} | null): SessionHostRecord;
|
|
244
|
+
listSessions(): SessionHostRecord[];
|
|
245
|
+
getSession(sessionId: string): SessionHostRecord | null;
|
|
246
|
+
attachClient(payload: AttachSessionPayload): SessionHostRecord;
|
|
247
|
+
detachClient(payload: DetachSessionPayload): SessionHostRecord;
|
|
248
|
+
acquireWrite(payload: AcquireWritePayload): SessionHostRecord;
|
|
249
|
+
releaseWrite(payload: ReleaseWritePayload): SessionHostRecord;
|
|
250
|
+
appendOutput(sessionId: string, data: string): {
|
|
251
|
+
record: SessionHostRecord;
|
|
252
|
+
seq: number;
|
|
253
|
+
};
|
|
254
|
+
getSnapshot(sessionId: string, sinceSeq?: number): SessionBufferSnapshot;
|
|
255
|
+
clearBuffer(sessionId: string): SessionHostRecord;
|
|
256
|
+
markStarted(sessionId: string, pid?: number): SessionHostRecord;
|
|
257
|
+
markStopped(sessionId: string, lifecycle?: 'stopped' | 'failed'): SessionHostRecord;
|
|
258
|
+
setLifecycle(sessionId: string, lifecycle: 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted'): SessionHostRecord;
|
|
259
|
+
private requireSession;
|
|
260
|
+
private cloneRecord;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
declare function getWorkspaceLabel(workspace: string): string;
|
|
264
|
+
declare function buildRuntimeDisplayName(payload: Pick<CreateSessionPayload, 'displayName' | 'providerType' | 'workspace'>): string;
|
|
265
|
+
declare function buildRuntimeKey(payload: Pick<CreateSessionPayload, 'runtimeKey' | 'displayName' | 'providerType' | 'workspace'>, existingKeys: Iterable<string>): string;
|
|
266
|
+
declare function resolveRuntimeRecord(records: SessionHostRecord[], identifier: string): SessionHostRecord;
|
|
267
|
+
declare function formatRuntimeOwner(record: Pick<SessionHostRecord, 'writeOwner'>): string;
|
|
268
|
+
|
|
269
|
+
interface SessionHostEndpoint {
|
|
270
|
+
kind: 'unix' | 'pipe';
|
|
271
|
+
path: string;
|
|
272
|
+
}
|
|
273
|
+
declare function getDefaultSessionHostEndpoint(appName?: string): SessionHostEndpoint;
|
|
274
|
+
declare function createLineParser(onEnvelope: (envelope: SessionHostWireEnvelope) => void): (chunk: Buffer | string) => void;
|
|
275
|
+
interface SessionHostClientOptions {
|
|
276
|
+
endpoint?: SessionHostEndpoint;
|
|
277
|
+
appName?: string;
|
|
278
|
+
}
|
|
279
|
+
declare class SessionHostClient {
|
|
280
|
+
readonly endpoint: SessionHostEndpoint;
|
|
281
|
+
private socket;
|
|
282
|
+
private requestWaiters;
|
|
283
|
+
private eventListeners;
|
|
284
|
+
constructor(options?: SessionHostClientOptions);
|
|
285
|
+
connect(): Promise<void>;
|
|
286
|
+
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
287
|
+
request<T = unknown>(request: SessionHostRequest): Promise<SessionHostResponse<T>>;
|
|
288
|
+
close(): Promise<void>;
|
|
289
|
+
}
|
|
290
|
+
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
291
|
+
declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: SessionHostWireEnvelope): void;
|
|
292
|
+
|
|
293
|
+
export { type AcquireWritePayload, type AttachSessionPayload, type ClearSessionBufferPayload, type CreateSessionPayload, type DetachSessionPayload, type GetSnapshotPayload, type ReleaseWritePayload, type ResizeSessionPayload, type ResumeSessionPayload, type SendInputPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostEndpoint, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, buildRuntimeDisplayName, buildRuntimeKey, createLineParser, createResponseEnvelope, formatRuntimeOwner, getDefaultSessionHostEndpoint, getWorkspaceLabel, resolveRuntimeRecord, writeEnvelope };
|