-
Notifications
You must be signed in to change notification settings - Fork 444
feat: build wasm with extism #1155
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
Open
thucpn
wants to merge
31
commits into
main
Choose a base branch
from
feat/build-wasm-with-extism
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
ccfc11c
feat: build wasm with extism
thucpn 02c8198
feat: detach packages for extism
thucpn ecc54cb
fix: lock
thucpn efbd61f
install extism-js
thucpn de4d8ff
install extism for all actions
thucpn fbb5ece
fix: install extism for all tests
thucpn 5c34d3a
create abstract ExtismTool
thucpn 9df0d63
feat: make agent example
thucpn dfb6c25
feat: add js example
thucpn 4b74096
update readme
thucpn 507012a
feat: ExtismToolFactory
thucpn 54abd70
feat: example with agent
thucpn 1eddb6e
export type
thucpn 7710d96
add getMetadata to wiki python example
thucpn 6cc8595
fix: typo and use same d.ts file for all tools
thucpn 879c15f
fix: lint
thucpn d48724f
fix: update doc
thucpn f7b666e
refactor: add package.json to examples
thucpn 8a73dac
test wiki
thucpn d95ed78
fix: lint depend on build
thucpn 660eab8
fix: e2e
thucpn fda48fa
fix: wrong path ts config.json
thucpn f34ea45
Merge branch 'main' into feat/build-wasm-with-extism
thucpn d718f43
fix: upgrade extism to fix worker bug
thucpn 191986b
refactor: create tool class params
thucpn f76abce
refactor: remove enum
thucpn 92d0d09
add todo tool example
thucpn 33d57d1
update test
thucpn 3293c22
Merge branch 'main' into feat/build-wasm-with-extism
thucpn 9447654
Create shy-bottles-shop.md
thucpn 951f215
Merge branch 'main' into feat/build-wasm-with-extism
marcusschiesser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import createPlugin from "@extism/extism"; | ||
|
||
async function main() { | ||
const plugin = await createPlugin("../extism/wiki/wiki.wasm", { | ||
useWasi: true, | ||
functions: {}, | ||
runInWorker: true, | ||
allowedHosts: ["*.wikipedia.org"], | ||
memory: { maxHttpResponseBytes: 100 * 1024 * 1024 }, | ||
}); | ||
|
||
try { | ||
const params = { query: "Ho Chi Minh City" }; | ||
const data = await plugin.call("wikiCall", JSON.stringify(params)); | ||
console.log(data.json()); | ||
} catch (e) { | ||
console.error(e); | ||
} finally { | ||
await plugin.close(); | ||
} | ||
} | ||
|
||
void main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import extism | ||
thucpn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import json | ||
from os.path import join, dirname | ||
|
||
|
||
def read_local_wasm(file_name): | ||
path = join(dirname(__file__), file_name) | ||
with open(path, "rb") as wasm_file: | ||
return wasm_file.read() | ||
|
||
|
||
def _manifest(file_name): | ||
wasm = read_local_wasm(file_name) | ||
return { | ||
"wasm": [{"data": wasm}], | ||
"allowed_hosts": ["*.wikipedia.org"], | ||
} | ||
|
||
|
||
manifest = _manifest("wiki.wasm") | ||
with extism.Plugin(manifest, wasi=True) as plugin: | ||
data = plugin.call( | ||
"wikiCall", | ||
json.dumps({"query": "Ho Chi Minh City"}), | ||
parse=lambda output: json.loads(bytes(output).decode("utf-8")), | ||
) | ||
print(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module 'main' { | ||
export function fakeData(): I32; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const { wiki } = require("wikipedia"); | ||
|
||
function fakeData() { | ||
const todoIndex = Host.inputString(); | ||
const request = { | ||
method: "GET", | ||
url: `https://jsonplaceholder.typicode.com/todos/${todoIndex}`, | ||
}; | ||
const response = Http.request(request); | ||
if (response.status != 200) throw new Error(`Got non 200 response ${response.status}`); | ||
Host.outputString(response.body); | ||
} | ||
|
||
module.exports = { fakeData }; |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module 'main' { | ||
export function wikiCall(): I32; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function wikiCall() { | ||
const params = JSON.parse(Host.inputString()); | ||
const query = params.query; | ||
const request = { | ||
method: "GET", | ||
url: `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(query)}`, | ||
}; | ||
const response = Http.request(request); | ||
if (response.status != 200) throw new Error(`Got non 200 response ${response.status}`); | ||
Host.outputString(response.body); | ||
} | ||
|
||
module.exports = { wikiCall }; |
thucpn marked this conversation as resolved.
Show resolved
Hide resolved
|
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.