Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit fcd4e39

Browse files
Update interface and publish as v0.1.5 (#4)
1 parent 23a53b5 commit fcd4e39

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ export class ModelInfo {
1010
}
1111

1212
export interface ModelFactory {
13-
getModel<T extends Model<object, object>>(modelName: string): T;
13+
getModel<T extends Model>(modelName: string): T;
1414
}
1515

16-
export abstract class Model<TInput extends object, TOutput extends object> {
17-
protected constructor(
18-
public readonly info: ModelInfo,
19-
protected invoker: ModelInvoker,
20-
) {}
16+
export abstract class Model<TInput = unknown, TOutput = unknown> {
17+
static invoker: ModelInvoker | null = null;
18+
protected constructor(public info: ModelInfo) {}
2119

2220
debug: boolean = false;
2321

@@ -27,13 +25,17 @@ export abstract class Model<TInput extends object, TOutput extends object> {
2725
* @returns The output object from the model.
2826
*/
2927
invoke(input: TInput): TOutput {
28+
if (!Model.invoker) {
29+
throw new Error("Model invoker is not set.");
30+
}
31+
3032
const modelName = this.info.name;
3133
const inputJson = JSON.stringify(input);
3234
if (this.debug) {
3335
console.debug(`Invoking ${modelName} model with input: ${inputJson}`);
3436
}
3537

36-
const outputJson = this.invoker(modelName, inputJson);
38+
const outputJson = Model.invoker(modelName, inputJson);
3739
if (!outputJson) {
3840
throw new Error(`Failed to invoke ${modelName} model.`);
3941
}

src/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hypermode/models-as",
3-
"version": "0.1.2",
3+
"version": "0.1.5",
44
"description": "Hypermode Model Interface Library for AssemblyScript",
55
"author": "Hypermode, Inc.",
66
"license": "MIT",
@@ -17,7 +17,7 @@
1717
"json-as": "^0.9.6"
1818
},
1919
"devDependencies": {
20-
"@types/node": "^20.14.4",
20+
"@types/node": "^20.14.5",
2121
"@typescript-eslint/eslint-plugin": "^7.13.1",
2222
"@typescript-eslint/parser": "^7.13.1",
2323
"assemblyscript": "^0.27.27",

0 commit comments

Comments
 (0)