Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the JavaScript runtime to use wit bindgen #429

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Setup bazel
uses: jwlawson/actions-setup-bazel@v1
with:
bazel-version: '3.7.2'
bazel-version: "3.7.2"
- uses: maxim-lobanov/setup-xcode@v1
if: runner.os == 'macOS'
with:
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
- name: Setup Rust
run: rustup show
- name: check @hotg-ai/rune
run: yarn install && yarn build && yarn test
run: yarn install && yarn ci
working-directory: bindings/web/rune
- name: check @hotg-ai/rune-tfjs-v3
run: yarn install && yarn build && yarn test
Expand All @@ -159,4 +159,3 @@ jobs:
- name: check @hotg-ai/rune-tflite
run: yarn install && yarn build
working-directory: bindings/web/tflite

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ examples/.DS_Store
tarpaulin-report.html
.ipynb_checkpoints/
build/

.parcel-cache/
42 changes: 21 additions & 21 deletions bindings/web/rune/LICENSE_APACHE.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,33 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
Expand Down
14 changes: 7 additions & 7 deletions bindings/web/rune/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ A package that lets you run Runes in the browser.

## Getting Started

The easiest way to get started is by following [*Lesson 4: Integrating With The
Browser*][lesson-4] from our tutorial series.
The easiest way to get started is by following [_Lesson 4: Integrating With The
Browser_][lesson-4] from our tutorial series.

This will walk you through creating a React application which initializes the
Rune runtime and executes it every time a button is pressed.
Expand All @@ -25,16 +25,16 @@ import path (i.e. you import from `@hotg-ai/rune/builtins` instead of
`@hotg-ai/rune/dist/builtins`).

As a precaution, the `package.json` in this folder sets `"private": true` to
make sure you don't accidentally run `yarn publish`
make sure you don't accidentally run `yarn publish`

## License

This project is licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE.md) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT.md) or
http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE.md) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT.md) or
http://opensource.org/licenses/MIT)

at your option.

Expand Down
32 changes: 24 additions & 8 deletions bindings/web/rune/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
{
"name": "@hotg-ai/rune",
"version": "0.11.8",
"version": "0.12.0-rc.1",
"description": "Execute Runes inside a JavaScript environment.",
"repository": "https://github.com/hotg-ai/rune",
"homepage": "https://hotg.dev/",
"author": "The Rune Developers <[email protected]>",
"license": "MIT OR Apache-2.0",
"main": "index.js",
"types": "index.d.ts",
"private": true,
"source": "src/index.ts",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"build": "parcel build",
"watch": "parcel watch",
"test": "jest",
"ci": "tsc --noEmit && parcel build && yarn test",
"fmt": "prettier --write .",
"release": "tsc && cd dist && cp ../*.md . && sed 's/\"private\": true,/\"private\": false,/g' ../package.json > package.json && yarn publish",
"generate-runefile-types": "json2ts ../../../crates/compiler/runefile-schema.json --output src/Runefile.ts"
},
"dependencies": {},
"files": [
"dist/*",
"*.md",
"*.json",
"jest.config.ts"
],
"dependencies": {
"@hotg-ai/rune": "^0.12.0-rc.0",
"@hotg-ai/rune-wit-files": "^0.3.1",
"js-yaml": "^4.1.0",
"jszip": "^3.9.1",
"pino": "^7.11.0"
},
"devDependencies": {
"@parcel/packager-ts": "2.6.0",
"@parcel/transformer-typescript-types": "^2.6.0",
"@types/jest": "^27.0.0",
"@types/js-yaml": "^4.0.5",
"jest": "^27.0.6",
"json-schema-to-typescript": "^10.1.5",
"parcel": "^2.5.0",
"prettier": "^2.5.1",
"ts-jest": "^27.0.4",
"ts-node": "^10.4.0",
Expand Down
40 changes: 40 additions & 0 deletions bindings/web/rune/src/Rune.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Logger, pino } from "pino";
import type { ModelHandler, Runtime } from ".";
import { RuneLoader } from "./RuneLoader";

/**
* A builder object that lets you configure how a Rune is loaded.
*/
export class Rune {
private modelHandlers: Record<string, ModelHandler> = {};
private logger: Logger = pino({ level: "silent", enabled: false });

/**
* Set the logger that will be used during the loading process and by the
* Rune runtime.
*/
public withLogger(logger: Logger): this {
this.logger = logger;
return this;
}

/**
* Register a model handler based on the "model-format" argument attached to
* a model node.
*/
public withModelHandler(modelType: string, handler: ModelHandler): this {
this.modelHandlers[modelType] = handler;
return this;
}

/**
* Load the Rune, instantiating a Runtime that can be used to interact with
* it.
*
* @param rune
*/
public async load(rune: Uint8Array): Promise<Runtime> {
const loader = new RuneLoader(this.modelHandlers, this.logger);
return await loader.load(rune);
}
}
Loading