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