11using System . Runtime . InteropServices . JavaScript ;
2+ using System . Runtime . Intrinsics ;
23using System . Runtime . Versioning ;
34using System . Text . Json ;
45using Motely ;
56using Motely . Analysis ;
67using Motely . Executors ;
8+ using Motely . Filters ;
79
810namespace Motely . BrowserWasm ;
911
10- /// <summary>
11- /// Browser WASM exports. Thin wrappers around MotelyExports (shared orchestration).
12- /// Each method adds [JSExport] and async Task.Run so the browser thread isn't blocked.
13- /// </summary>
1412[ SupportedOSPlatform ( "browser" ) ]
1513public static partial class MotelyWasmExports
1614{
1715 private static CancellationTokenSource ? _activeCts ;
1816
19- // ── SEARCH (sequential) ──
17+ // ── SEARCH ──
2018
2119 [ JSExport ]
2220 public static Task < string > StartJamlSearch (
2321 string jamlContent , int threadCount , int batchCharCount ,
2422 int startBatch , int endBatch ,
2523 [ JSMarshalAs < JSType . Function < JSType . Number , JSType . Number , JSType . Number > > ] Action < long , long , long > onProgress ,
2624 [ JSMarshalAs < JSType . Function < JSType . String , JSType . Number > > ] Action < string , int > onResult )
27- {
28- return RunSearch ( jamlContent , new MotelySearchRequest
25+ => RunSearch ( jamlContent , new MotelySearchRequest
2926 {
3027 ThreadCount = ResolveThreads ( threadCount ) ,
3128 BatchCharCount = ResolveBatch ( batchCharCount ) ,
3229 StartBatch = startBatch >= 0 ? startBatch : null ,
3330 EndBatch = endBatch > 0 ? endBatch : null ,
3431 } , onProgress , onResult ) ;
35- }
36-
37- // ── SEARCH (seed list / verify) ──
3832
3933 [ JSExport ]
4034 public static Task < string > StartSeedListSearch (
4135 string jamlContent , int threadCount , int batchCharCount ,
4236 [ JSMarshalAs < JSType . Array < JSType . String > > ] string [ ] seeds ,
4337 [ JSMarshalAs < JSType . Function < JSType . Number , JSType . Number , JSType . Number > > ] Action < long , long , long > onProgress ,
4438 [ JSMarshalAs < JSType . Function < JSType . String , JSType . Number > > ] Action < string , int > onResult )
45- {
46- return RunSearch ( jamlContent , new MotelySearchRequest
39+ => RunSearch ( jamlContent , new MotelySearchRequest
4740 {
4841 ThreadCount = ResolveThreads ( threadCount ) ,
4942 BatchCharCount = ResolveBatch ( batchCharCount ) ,
5043 Seeds = seeds ,
5144 } , onProgress , onResult ) ;
52- }
53-
54- // ── SEARCH (keyword) ──
5545
5646 [ JSExport ]
5747 public static Task < string > StartKeywordSearch (
5848 string jamlContent , int threadCount , int batchCharCount ,
5949 [ JSMarshalAs < JSType . Array < JSType . String > > ] string [ ] keywords , string padding ,
6050 [ JSMarshalAs < JSType . Function < JSType . Number , JSType . Number , JSType . Number > > ] Action < long , long , long > onProgress ,
6151 [ JSMarshalAs < JSType . Function < JSType . String , JSType . Number > > ] Action < string , int > onResult )
62- {
63- return RunSearch ( jamlContent , new MotelySearchRequest
52+ => RunSearch ( jamlContent , new MotelySearchRequest
6453 {
6554 ThreadCount = ResolveThreads ( threadCount ) ,
6655 BatchCharCount = ResolveBatch ( batchCharCount ) ,
6756 Keywords = keywords ,
6857 Padding = string . IsNullOrEmpty ( padding ) ? null : padding ,
6958 } , onProgress , onResult ) ;
70- }
71-
72- // ── SEARCH (random) ──
7359
7460 [ JSExport ]
7561 public static Task < string > StartRandomSearch (
7662 string jamlContent , int threadCount , int batchCharCount , int count ,
7763 [ JSMarshalAs < JSType . Function < JSType . Number , JSType . Number , JSType . Number > > ] Action < long , long , long > onProgress ,
7864 [ JSMarshalAs < JSType . Function < JSType . String , JSType . Number > > ] Action < string , int > onResult )
79- {
80- return RunSearch ( jamlContent , new MotelySearchRequest
65+ => RunSearch ( jamlContent , new MotelySearchRequest
8166 {
8267 ThreadCount = ResolveThreads ( threadCount ) ,
8368 BatchCharCount = ResolveBatch ( batchCharCount ) ,
8469 RandomSeeds = count > 0 ? count : 1000 ,
8570 } , onProgress , onResult ) ;
86- }
87-
88- // ── SEARCH (palindrome) ──
8971
9072 [ JSExport ]
9173 public static Task < string > StartPalindromeSearch (
9274 string jamlContent , int threadCount , int batchCharCount ,
9375 [ JSMarshalAs < JSType . Function < JSType . Number , JSType . Number , JSType . Number > > ] Action < long , long , long > onProgress ,
9476 [ JSMarshalAs < JSType . Function < JSType . String , JSType . Number > > ] Action < string , int > onResult )
95- {
96- return RunSearch ( jamlContent , new MotelySearchRequest
77+ => RunSearch ( jamlContent , new MotelySearchRequest
9778 {
9879 ThreadCount = ResolveThreads ( threadCount ) ,
9980 BatchCharCount = ResolveBatch ( batchCharCount ) ,
10081 Palindrome = true ,
10182 } , onProgress , onResult ) ;
102- }
10383
10484 [ JSExport ]
10585 public static Task StopSearch ( )
@@ -115,7 +95,7 @@ public static Task<string> AnalyzeSeed(string seed, string deck, string stake)
11595 {
11696 try
11797 {
118- var dto = MotelyExports . AnalyzeSeed ( seed , deck , stake ) ;
98+ var dto = MotelySeedAnalyzer . AnalyzeToDto ( seed , deck , stake ) ;
11999 return Task . FromResult ( JsonSerializer . Serialize ( dto , AnalysisJsonContext . Default . SeedAnalysisDto ) ) ;
120100 }
121101 catch ( Exception ex )
@@ -126,31 +106,33 @@ public static Task<string> AnalyzeSeed(string seed, string deck, string stake)
126106 }
127107 }
128108
129- // ── SIMPLE GETTERS ──
109+ // ── GETTERS ──
130110
131111 [ JSExport ]
132- public static Task < string > GetVersion ( ) => Task . FromResult ( MotelyExports . GetVersion ( typeof ( MotelyCore ) . Assembly ) ) ;
112+ public static Task < string > GetVersion ( ) => Task . FromResult ( MotelyBuildVersion . For ( typeof ( MotelyCore ) . Assembly ) ) ;
133113
134114 [ JSExport ]
135- public static Task < bool > IsSimdEnabled ( ) => Task . FromResult ( MotelyExports . IsSimdEnabled ( ) ) ;
115+ public static Task < bool > IsSimdEnabled ( ) => Task . FromResult ( Vector128 . IsHardwareAccelerated ) ;
136116
137117 [ JSExport ]
138- public static Task < int > GetProcessorCount ( ) => Task . FromResult ( MotelyExports . GetProcessorCount ( ) ) ;
118+ public static Task < int > GetProcessorCount ( ) => Task . FromResult ( Environment . ProcessorCount ) ;
139119
140120 [ JSExport ]
141- public static Task < bool > ValidateJaml ( string jamlContent ) => Task . FromResult ( MotelyExports . ValidateJaml ( jamlContent ) ) ;
121+ public static Task < bool > ValidateJaml ( string jamlContent ) => Task . FromResult ( JamlConfigLoader . TryLoad ( jamlContent , out _ , out _ ) ) ;
142122
143123 [ JSExport ]
144- public static Task < string > ValidateJamlWithError ( string jamlContent ) => Task . FromResult ( MotelyExports . ValidateJamlWithError ( jamlContent ) ) ;
124+ public static Task < string > ValidateJamlWithError ( string jamlContent )
125+ {
126+ if ( JamlConfigLoader . TryLoad ( jamlContent , out _ , out var error ) )
127+ return Task . FromResult ( "" ) ;
128+ return Task . FromResult ( error ?? "Unknown validation error" ) ;
129+ }
145130
146131 // ── Internals ──
147132
148133 private static int ResolveThreads ( int t ) => t > 0 ? t : Environment . ProcessorCount ;
149134 private static int ResolveBatch ( int b ) => b is >= 1 and <= 7 ? b : 4 ;
150135
151- /// <summary>
152- /// Delegates to MotelyExports.RunSearch (shared orchestration) with cancellation + async.
153- /// </summary>
154136 private static async Task < string > RunSearch (
155137 string jamlContent , MotelySearchRequest request ,
156138 Action < long , long , long > onProgress , Action < string , int > onResult )
@@ -164,24 +146,11 @@ private static async Task<string> RunSearch(
164146 try
165147 {
166148 var ( status , _, _) = await Task . Run ( ( ) =>
167- MotelyExports . RunSearch ( jamlContent , request , onProgress , onResult , cts . Token ) ) ;
149+ MotelySearchOrchestrator . RunSearch ( jamlContent , request , onProgress , onResult , cts . Token ) ) ;
168150 return status ;
169151 }
170- catch ( OperationCanceledException )
171- {
172- return "cancelled" ;
173- }
174- catch ( InvalidOperationException ex )
175- {
176- return $ "error: { ex . Message } ";
177- }
178- catch ( Exception ex )
179- {
180- return $ "error: { ex . Message } ";
181- }
182- finally
183- {
184- _activeCts = null ;
185- }
152+ catch ( OperationCanceledException ) { return "cancelled" ; }
153+ catch ( Exception ex ) { return $ "error: { ex . Message } "; }
154+ finally { _activeCts = null ; }
186155 }
187156}
0 commit comments