diff --git a/src/index.ts b/src/index.ts index a9f0233..5a4554c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,14 +10,12 @@ export class ModelInfo { } export interface ModelFactory { - getModel>(modelName: string): T; + getModel(modelName: string): T; } -export abstract class Model { - protected constructor( - public readonly info: ModelInfo, - protected invoker: ModelInvoker, - ) {} +export abstract class Model { + static invoker: ModelInvoker | null = null; + protected constructor(public info: ModelInfo) {} debug: boolean = false; @@ -27,13 +25,17 @@ export abstract class Model { * @returns The output object from the model. */ invoke(input: TInput): TOutput { + if (!Model.invoker) { + throw new Error("Model invoker is not set."); + } + const modelName = this.info.name; const inputJson = JSON.stringify(input); if (this.debug) { console.debug(`Invoking ${modelName} model with input: ${inputJson}`); } - const outputJson = this.invoker(modelName, inputJson); + const outputJson = Model.invoker(modelName, inputJson); if (!outputJson) { throw new Error(`Failed to invoke ${modelName} model.`); } diff --git a/src/package-lock.json b/src/package-lock.json index c5139fe..1f1a84d 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,18 +1,18 @@ { "name": "@hypermode/models-as", - "version": "0.1.2", + "version": "0.1.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@hypermode/models-as", - "version": "0.1.2", + "version": "0.1.5", "license": "MIT", "dependencies": { "json-as": "^0.9.6" }, "devDependencies": { - "@types/node": "^20.14.4", + "@types/node": "^20.14.5", "@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/parser": "^7.13.1", "assemblyscript": "^0.27.27", @@ -208,9 +208,9 @@ } }, "node_modules/@types/node": { - "version": "20.14.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.4.tgz", - "integrity": "sha512-1ChboN+57suCT2t/f8lwtPY/k3qTpuD/qnqQuYoBg6OQOcPyaw7PiZVdGpaZYAvhDDtqrt0oAaM8+oSu1xsUGw==", + "version": "20.14.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.5.tgz", + "integrity": "sha512-aoRR+fJkZT2l0aGOJhuA8frnCSoNX6W7U2mpNq63+BxBIj5BQFt8rHy627kijCmm63ijdSdwvGgpUsU6MBsZZA==", "dev": true, "license": "MIT", "dependencies": { diff --git a/src/package.json b/src/package.json index 725d36c..d0fc135 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "@hypermode/models-as", - "version": "0.1.2", + "version": "0.1.5", "description": "Hypermode Model Interface Library for AssemblyScript", "author": "Hypermode, Inc.", "license": "MIT", @@ -17,7 +17,7 @@ "json-as": "^0.9.6" }, "devDependencies": { - "@types/node": "^20.14.4", + "@types/node": "^20.14.5", "@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/parser": "^7.13.1", "assemblyscript": "^0.27.27",