@nextclaw/remote 0.1.76 → 0.1.78
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.ts +186 -177
- package/dist/index.js +1012 -1190
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,236 +1,245 @@
|
|
|
1
|
-
import { Config } from
|
|
2
|
-
import { Command } from
|
|
1
|
+
import { Config } from "@nextclaw/core";
|
|
2
|
+
import { Command } from "commander";
|
|
3
3
|
|
|
4
|
+
//#region src/types.d.ts
|
|
4
5
|
type RemoteConnectCommandOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
apiBase?: string;
|
|
7
|
+
localOrigin?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
once?: boolean;
|
|
9
10
|
};
|
|
10
11
|
type RemoteEnableCommandOptions = {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
apiBase?: string;
|
|
13
|
+
name?: string;
|
|
13
14
|
};
|
|
14
15
|
type RemoteStatusCommandOptions = {
|
|
15
|
-
|
|
16
|
+
json?: boolean;
|
|
16
17
|
};
|
|
17
18
|
type RemoteDoctorCommandOptions = {
|
|
18
|
-
|
|
19
|
+
json?: boolean;
|
|
19
20
|
};
|
|
20
21
|
type RemoteRuntimeState = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
mode: "service" | "foreground";
|
|
24
|
+
state: "disabled" | "connecting" | "connected" | "disconnected" | "error";
|
|
25
|
+
deviceId?: string;
|
|
26
|
+
deviceName?: string;
|
|
27
|
+
platformBase?: string;
|
|
28
|
+
localOrigin?: string;
|
|
29
|
+
lastConnectedAt?: string | null;
|
|
30
|
+
lastError?: string | null;
|
|
31
|
+
updatedAt: string;
|
|
31
32
|
};
|
|
32
33
|
type RemoteStatusSnapshot = {
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
configuredEnabled: boolean;
|
|
35
|
+
runtime: RemoteRuntimeState | null;
|
|
35
36
|
};
|
|
36
37
|
type RemoteLogger = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
info: (message: string) => void;
|
|
39
|
+
warn: (message: string) => void;
|
|
40
|
+
error: (message: string) => void;
|
|
40
41
|
};
|
|
41
42
|
type RemoteServiceStateView = {
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
pid: number;
|
|
44
|
+
uiPort?: number;
|
|
44
45
|
};
|
|
45
46
|
type RegisteredRemoteDevice = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
id: string;
|
|
48
|
+
deviceInstallId: string;
|
|
49
|
+
displayName: string;
|
|
50
|
+
platform: string;
|
|
51
|
+
appVersion: string;
|
|
52
|
+
localOrigin: string;
|
|
53
|
+
status: "online" | "offline";
|
|
54
|
+
lastSeenAt: string;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
updatedAt: string;
|
|
56
57
|
};
|
|
57
58
|
type RemoteStatusWriter = {
|
|
58
|
-
|
|
59
|
+
write: (next: Omit<RemoteRuntimeState, "mode" | "updatedAt">) => void;
|
|
59
60
|
};
|
|
60
61
|
type RemoteConnectorRunOptions = RemoteConnectCommandOptions & {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
mode?: "foreground" | "service";
|
|
64
|
+
autoReconnect?: boolean;
|
|
65
|
+
statusStore?: RemoteStatusWriter;
|
|
65
66
|
};
|
|
66
67
|
type RemoteRunContext = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
config: Config;
|
|
69
|
+
platformBase: string;
|
|
70
|
+
token: string;
|
|
71
|
+
localOrigin: string;
|
|
72
|
+
displayName: string;
|
|
73
|
+
deviceInstallId: string;
|
|
74
|
+
autoReconnect: boolean;
|
|
74
75
|
};
|
|
75
76
|
type RemotePlatformClientDeps = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
|
|
77
|
+
loadConfig: () => Config;
|
|
78
|
+
getDataDir: () => string;
|
|
79
|
+
getPackageVersion: () => string;
|
|
80
|
+
resolvePlatformBase: (rawApiBase: string) => string;
|
|
81
|
+
readManagedServiceState?: () => RemoteServiceStateView | null;
|
|
82
|
+
isProcessRunning?: (pid: number) => boolean;
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/register-remote-commands.d.ts
|
|
84
86
|
type RemoteCommandRuntime = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
enable: (opts?: RemoteEnableCommandOptions) => Promise<void>;
|
|
88
|
+
disable: () => Promise<void>;
|
|
89
|
+
status: (opts?: RemoteStatusCommandOptions) => Promise<void>;
|
|
90
|
+
doctor: (opts?: RemoteDoctorCommandOptions) => Promise<void>;
|
|
91
|
+
connect: (opts?: RemoteConnectCommandOptions) => Promise<void>;
|
|
90
92
|
};
|
|
91
93
|
declare function registerRemoteCommands(program: Command, runtime: RemoteCommandRuntime): void;
|
|
92
|
-
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/remote-runtime-actions.d.ts
|
|
93
96
|
type RemoteConfigChange = {
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
changed: boolean;
|
|
98
|
+
config: Config;
|
|
96
99
|
};
|
|
97
100
|
type RemoteCommandDriver = {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
connect: (opts?: RemoteConnectCommandOptions) => Promise<void>;
|
|
102
|
+
enableConfig: (opts?: RemoteEnableCommandOptions) => RemoteConfigChange;
|
|
103
|
+
disableConfig: () => RemoteConfigChange;
|
|
104
|
+
status: (opts?: RemoteStatusCommandOptions) => Promise<void>;
|
|
105
|
+
doctor: (opts?: RemoteDoctorCommandOptions) => Promise<void>;
|
|
103
106
|
};
|
|
104
107
|
declare class RemoteRuntimeActions {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
private readonly deps;
|
|
109
|
+
constructor(deps: {
|
|
110
|
+
appName: string;
|
|
111
|
+
initAuto: (source: string) => Promise<void>;
|
|
112
|
+
remoteCommands: RemoteCommandDriver;
|
|
113
|
+
restartBackgroundService: (reason: string) => Promise<boolean>;
|
|
114
|
+
hasRunningManagedService: () => boolean;
|
|
115
|
+
});
|
|
116
|
+
connect(opts?: RemoteConnectCommandOptions): Promise<void>;
|
|
117
|
+
enable(opts?: RemoteEnableCommandOptions): Promise<void>;
|
|
118
|
+
disable(): Promise<void>;
|
|
119
|
+
status(opts?: RemoteStatusCommandOptions): Promise<void>;
|
|
120
|
+
doctor(opts?: RemoteDoctorCommandOptions): Promise<void>;
|
|
118
121
|
}
|
|
119
|
-
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/remote-platform-client.d.ts
|
|
120
124
|
declare function normalizeOptionalString(value: unknown): string | undefined;
|
|
121
125
|
declare function delay(ms: number, signal?: AbortSignal): Promise<void>;
|
|
122
126
|
declare function redactWsUrl(url: string): string;
|
|
123
127
|
declare class RemotePlatformClient {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
private readonly deps;
|
|
129
|
+
constructor(deps: RemotePlatformClientDeps);
|
|
130
|
+
private get remoteDir();
|
|
131
|
+
private get devicePath();
|
|
132
|
+
resolveRunContext(opts: RemoteConnectorRunOptions): RemoteRunContext;
|
|
133
|
+
registerDevice(params: {
|
|
134
|
+
platformBase: string;
|
|
135
|
+
token: string;
|
|
136
|
+
deviceInstallId: string;
|
|
137
|
+
displayName: string;
|
|
138
|
+
localOrigin: string;
|
|
139
|
+
}): Promise<RegisteredRemoteDevice>;
|
|
140
|
+
private ensureDeviceInstallId;
|
|
141
|
+
private resolvePlatformAccess;
|
|
142
|
+
private resolveLocalOrigin;
|
|
143
|
+
private resolveDisplayName;
|
|
140
144
|
}
|
|
141
|
-
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/remote-relay-bridge.d.ts
|
|
142
147
|
type RelayRequestFrame = {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
type: "request";
|
|
149
|
+
requestId: string;
|
|
150
|
+
method: string;
|
|
151
|
+
path: string;
|
|
152
|
+
headers: Array<[string, string]>;
|
|
153
|
+
bodyBase64?: string;
|
|
149
154
|
};
|
|
150
155
|
declare class RemoteRelayBridge {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
private readonly localOrigin;
|
|
157
|
+
constructor(localOrigin: string);
|
|
158
|
+
ensureLocalUiHealthy(): Promise<void>;
|
|
159
|
+
forward(frame: RelayRequestFrame, socket: WebSocket): Promise<void>;
|
|
160
|
+
private createForwardHeaders;
|
|
161
|
+
requestBridgeCookie(): Promise<string | null>;
|
|
162
|
+
private sendStreamingResponse;
|
|
158
163
|
}
|
|
159
|
-
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/remote-connector.d.ts
|
|
160
166
|
declare class RemoteConnector {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
167
|
+
private readonly deps;
|
|
168
|
+
constructor(deps: {
|
|
169
|
+
platformClient: RemotePlatformClient;
|
|
170
|
+
relayBridgeFactory?: (localOrigin: string) => RemoteRelayBridge;
|
|
171
|
+
logger?: RemoteLogger;
|
|
172
|
+
createSocket?: (wsUrl: string) => WebSocket;
|
|
173
|
+
delayFn?: typeof delay;
|
|
174
|
+
random?: () => number;
|
|
175
|
+
});
|
|
176
|
+
private get logger();
|
|
177
|
+
private get delayFn();
|
|
178
|
+
private get random();
|
|
179
|
+
private createSocket;
|
|
180
|
+
private connectOnce;
|
|
181
|
+
private handleSocketMessage;
|
|
182
|
+
private parseRelayFrame;
|
|
183
|
+
private ensureDevice;
|
|
184
|
+
private writeRemoteState;
|
|
185
|
+
private runCycle;
|
|
186
|
+
run(opts?: RemoteConnectorRunOptions): Promise<void>;
|
|
181
187
|
}
|
|
182
|
-
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/remote-status-store.d.ts
|
|
183
190
|
declare function buildConfiguredRemoteState(config: Config): RemoteRuntimeState;
|
|
184
191
|
declare function resolveRemoteStatusSnapshot(params: {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
192
|
+
config: Config;
|
|
193
|
+
currentRemoteState?: RemoteRuntimeState | null;
|
|
194
|
+
fallbackDeviceName?: string;
|
|
188
195
|
}): RemoteStatusSnapshot;
|
|
189
196
|
declare class RemoteStatusStore implements RemoteStatusWriter {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
197
|
+
private readonly mode;
|
|
198
|
+
private readonly deps;
|
|
199
|
+
constructor(mode: RemoteRuntimeState["mode"], deps: {
|
|
200
|
+
writeRemoteState: (next: RemoteRuntimeState) => void;
|
|
201
|
+
});
|
|
202
|
+
write(next: Omit<RemoteRuntimeState, "mode" | "updatedAt">): void;
|
|
196
203
|
}
|
|
197
|
-
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/remote-service-module.d.ts
|
|
198
206
|
declare class RemoteServiceModule {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
207
|
+
private readonly deps;
|
|
208
|
+
private abortController;
|
|
209
|
+
private runTask;
|
|
210
|
+
private releaseOwnership;
|
|
211
|
+
constructor(deps: {
|
|
212
|
+
loadConfig: () => Config;
|
|
213
|
+
uiEnabled: boolean;
|
|
214
|
+
localOrigin: string;
|
|
215
|
+
statusStore: RemoteStatusWriter;
|
|
216
|
+
createConnector: (logger: RemoteLogger) => RemoteConnector;
|
|
217
|
+
claimOwnership?: () => {
|
|
218
|
+
ok: true;
|
|
219
|
+
release: () => void;
|
|
220
|
+
} | {
|
|
221
|
+
ok: false;
|
|
222
|
+
error: string;
|
|
223
|
+
};
|
|
224
|
+
logger?: RemoteLogger;
|
|
225
|
+
});
|
|
226
|
+
start(): Promise<void> | null;
|
|
227
|
+
restart(): Promise<void>;
|
|
228
|
+
stop(): Promise<void>;
|
|
221
229
|
}
|
|
222
|
-
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/platform-session-token.d.ts
|
|
223
232
|
type PlatformSessionTokenState = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
233
|
+
valid: false;
|
|
234
|
+
reason: "missing" | "malformed" | "expired";
|
|
235
|
+
payload: Record<string, unknown> | null;
|
|
227
236
|
} | {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
237
|
+
valid: true;
|
|
238
|
+
reason: "valid";
|
|
239
|
+
payload: Record<string, unknown>;
|
|
231
240
|
};
|
|
232
241
|
declare function decodePlatformSessionTokenPayload(token: string): Record<string, unknown> | null;
|
|
233
242
|
declare function readPlatformSessionTokenState(token: string | null | undefined): PlatformSessionTokenState;
|
|
234
243
|
declare function isValidPlatformSessionToken(token: string | null | undefined): token is string;
|
|
235
|
-
|
|
236
|
-
export {
|
|
244
|
+
//#endregion
|
|
245
|
+
export { PlatformSessionTokenState, RegisteredRemoteDevice, RelayRequestFrame, RemoteConnectCommandOptions, RemoteConnector, RemoteConnectorRunOptions, RemoteDoctorCommandOptions, RemoteEnableCommandOptions, RemoteLogger, RemotePlatformClient, RemotePlatformClientDeps, RemoteRelayBridge, RemoteRunContext, RemoteRuntimeActions, RemoteRuntimeState, RemoteServiceModule, RemoteServiceStateView, RemoteStatusCommandOptions, RemoteStatusSnapshot, RemoteStatusStore, RemoteStatusWriter, buildConfiguredRemoteState, decodePlatformSessionTokenPayload, delay, isValidPlatformSessionToken, normalizeOptionalString, readPlatformSessionTokenState, redactWsUrl, registerRemoteCommands, resolveRemoteStatusSnapshot };
|