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

Commit

Permalink
Initial Spike
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint committed Jun 14, 2024
1 parent eafb12f commit 3d98cad
Show file tree
Hide file tree
Showing 26 changed files with 2,675 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CODEOWNERS info: https://help.github.com/en/articles/about-code-owners
# Owners are automatically requested for review for PRs that changes code
# that they own.
* @hypermodeAI/runtime
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/src"
schedule:
interval: "weekly"
day: "wednesday"
time: "16:00"
groups:
minor-and-patch:
applies-to: version-updates
update-types:
- "minor"
- "patch"

- package-ecosystem: "github-actions"
# Workflow files stored in the default location of `.github/workflows`. (You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.)
directory: "/"
schedule:
interval: "weekly"
day: "wednesday"
time: "16:00"
29 changes: 29 additions & 0 deletions .github/workflows/ci-as-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci-as-lint
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
jobs:
as-lint:
if: github.event_name == 'pull_request'
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: 'src/'
steps:
- name: Checkout Source
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ">=20"
- name: Install dependencies
run: npm install
- name: Validate code is formatted
run: npm run pretty:check
- name: Valid code is linted
run: npm run lint
26 changes: 26 additions & 0 deletions .github/workflows/ci-as-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci-as-tests
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
jobs:
as-tests:
if: github.event_name == 'pull_request'
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: "src"
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ">=20"
- name: Install dependencies
run: npm install
- name: Run Unit Tests
run: npm run test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
build/

.DS_Store
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"streetsidesoftware.code-spell-checker"
]
}
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"editor.formatOnSave": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.associations": {
"hypermode.json": "jsonc"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Change Log

## UNRELEASED

- Initial Release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Hypermode, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- This readme will display with the repository on GitHub. -->

![NPM Version](https://img.shields.io/npm/v/%40hypermode%2Fmodels-as)
![NPM Downloads](https://img.shields.io/npm/dw/%40hypermode%2Fmodels-as)

# Hypermode Model Interface Library for AssemblyScript

This repository contains model class definitions for use with [Hypermode](https://hypermode.com)
Functions written in [AssemblyScript](https://www.assemblyscript.org/).

## Documentation

Please visit [docs.hypermode.com](https://docs.hypermode.com/) for detailed docs
covering the Hypermode platform, including this library.
24 changes: 24 additions & 0 deletions src/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"es6": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/ban-types": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
}
}
3 changes: 3 additions & 0 deletions src/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["assemblyscript-prettier"]
}
21 changes: 21 additions & 0 deletions src/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Hypermode, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- This readme will display with the package on npmjs.com. -->

# Hypermode Model Interface Library for AssemblyScript

This package contains a shared library used by Hypermode Functions written in AssemblyScript.
It provides class definitions for models, model inputs, and model outputs.

For further details, refer to https://github.com/hypermodeAI/models-as.
1 change: 1 addition & 0 deletions src/__tests__/as-pect.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@as-pect/assembly/types/as-pect" />
24 changes: 24 additions & 0 deletions src/as-pect.asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"targets": {
"coverage": {
"lib": ["./node_modules/@as-covers/assembly/index.ts"],
"transform": ["@as-covers/transform", "@as-pect/transform"]
},
"noCoverage": {
"transform": ["@as-pect/transform"]
}
},
"options": {
"exportMemory": true,
"outFile": "output.wasm",
"textFile": "output.wat",
"bindings": "raw",
"exportStart": "_start",
"exportRuntime": true,
"use": ["RTRACE=1"],
"debug": true,
"exportTable": true
},
"extends": "./asconfig.json",
"entries": ["./node_modules/@as-pect/assembly/assembly/index.ts"]
}
14 changes: 14 additions & 0 deletions src/as-pect.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
entries: ["assembly/__tests__/**/*.spec.ts"],
include: ["assembly/__tests__/**/*.include.ts"],
disclude: [/node_modules/],
outputBinary: false,

async instantiate(memory, createImports, instantiate, binary) {
const imports = {
env: { memory },
};

return instantiate(binary, createImports(imports));
},
};
5 changes: 5 additions & 0 deletions src/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"options": {
"transform": ["json-as/transform"]
}
}
12 changes: 12 additions & 0 deletions src/bin/pretest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { execSync } from "child_process";
import process from "process";
import console from "console";

try {
await import("@as-pect/cli");
} catch {
console.log("Installing @as-pect/cli");
const npm = process.env.npm_execpath;
const cmd = `node ${npm} install --no-save --no-audit @as-pect/cli`;
execSync(cmd, { stdio: "inherit" });
}
47 changes: 47 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { JSON } from "json-as";

type ModelInvoker = (modelName: string, inputJson: string) => string | null;

export class ModelInfo {
constructor(
public readonly name: string,
public readonly fullName: string = name,
) {}
}

export interface ModelFactory {
getModel<T extends Model<object, object>>(modelName: string): T;
}

export abstract class Model<TInput extends object, TOutput extends object> {
protected constructor(
public readonly info: ModelInfo,
private invoker: ModelInvoker,
) {}

debug: boolean = false;

/**
* Invokes the model with the given input.
* @param input The input object to pass to the model.
* @returns The output object from the model.
*/
invoke(input: TInput): TOutput {
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);
if (!outputJson) {
throw new Error(`Failed to invoke ${modelName} model.`);
}

if (this.debug) {
console.debug(`Received output: ${outputJson}`);
}

return JSON.parse<TOutput>(outputJson, true);
}
}
Loading

0 comments on commit 3d98cad

Please sign in to comment.