import {
asEventLogHandleId,
asOCELHandleId,
asDFGHandleId,
asPetriNetHandleId,
asDeclareHandleId,
asTemporalProfileHandleId,
asNGramPredictorHandleId,
asStreamingDFGHandleId,
asStreamingConformanceHandleId,
} from './types.js';
export function parseWasm4pmError(error) {
if (typeof error === 'string') {
try {
const parsed = JSON.parse(error);
if (parsed.code && parsed.message) {
return { code: parsed.code, message: parsed.message };
}
} catch {
}
return { code: 'UNKNOWN_ERROR', message: error };
}
if (error instanceof Error) {
return { code: 'ERROR', message: error.message };
}
return { code: 'UNKNOWN_ERROR', message: String(error) };
}
export class ProcessMiningClient {
constructor() {
this.initialized = false;
this.wasmModule = null;
this.objects = new Map();
}
async init() {
if (this.initialized) {
return;
}
try {
if (typeof globalThis !== 'undefined' && globalThis.wasm4pm) {
this.wasmModule = globalThis.wasm4pm;
}
this.initialized = true;
} catch (error) {
throw new Error(`Failed to initialize wasm4pm: ${error}`);
}
}
loadEventLogFromJSON(jsonContent) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const handle = asEventLogHandleId(this.wasmModule.load_eventlog_from_json(jsonContent));
return new EventLogHandle(handle, this.wasmModule);
}
loadEventLogFromXES(xesContent) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const handle = asEventLogHandleId(this.wasmModule.load_eventlog_from_xes(xesContent));
return new EventLogHandle(handle, this.wasmModule);
}
loadOCELFromJSON(jsonContent) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const handle = asOCELHandleId(this.wasmModule.load_ocel_from_json(jsonContent));
return new OCELHandle(handle, this.wasmModule);
}
loadOCELFromXML(xmlContent) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const handle = asOCELHandleId(this.wasmModule.load_ocel_from_xml(xmlContent));
return new OCELHandle(handle, this.wasmModule);
}
discoverTemporalProfile(log, options = {}) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const activityKey = options.activityKey || 'concept:name';
const timestampKey = options.timestampKey || 'time:timestamp';
const handle = asTemporalProfileHandleId(
this.wasmModule.discover_temporal_profile(log.getId(), activityKey, timestampKey)
);
return new TemporalProfileHandle(handle, this.wasmModule);
}
buildNGramPredictor(log, options = {}) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const activityKey = options.activityKey || 'concept:name';
const n = options.n || 3;
const handle = asNGramPredictorHandleId(
this.wasmModule.build_ngram_predictor(log.getId(), activityKey, n)
);
return new NGramPredictorHandle(handle, this.wasmModule);
}
buildRemainingTimeModel(log, options = {}) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const activityKey = options.activityKey || 'concept:name';
const timestampKey = options.timestampKey || 'time:timestamp';
const handle = this.wasmModule.build_remaining_time_model(
log.getId(),
activityKey,
timestampKey
);
return new RemainingTimeModelHandle(handle, this.wasmModule);
}
beginStreamingDFG() {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const handle = asStreamingDFGHandleId(this.wasmModule.streaming_dfg_begin());
return new StreamingDFGHandle(handle, this.wasmModule);
}
beginStreamingConformance(dfg) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
const handle = asStreamingConformanceHandleId(
this.wasmModule.streaming_conformance_begin(dfg.getId())
);
return new StreamingConformanceHandle(handle, this.wasmModule);
}
getCapabilityRegistry() {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
return this.wasmModule.get_capability_registry();
}
analyzeOCPerformance(ocel) {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
return this.wasmModule.oc_performance_analysis(ocel.getId());
}
getVersion() {
if (!this.initialized) throw new Error('Client not initialized. Call init() first.');
return this.wasmModule.get_version();
}
}
export class EventLogHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
getStats() {
try {
return this.wasmModule.analyze_event_statistics(this.handle);
} catch (error) {
throw new Error(`Failed to get event log statistics: ${error}`);
}
}
getTraceCount() {
return this.wasmModule.get_trace_count(this.handle);
}
getEventCount() {
return this.wasmModule.get_event_count(this.handle);
}
getActivities(activityKey = 'concept:name') {
return this.wasmModule.get_activities(this.handle, activityKey);
}
getTraceLengthStats(activityKey = 'concept:name') {
return this.wasmModule.get_trace_length_statistics(this.handle);
}
getActivityFrequencies(activityKey = 'concept:name') {
return this.wasmModule.get_activity_frequencies(this.handle, activityKey);
}
getAttributeNames() {
return this.wasmModule.get_attribute_names(this.handle);
}
filterByActivity(activity, activityKey = 'concept:name') {
const result = this.wasmModule.filter_log_by_activity(this.handle, activityKey, activity);
return new EventLogHandle(asEventLogHandleId(result.handle), this.wasmModule);
}
filterByTraceLength(minLength, maxLength) {
const result = this.wasmModule.filter_log_by_trace_length(this.handle, minLength, maxLength);
return new EventLogHandle(asEventLogHandleId(result.handle), this.wasmModule);
}
discoverDFG(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const minFrequency = options.minFrequency || 1;
const result = this.wasmModule.discover_dfg_filtered(this.handle, activityKey, minFrequency);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
discoverDECLARE(activityKey = 'concept:name') {
const result = this.wasmModule.discover_declare(this.handle, activityKey);
return new DeclareModelHandle(asDeclareHandleId(result.handle), this.wasmModule);
}
discoverAlphaPlusPlus(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const minSupport = options.minSupport || 0.1;
const result = this.wasmModule.discover_alpha_plus_plus(this.handle, activityKey, minSupport);
return new PetriNetHandle(asPetriNetHandleId(result.handle), this.wasmModule);
}
discoverILPPetriNet(activityKey = 'concept:name') {
const result = this.wasmModule.discover_ilp_petri_net(this.handle, activityKey);
return new PetriNetHandle(asPetriNetHandleId(result.handle), this.wasmModule);
}
discoverOptimizedDFG(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const fitnessWeight = options.fitnessWeight || 0.7;
const simplicityWeight = options.simplicityWeight || 0.3;
const result = this.wasmModule.discover_optimized_dfg(
this.handle,
activityKey,
fitnessWeight,
simplicityWeight
);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
discoverGeneticAlgorithm(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const populationSize = options.populationSize || 50;
const generations = options.generations || 20;
const result = this.wasmModule.discover_genetic_algorithm(
this.handle,
activityKey,
populationSize,
generations
);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
discoverPSOAlgorithm(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const swarmSize = options.swarmSize || 30;
const iterations = options.iterations || 50;
const result = this.wasmModule.discover_pso_algorithm(
this.handle,
activityKey,
swarmSize,
iterations
);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
discoverAStar(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const maxIterations = options.maxIterations || 1000;
const result = this.wasmModule.discover_astar(this.handle, activityKey, maxIterations);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
discoverHillClimbing(activityKey = 'concept:name') {
const result = this.wasmModule.discover_hill_climbing(this.handle, activityKey);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
getTraceVariants(activityKey = 'concept:name') {
return this.wasmModule.analyze_trace_variants(this.handle, activityKey);
}
mineSequentialPatterns(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const minSupport = options.minSupport || 0.01;
const patternLength = options.patternLength || 3;
return this.wasmModule.mine_sequential_patterns(
this.handle,
activityKey,
minSupport,
patternLength
);
}
detectConceptDrift(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const windowSize = options.windowSize || 50;
return this.wasmModule.detect_concept_drift(this.handle, activityKey, windowSize);
}
clusterTraces(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const numClusters = options.numClusters || 5;
return this.wasmModule.cluster_traces(this.handle, activityKey, numClusters);
}
getStartEndActivities(activityKey = 'concept:name') {
return this.wasmModule.analyze_start_end_activities(this.handle, activityKey);
}
getActivityCooccurrence(activityKey = 'concept:name') {
return this.wasmModule.analyze_activity_cooccurrence(this.handle, activityKey);
}
discoverInductiveMiner(activityKey = 'concept:name') {
const result = this.wasmModule.discover_inductive_miner(this.handle, activityKey);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
discoverAntColony(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const numAnts = options.numAnts || 20;
const iterations = options.iterations || 10;
const result = this.wasmModule.discover_ant_colony(
this.handle,
activityKey,
numAnts,
iterations
);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
discoverSimulatedAnnealing(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const temperature = options.temperature || 100.0;
const coolingRate = options.coolingRate || 0.95;
const result = this.wasmModule.discover_simulated_annealing(
this.handle,
activityKey,
temperature,
coolingRate
);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
extractProcessSkeleton(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const minFrequency = options.minFrequency || 2;
const result = this.wasmModule.extract_process_skeleton(this.handle, activityKey, minFrequency);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
getActivityDependencies(activityKey = 'concept:name') {
return this.wasmModule.analyze_activity_dependencies(this.handle, activityKey);
}
getCaseAttributeAnalysis(activityKey = 'concept:name') {
return this.wasmModule.analyze_case_attributes(this.handle, activityKey);
}
getVariantComplexity(activityKey = 'concept:name') {
return this.wasmModule.analyze_variant_complexity(this.handle, activityKey);
}
getTransitionMatrix(activityKey = 'concept:name') {
return this.wasmModule.compute_activity_transition_matrix(this.handle, activityKey);
}
analyzeProcessSpeedup(options = {}) {
const timestampKey = options.timestampKey || 'time:timestamp';
const windowSize = options.windowSize || 50;
return this.wasmModule.analyze_process_speedup(this.handle, timestampKey, windowSize);
}
getTraceSimilarityMatrix(activityKey = 'concept:name') {
return this.wasmModule.compute_trace_similarity_matrix(this.handle, activityKey);
}
getTemporalBottlenecks(options = {}) {
const activityKey = options.activityKey || 'concept:name';
const timestampKey = options.timestampKey || 'time:timestamp';
return this.wasmModule.analyze_temporal_bottlenecks(this.handle, activityKey, timestampKey);
}
getActivityOrdering(activityKey = 'concept:name') {
return this.wasmModule.extract_activity_ordering(this.handle, activityKey);
}
getDottedChart(activityKey = 'concept:name') {
return this.wasmModule.analyze_dotted_chart(this.handle);
}
calculateCaseDurations(timestampKey = 'time:timestamp') {
return this.wasmModule.calculate_trace_durations(this.handle, timestampKey);
}
hasTimestamps(timestampKey = 'time:timestamp') {
return this.wasmModule.validate_has_timestamps(this.handle, timestampKey);
}
hasActivities(activityKey = 'concept:name') {
return this.wasmModule.validate_has_activities(this.handle, activityKey);
}
toJSON() {
return this.wasmModule.export_eventlog_to_json(this.handle);
}
toXES() {
return this.wasmModule.export_eventlog_to_xes(this.handle);
}
extractCaseFeatures(
activityKey = 'concept:name',
timestampKey = 'time:timestamp',
config = { features: [], target: 'outcome' }
) {
try {
const result = this.wasmModule.extract_case_features(
this.handle,
activityKey,
timestampKey,
JSON.stringify(config)
);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to extract case features: ${error}`));
}
}
extractPrefixFeatures(
activityKey = 'concept:name',
timestampKey = 'time:timestamp',
prefixLength = 5
) {
try {
const result = this.wasmModule.extract_prefix_features(
this.handle,
activityKey,
timestampKey,
prefixLength
);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to extract prefix features: ${error}`));
}
}
exportFeaturesAsCSV(
activityKey = 'concept:name',
timestampKey = 'time:timestamp',
config = { features: [], target: 'outcome' }
) {
try {
const featuresJson = this.wasmModule.export_features_json(
this.handle,
activityKey,
timestampKey,
JSON.stringify(config)
);
const result = this.wasmModule.export_features_csv(featuresJson);
return Promise.resolve(result);
} catch (error) {
return Promise.reject(new Error(`Failed to export features as CSV: ${error}`));
}
}
checkDataQuality(activityKey = 'concept:name', timestampKey = 'time:timestamp') {
try {
const result = this.wasmModule.check_data_quality(this.handle, activityKey, timestampKey);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to check data quality: ${error}`));
}
}
inferSchema() {
try {
const result = this.wasmModule.infer_eventlog_schema(this.handle);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to infer schema: ${error}`));
}
}
analyzeResourceUtilization(resourceKey = 'org:resource', timestampKey = 'time:timestamp') {
try {
const result = this.wasmModule.analyze_resource_utilization(
this.handle,
resourceKey,
timestampKey
);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to analyze resource utilization: ${error}`));
}
}
analyzeResourceActivityMatrix(resourceKey = 'org:resource', activityKey = 'concept:name') {
try {
const result = this.wasmModule.analyze_resource_activity_matrix(
this.handle,
resourceKey,
activityKey
);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to analyze resource-activity matrix: ${error}`));
}
}
identifyResourceBottlenecks(
resourceKey = 'org:resource',
timestampKey = 'time:timestamp',
activityKey = 'concept:name'
) {
try {
const result = this.wasmModule.identify_resource_bottlenecks(
this.handle,
resourceKey,
timestampKey,
activityKey
);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to identify resource bottlenecks: ${error}`));
}
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class OCELHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
getStats() {
return this.wasmModule.analyze_ocel_statistics(this.handle);
}
getEventCount() {
return this.wasmModule.get_ocel_event_count(this.handle);
}
getObjectCount() {
return this.wasmModule.get_ocel_object_count(this.handle);
}
discoverOCDFG(options = {}) {
const minFrequency = options.minFrequency || 1;
const result = this.wasmModule.discover_ocel_dfg(this.handle);
return new DFGHandle(asDFGHandleId(result.handle), this.wasmModule);
}
toJSON() {
return this.wasmModule.export_ocel_to_json(this.handle);
}
listObjectTypes() {
try {
const result = this.wasmModule.list_ocel_object_types(this.handle);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to list object types: ${error}`));
}
}
getTypeStatistics() {
try {
const result = this.wasmModule.get_ocel_type_statistics(this.handle);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to get type statistics: ${error}`));
}
}
flattenToEventLog(objectType) {
try {
const result = this.wasmModule.flatten_ocel_to_eventlog(this.handle, objectType);
return new EventLogHandle(asEventLogHandleId(result), this.wasmModule);
} catch (error) {
throw new Error(`Failed to flatten OCEL to EventLog: ${error}`);
}
}
discoverDFGPerType() {
try {
const result = this.wasmModule.discover_ocel_dfg_per_type(this.handle);
return Promise.resolve(JSON.parse(result));
} catch (error) {
return Promise.reject(new Error(`Failed to discover DFG per type: ${error}`));
}
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class DFGHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
toJSON() {
const json = this.wasmModule.export_dfg_to_json(this.handle);
return JSON.parse(json);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class PetriNetHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
toJSON() {
const json = this.wasmModule.export_petri_net_to_json(this.handle);
return JSON.parse(json);
}
checkConformance(log, activityKey = 'concept:name') {
return this.wasmModule.check_token_based_replay(log.getId(), this.handle, activityKey);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class DeclareModelHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
toJSON() {
const exportFn = this.wasmModule.export_declare_model_to_json;
if (!exportFn)
throw new Error('export_declare_model_to_json not available in current WASM build');
const json = exportFn(this.handle);
return JSON.parse(json);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class OCPetriNetHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
toJSON() {
const exportFn = this.wasmModule.export_oc_petri_net_to_json;
if (!exportFn)
throw new Error('export_oc_petri_net_to_json not available in current WASM build');
const json = exportFn(this.handle);
return JSON.parse(json);
}
toPNML() {
const exportFn = this.wasmModule.export_oc_petri_net_to_pnml;
if (!exportFn)
throw new Error('export_oc_petri_net_to_pnml not available in current WASM build');
return exportFn(this.handle);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class TemporalProfileHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
checkConformance(log, options = {}) {
const activityKey = options.activityKey || 'concept:name';
const timestampKey = options.timestampKey || 'time:timestamp';
const zeta = options.zeta || 2.0;
return this.wasmModule.check_temporal_conformance(
log.getId(),
this.handle,
activityKey,
timestampKey,
zeta
);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class NGramPredictorHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
predictNextActivity(prefix) {
return this.wasmModule.predict_next_activity(this.handle, JSON.stringify(prefix));
}
predictNextK(prefix, k) {
return JSON.parse(this.wasmModule.predict_next_k(this.handle, JSON.stringify(prefix), k));
}
predictBeamPaths(prefix, beamWidth, maxSteps) {
return JSON.parse(
this.wasmModule.predict_beam_paths(this.handle, JSON.stringify(prefix), beamWidth, maxSteps)
);
}
scoreTraceLikelihood(activities) {
return this.wasmModule.score_trace_likelihood(this.handle, JSON.stringify(activities));
}
computeTraceLikelihood(activities) {
return this.wasmModule.compute_trace_likelihood(this.handle, JSON.stringify(activities));
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class RemainingTimeModelHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
predictCaseDuration(prefix) {
return this.wasmModule.predict_case_duration(this.handle, JSON.stringify(prefix));
}
predictHazardRate(elapsedMs) {
return this.wasmModule.predict_hazard_rate(this.handle, elapsedMs);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class StreamingDFGHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
addEvent(caseId, activity) {
return this.wasmModule.streaming_dfg_add_event(this.handle, caseId, activity);
}
addBatch(eventsJson) {
return this.wasmModule.streaming_dfg_add_batch(this.handle, eventsJson);
}
closeTrace(caseId) {
return this.wasmModule.streaming_dfg_close_trace(this.handle, caseId);
}
flushOpen() {
return this.wasmModule.streaming_dfg_flush_open(this.handle);
}
snapshot() {
return this.wasmModule.streaming_dfg_snapshot(this.handle);
}
finalize() {
return this.wasmModule.streaming_dfg_finalize(this.handle);
}
stats() {
return this.wasmModule.streaming_dfg_stats(this.handle);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export class StreamingConformanceHandle {
constructor(handle, wasmModule) {
this.handle = handle;
this.wasmModule = wasmModule;
}
getId() {
return this.handle;
}
addEvent(caseId, activity) {
return this.wasmModule.streaming_conformance_add_event(this.handle, caseId, activity);
}
closeTrace(caseId) {
return this.wasmModule.streaming_conformance_close_trace(this.handle, caseId);
}
stats() {
return this.wasmModule.streaming_conformance_stats(this.handle);
}
finalize() {
return this.wasmModule.streaming_conformance_finalize(this.handle);
}
delete() {
this.wasmModule.delete_object(this.handle);
}
}
export async function loadFileAsText(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => resolve(e.target?.result);
reader.onerror = () => reject(new Error('Failed to read file'));
reader.readAsText(file);
});
}
let wasmModuleGlobal = null;
export function initializeWasm4pmModule(wasmModule) {
wasmModuleGlobal = wasmModule;
}
export async function encodeTextAsText(dfgHandle) {
if (!wasmModuleGlobal) {
throw new Error('WASM module not initialized. Call initializeWasm4pmModule() first.');
}
try {
return wasmModuleGlobal.encode_dfg_as_text(dfgHandle.getId());
} catch (error) {
throw new Error(`Failed to encode DFG as text: ${error}`);
}
}
export async function encodeVariantsAsText(logHandle, activityKey = 'concept:name', topN = 10) {
if (!wasmModuleGlobal) {
throw new Error('WASM module not initialized. Call initializeWasm4pmModule() first.');
}
try {
return wasmModuleGlobal.encode_variants_as_text(logHandle.getId(), activityKey, topN);
} catch (error) {
throw new Error(`Failed to encode variants as text: ${error}`);
}
}
export async function encodeLogAsText(logHandle) {
if (!wasmModuleGlobal) {
throw new Error('WASM module not initialized. Call initializeWasm4pmModule() first.');
}
try {
return wasmModuleGlobal.encode_statistics_as_text(logHandle.getId());
} catch (error) {
throw new Error(`Failed to encode log as text: ${error}`);
}
}
export async function encodePetriNetAsText(petriNetHandle) {
if (!wasmModuleGlobal) {
throw new Error('WASM module not initialized. Call initializeWasm4pmModule() first.');
}
try {
return wasmModuleGlobal.encode_petri_net_as_text(petriNetHandle.getId());
} catch (error) {
throw new Error(`Failed to encode Petri Net as text: ${error}`);
}
}
export async function encodeOCELAsText(ocelHandle) {
if (!wasmModuleGlobal) {
throw new Error('WASM module not initialized. Call initializeWasm4pmModule() first.');
}
try {
return wasmModuleGlobal.encode_ocel_as_text(ocelHandle.getId());
} catch (error) {
throw new Error(`Failed to encode OCEL as text: ${error}`);
}
}
export async function encodeOCPetriNetAsText(ocpnHandle) {
if (!wasmModuleGlobal) {
throw new Error('WASM module not initialized. Call initializeWasm4pmModule() first.');
}
try {
return wasmModuleGlobal.encode_oc_petri_net_as_text(ocpnHandle.getId());
} catch (error) {
throw new Error(`Failed to encode OC Petri Net as text: ${error}`);
}
}
export async function encodeModelComparisonAsText(model1Handle, model2Handle) {
if (!wasmModuleGlobal) {
throw new Error('WASM module not initialized. Call initializeWasm4pmModule() first.');
}
try {
const id1 = model1Handle instanceof DFGHandle ? model1Handle.getId() : model1Handle.getId();
const id2 = model2Handle instanceof DFGHandle ? model2Handle.getId() : model2Handle.getId();
return wasmModuleGlobal.encode_model_comparison_as_text(id1, id2);
} catch (error) {
throw new Error(`Failed to encode model comparison as text: ${error}`);
}
}
export function scoreAnomaly(dfgHandle, trace) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.score_anomaly(dfgHandle.getId(), JSON.stringify(trace));
}
export function computeBoundaryCoverage(logHandle, prefix, activityKey = 'concept:name') {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.compute_boundary_coverage(
logHandle.getId(),
JSON.stringify(prefix),
activityKey
);
}
export function detectDrift(logHandle, activityKey = 'concept:name', windowSize = 10) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return JSON.parse(wasmModuleGlobal.detect_drift(logHandle.getId(), activityKey, windowSize));
}
export function computeEwma(values, alpha = 0.3) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return JSON.parse(wasmModuleGlobal.compute_ewma(JSON.stringify(values), alpha));
}
export function extractPrefixFeatures(prefix) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.extract_prefix_features_wasm(JSON.stringify(prefix));
}
export function computeReworkScore(trace) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.compute_rework_score(JSON.stringify(trace));
}
export function buildTransitionProbabilities(logHandle, activityKey = 'concept:name') {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.build_transition_probabilities(logHandle.getId(), activityKey);
}
export function estimateQueueDelay(arrivalRate, serviceRate) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.estimate_queue_delay(arrivalRate, serviceRate);
}
export function rankInterventions(interventions, exploitationWeight = 0.7) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.rank_interventions(JSON.stringify(interventions), exploitationWeight);
}
export function selectIntervention(banditState, explorationFactor = Math.SQRT2) {
if (!wasmModuleGlobal) throw new Error('WASM module not initialized');
return wasmModuleGlobal.select_intervention(JSON.stringify(banditState), explorationFactor);
}