diff --git a/README.md b/README.md index 83161b4..44490c2 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,59 @@ # Introduction -An interface around the caml files produced by the `howso-engine` releases. +An interface surrounding `@howso/amalgam-lang` WASM to create a simplified client. ## Getting Started ### Install dependencies ```bash -npm install +npm install @howso/engine +``` + +### Create a client using a Worker + +```ts +import { AmalgamWasmService, initRuntime } from "@howso/amalgam-lang"; +import wasmDataUri from "@howso/amalgam-lang/lib/amalgam-st.data?url"; +import wasmUri from "@howso/amalgam-lang/lib/amalgam-st.wasm?url"; + +(async function () { + const svc = new AmalgamWasmService((options) => { + return initRuntime(options, { + locateFile: (path: string) => { + // Override file paths so we can use hashed version in build + if (path.endsWith("amalgam-st.wasm")) { + return wasmUri; + } else if (path.endsWith("amalgam-st.data")) { + return wasmDataUri; + } + return self.location.href + path; + }, + }); + }); + self.onmessage = async (ev) => { + svc.dispatch(ev); + }; + self.postMessage({ type: "event", event: "ready" }); +})(); +``` + +You can then create the worker client using a url import: + +```ts +import howsoUrl from "@/data/engine/howso.caml?url"; +import migrationsUrl from "@/data/engine/migrations.caml?url"; +import { type ClientOptions, Trainee, WasmClient } from "@howso/engine/wasm"; + +const getClient = async (): WasmClient => { + const worker = new Worker(new URL("@/workers/AmalgamWorker", import.meta.url), { type: "module" }); + const client = new WasmClient(worker, { + howsoUrl, + migrationsUrl, + ...options, + }); + return client.setup(); +}; ``` ## Build and Test diff --git a/package-lock.json b/package-lock.json index 431a57d..c13d6bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "license": "AGPL-3.0-only", "dependencies": { - "@howso/amalgam-lang": "^54.2.1", + "@howso/amalgam-lang": "^54.3.17", "@howso/openapi-client": "^2.0.1", "@microsoft/fetch-event-source": "^2.0.1", "uuid": "^9.0.0" @@ -97,9 +97,9 @@ } }, "node_modules/@howso/amalgam-lang": { - "version": "54.2.1", - "resolved": "https://dpbuild.jfrog.io/artifactory/api/npm/npm-virtual/@howso/amalgam-lang/-/@howso/amalgam-lang-54.2.1.tgz", - "integrity": "sha512-fWXjjVrFRJvgRKQ0z4Cb99mmJIqka2CJ313FCul6wnVmbMMaDiJ92ffFDBjhJsR/VCAqIn1RcLzBr49RzpiA6Q==" + "version": "54.3.17", + "resolved": "https://dpbuild.jfrog.io/artifactory/api/npm/npm-virtual/@howso/amalgam-lang/-/@howso/amalgam-lang-54.3.17.tgz", + "integrity": "sha512-ALMFB2Cxe78T2qM4eES3nmBtka5HlYuigPtJV4QJLDGoo7iIIp7ocnF3hxByhIPIBCYKLzM/1QtNsywibh6Tyw==" }, "node_modules/@howso/openapi-client": { "version": "2.0.1", @@ -1438,12 +1438,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -2213,9 +2213,9 @@ "dev": true }, "@howso/amalgam-lang": { - "version": "54.2.1", - "resolved": "https://dpbuild.jfrog.io/artifactory/api/npm/npm-virtual/@howso/amalgam-lang/-/@howso/amalgam-lang-54.2.1.tgz", - "integrity": "sha512-fWXjjVrFRJvgRKQ0z4Cb99mmJIqka2CJ313FCul6wnVmbMMaDiJ92ffFDBjhJsR/VCAqIn1RcLzBr49RzpiA6Q==" + "version": "54.3.17", + "resolved": "https://dpbuild.jfrog.io/artifactory/api/npm/npm-virtual/@howso/amalgam-lang/-/@howso/amalgam-lang-54.3.17.tgz", + "integrity": "sha512-ALMFB2Cxe78T2qM4eES3nmBtka5HlYuigPtJV4QJLDGoo7iIIp7ocnF3hxByhIPIBCYKLzM/1QtNsywibh6Tyw==" }, "@howso/openapi-client": { "version": "2.0.1", @@ -3172,12 +3172,12 @@ "dev": true }, "micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "requires": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" } }, diff --git a/package.json b/package.json index 2582b83..87fce0d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lint": "tsc --noEmit && eslint 'src/**'", "lint:fix": "eslint --fix 'src/**'", "prepack": "npm run build", - "test": "tsc --noEmit && eslint 'src/**'" + "test": "tsc --noEmit" }, "files": [ "LICENSE.txt", @@ -37,7 +37,7 @@ "./package.json": "./package.json" }, "dependencies": { - "@howso/amalgam-lang": "^54.2.1", + "@howso/amalgam-lang": "^54.3.17", "@howso/openapi-client": "^2.0.1", "@microsoft/fetch-event-source": "^2.0.1", "uuid": "^9.0.0" diff --git a/src/client/wasm/client.ts b/src/client/wasm/client.ts index 85b0385..449daf1 100644 --- a/src/client/wasm/client.ts +++ b/src/client/wasm/client.ts @@ -1,66 +1,66 @@ -import type { AmalgamRequest, AmalgamResponseBody, AmalgamCommand } from "@howso/amalgam-lang/worker"; -import type { Capabilities, ITraineeClient, ISessionClient } from "../capabilities/index.js"; -import { AmalgamCoreResponse, prepareCoreRequest, prepareCoreResponse } from "./core.js"; -import { AmalgamOptions } from "@howso/amalgam-lang/wasm"; +import type { AmalgamCommand, AmalgamOptions, AmalgamRequest, AmalgamResponseBody } from "@howso/amalgam-lang"; +import { AmalgamError } from "@howso/amalgam-lang"; +import { SetAutoAblationParamsRequest } from "@howso/openapi-client"; import { AnalyzeRequest, + AnalyzeRequestToJSON, + CaseCountResponse, Cases, CasesRequest, - CaseCountResponse, + CasesRequestToJSON, FeatureAttributes, + FeatureAttributesFromJSON, + FeatureAttributesToJSON, + FeatureConviction, + FeatureConvictionRequest, + FeatureConvictionRequestToJSON, FeatureMarginalStats, + FeatureMarginalStatsFromJSON, FeatureMarginalStatsRequest, - TrainRequest, - TrainResponse, + FeatureMarginalStatsRequestToJSON, + ReactAggregateRequest, + ReactAggregateRequestToJSON, + ReactAggregateResponse, + ReactAggregateResponseContent, + ReactAggregateResponseFromJSON, + ReactIntoFeaturesRequest, + ReactIntoFeaturesRequestToJSON, + ReactIntoFeaturesResponse, + ReactIntoFeaturesResponseFromJSON, ReactRequest, + ReactRequestToJSON, ReactResponse, ReactResponseContent, + ReactResponseFromJSON, ReactSeriesRequest, + ReactSeriesRequestToJSON, ReactSeriesResponse, ReactSeriesResponseContent, + ReactSeriesResponseFromJSON, Session, SessionIdentity, - SetAutoAnalyzeParamsRequest, - TraineeIdentity, - ReactIntoFeaturesRequest, - ReactIntoFeaturesResponse, - FeatureConviction, - FeatureConvictionRequest, - CasesRequestToJSON, - FeatureAttributesToJSON, - FeatureAttributesFromJSON, - FeatureMarginalStatsFromJSON, - FeatureMarginalStatsRequestToJSON, SessionToJSON, + SetAutoAnalyzeParamsRequest, SetAutoAnalyzeParamsRequestToJSON, - TraineeToJSON, TraineeFromJSON, - TrainRequestToJSON, - ReactRequestToJSON, - ReactResponseFromJSON, - ReactSeriesRequestToJSON, - ReactSeriesResponseFromJSON, - ReactIntoFeaturesRequestToJSON, - ReactIntoFeaturesResponseFromJSON, - FeatureConvictionRequestToJSON, - AnalyzeRequestToJSON, - ReactAggregateResponse, - ReactAggregateRequest, - ReactAggregateResponseContent, - ReactAggregateResponseFromJSON, - ReactAggregateRequestToJSON, - TraineeWorkflowAttributesRequest, + TraineeIdentity, + TraineeToJSON, TraineeWorkflowAttributesFromJSON, + TraineeWorkflowAttributesRequest, TraineeWorkflowAttributesRequestToJSON, + TrainRequest, + TrainRequestToJSON, + TrainResponse, } from "@howso/openapi-client/models"; -import { RequiredError, mapValues } from "@howso/openapi-client/runtime"; +import { mapValues, RequiredError } from "@howso/openapi-client/runtime"; import { v4 as uuid } from "uuid"; import { Trainee } from "../../trainees/index.js"; import { BaseClient, TraineeBaseCache } from "../capabilities/index"; +import type { Capabilities, ISessionClient, ITraineeClient } from "../capabilities/index.js"; import { ProblemError } from "../errors"; -import { CacheMap, isNode, batcher, BatchOptions } from "../utilities/index"; +import { batcher, BatchOptions, CacheMap, isNode } from "../utilities/index"; +import { AmalgamCoreResponse, prepareCoreRequest, prepareCoreResponse } from "./core.js"; import { FileSystemClient } from "./files"; -import { AmalgamError } from "@howso/amalgam-lang"; export interface TraineeCache extends TraineeBaseCache {} @@ -633,6 +633,28 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl return TraineeWorkflowAttributesFromJSON(response); } + /** + * Set the parameters use by auto analyze. + * @param traineeId The trainee identifier. + * @param request The analysis parameters. + */ + public async setAutoAblationParams( + traineeId: string, + request: Omit, + ): Promise { + await this.autoResolveTrainee(traineeId); + + await this.execute( + traineeId, + "set_auto_ablation_params", + JSON.stringify({ + trainee_id: traineeId, + ...request, + }), + ); + await this.autoPersistTrainee(traineeId); + } + /** * Set the parameters use by auto analyze. * @param traineeId The trainee identifier. diff --git a/src/client/wasm/files.ts b/src/client/wasm/files.ts index 17ab9b8..103a322 100644 --- a/src/client/wasm/files.ts +++ b/src/client/wasm/files.ts @@ -1,10 +1,10 @@ import type { - IFileSystem, FileSystemOperation, FileSystemRequest, FileSystemResponse, FileSystemResponseBody, -} from "@howso/amalgam-lang/worker"; + IFileSystem, +} from "@howso/amalgam-lang"; import { isNode } from "../utilities/detectors.js"; export class FileSystemClient implements IFileSystem {