happy-coder 0.10.0-0 → 0.10.0-2

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/lib.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { EventEmitter } from 'node:events';
3
+ import { Socket } from 'socket.io-client';
3
4
  import { ExpoPushMessage } from 'expo-server-sdk';
4
5
 
5
6
  /**
@@ -287,7 +288,80 @@ declare const RawJSONLinesSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
287
288
  }, z.ZodTypeAny, "passthrough">>]>;
288
289
  type RawJSONLines = z.infer<typeof RawJSONLinesSchema>;
289
290
 
290
- type RpcHandler<T = any, R = any> = (data: T) => R | Promise<R>;
291
+ /**
292
+ * Common RPC types and interfaces for both session and machine clients
293
+ */
294
+ /**
295
+ * Generic RPC handler function type
296
+ * @template TRequest - The request data type
297
+ * @template TResponse - The response data type
298
+ */
299
+ type RpcHandler<TRequest = any, TResponse = any> = (data: TRequest) => TResponse | Promise<TResponse>;
300
+ /**
301
+ * RPC request data from server
302
+ */
303
+ interface RpcRequest {
304
+ method: string;
305
+ params: string;
306
+ }
307
+ /**
308
+ * Configuration for RPC handler manager
309
+ */
310
+ interface RpcHandlerConfig {
311
+ /** Prefix to add to all method names (e.g., sessionId or machineId) */
312
+ scopePrefix: string;
313
+ /** Secret key for encryption/decryption */
314
+ secret: Uint8Array;
315
+ /** Logger function for debugging */
316
+ logger?: (message: string, data?: any) => void;
317
+ }
318
+
319
+ /**
320
+ * Generic RPC handler manager for session and machine clients
321
+ * Manages RPC method registration, encryption/decryption, and handler execution
322
+ */
323
+
324
+ declare class RpcHandlerManager {
325
+ private handlers;
326
+ private readonly scopePrefix;
327
+ private readonly secret;
328
+ private readonly logger;
329
+ private socket;
330
+ constructor(config: RpcHandlerConfig);
331
+ /**
332
+ * Register an RPC handler for a specific method
333
+ * @param method - The method name (without prefix)
334
+ * @param handler - The handler function
335
+ */
336
+ registerHandler<TRequest = any, TResponse = any>(method: string, handler: RpcHandler<TRequest, TResponse>): void;
337
+ /**
338
+ * Handle an incoming RPC request
339
+ * @param request - The RPC request data
340
+ * @param callback - The response callback
341
+ */
342
+ handleRequest(request: RpcRequest): Promise<any>;
343
+ onSocketConnect(socket: Socket): void;
344
+ onSocketDisconnect(): void;
345
+ /**
346
+ * Get the number of registered handlers
347
+ */
348
+ getHandlerCount(): number;
349
+ /**
350
+ * Check if a handler is registered
351
+ * @param method - The method name (without prefix)
352
+ */
353
+ hasHandler(method: string): boolean;
354
+ /**
355
+ * Clear all handlers
356
+ */
357
+ clearHandlers(): void;
358
+ /**
359
+ * Get the prefixed method name
360
+ * @param method - The method name
361
+ */
362
+ private getPrefixedMethod;
363
+ }
364
+
291
365
  declare class ApiSessionClient extends EventEmitter {
292
366
  private readonly token;
293
367
  private readonly secret;
@@ -299,7 +373,7 @@ declare class ApiSessionClient extends EventEmitter {
299
373
  private socket;
300
374
  private pendingMessages;
301
375
  private pendingMessageCallback;
302
- private rpcHandlers;
376
+ readonly rpcHandlerManager: RpcHandlerManager;
303
377
  private agentStateLock;
304
378
  private metadataLock;
305
379
  constructor(token: string, secret: Uint8Array, session: Session);
@@ -343,16 +417,6 @@ declare class ApiSessionClient extends EventEmitter {
343
417
  * @param handler - Handler function that returns the updated agent state
344
418
  */
345
419
  updateAgentState(handler: (metadata: AgentState) => AgentState): void;
346
- /**
347
- * Set a custom RPC handler for a specific method with encrypted arguments and responses
348
- * @param method - The method name to handle
349
- * @param handler - The handler function to call when the method is invoked
350
- */
351
- setHandler<T = any, R = any>(method: string, handler: RpcHandler<T, R>): void;
352
- /**
353
- * Re-register all RPC handlers after reconnection
354
- */
355
- private reregisterHandlers;
356
420
  /**
357
421
  * Wait for socket buffer to flush
358
422
  */
@@ -642,11 +706,6 @@ type AgentState = {
642
706
  };
643
707
  };
644
708
 
645
- /**
646
- * RPC handlers for API session communication
647
- * Handles remote procedure calls from mobile clients
648
- */
649
-
650
709
  interface SpawnSessionOptions {
651
710
  machineId?: string;
652
711
  directory: string;
@@ -680,9 +739,7 @@ declare class ApiMachineClient {
680
739
  private machine;
681
740
  private socket;
682
741
  private keepAliveInterval;
683
- private spawnSession?;
684
- private stopSession?;
685
- private requestShutdown?;
742
+ private rpcHandlerManager;
686
743
  constructor(token: string, secret: Uint8Array, machine: Machine);
687
744
  setRPCHandlers({ spawnSession, stopSession, requestShutdown }: MachineRpcHandlers): void;
688
745
  /**
@@ -753,7 +810,7 @@ declare class ApiClient {
753
810
  * Register or update machine with the server
754
811
  * Returns the current machine state from the server with decrypted metadata and daemonState
755
812
  */
756
- createMachineOrGetExistingAsIs(opts: {
813
+ getOrCreateMachine(opts: {
757
814
  machineId: string;
758
815
  metadata: MachineMetadata;
759
816
  daemonState?: DaemonState;
package/dist/lib.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ApiClient, a as ApiSessionClient, R as RawJSONLinesSchema, c as configuration, l as logger } from './types-CGbH1LGX.mjs';
1
+ export { A as ApiClient, a as ApiSessionClient, R as RawJSONLinesSchema, c as configuration, l as logger } from './types-xfXKJHdM.mjs';
2
2
  import 'axios';
3
3
  import 'chalk';
4
4
  import 'fs';
@@ -11,4 +11,10 @@ import 'node:crypto';
11
11
  import 'tweetnacl';
12
12
  import 'node:events';
13
13
  import 'socket.io-client';
14
+ import 'child_process';
15
+ import 'util';
16
+ import 'fs/promises';
17
+ import 'crypto';
18
+ import 'path';
19
+ import 'url';
14
20
  import 'expo-server-sdk';