@@ -113,6 +113,9 @@ interface IWorkerClient {
113113
114114 // Properties
115115 readonly currentFolder : string ;
116+
117+ // Clone Management
118+ clone ( ) : Promise < WorkerClient > ;
116119}
117120
118121// Worker thread code as a string
@@ -1254,4 +1257,42 @@ export class WorkerClient extends Worker implements IWorkerClient {
12541257 installationId : newInstallationId ,
12551258 } ;
12561259 }
1260+
1261+ /**
1262+ * Creates a clone of this worker client with a separate underlying client instance
1263+ * The clone will have the same configuration but a new name: ${original_worker_name}_clone
1264+ * @returns A new WorkerClient instance with separate client
1265+ */
1266+ async clone ( ) : Promise < WorkerClient > {
1267+ console . debug ( `[${ this . nameId } ] Creating clone of worker` ) ;
1268+
1269+ // Create the clone name
1270+ const cloneName = `${ this . name } _clone` ;
1271+
1272+ // Create a WorkerBase object with the same properties but new name
1273+ const cloneWorkerBase : WorkerBase = {
1274+ name : cloneName ,
1275+ sdk : this . sdk ,
1276+ folder : this . folder ,
1277+ walletKey : this . walletKey ,
1278+ encryptionKey : this . encryptionKeyHex ,
1279+ } ;
1280+
1281+ // Create a new WorkerClient instance with the same configuration
1282+ const clonedWorker = new WorkerClient (
1283+ cloneWorkerBase ,
1284+ this . env ,
1285+ { } , // Use default worker options
1286+ this . apiUrl ,
1287+ ) ;
1288+
1289+ // Initialize the cloned worker to create its client instance
1290+ await clonedWorker . initialize ( ) ;
1291+
1292+ console . debug (
1293+ `[${ this . nameId } ] Successfully created clone: ${ clonedWorker . nameId } ` ,
1294+ ) ;
1295+
1296+ return clonedWorker ;
1297+ }
12571298}
0 commit comments