@six5536/smllm-wasm 0.0.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/wrap.js ADDED
@@ -0,0 +1,104 @@
1
+ // The typed layer over the raw string API: objects in and
2
+ // out, and an object-based host. Each entry module subclasses `Engine` with
3
+ // its build's wasm-bindgen `Engine` as `Raw`.
4
+ const parse = (text) => JSON.parse(text);
5
+ /** The raw host: `host`'s methods, JSON parsed, defaults filled in. */
6
+ function adapt(host) {
7
+ return {
8
+ supports: (kind) => Boolean(host.supports?.(kind)),
9
+ check: (kind, params, env, cwd) => host.check ? Boolean(host.check(kind, parse(params), parse(env), cwd)) : false,
10
+ run: (kind, params, env, cwd) => host.run ? (host.run(kind, parse(params), parse(env), cwd) ?? "") : `${kind} is not supported`,
11
+ read: (file) => host.read?.(file) ?? undefined,
12
+ isMatch: (pattern, value) => host.isMatch ? host.isMatch(pattern, value) : new RegExp(pattern).test(value),
13
+ now: () => (host.now ? host.now() : Date.now()),
14
+ random: () => (host.random ? host.random() : crypto.getRandomValues(new Uint32Array(1))[0]),
15
+ history: (machine, id, entry) => {
16
+ host.history?.(machine, id, parse(entry));
17
+ },
18
+ put: (kind, key, record) => {
19
+ host.put?.(kind, key, parse(record));
20
+ },
21
+ };
22
+ }
23
+ /** smllm's engine over compiled machines (`smllm compile` output). */
24
+ export class Engine {
25
+ /** The build's raw `Engine`: set by the entry module's subclass. */
26
+ static Raw;
27
+ #raw;
28
+ /**
29
+ * `storage`, when given, is loaded now and then receives every saved
30
+ * record and history entry (its `put` and `history` go before `host`'s).
31
+ */
32
+ constructor(compiled, host = {}, storage) {
33
+ const json = typeof compiled === "string" ? compiled : JSON.stringify(compiled);
34
+ const Raw = this.constructor.Raw;
35
+ const all = storage
36
+ ? {
37
+ ...host,
38
+ put: (kind, key, record) => {
39
+ storage.put(kind, key, record);
40
+ host.put?.(kind, key, record);
41
+ },
42
+ history: (machine, id, entry) => {
43
+ storage.history(machine, id, entry);
44
+ host.history?.(machine, id, entry);
45
+ },
46
+ }
47
+ : host;
48
+ this.#raw = new Raw(json, adapt(all));
49
+ const saved = storage?.load();
50
+ if (saved) {
51
+ this.importState(saved);
52
+ }
53
+ }
54
+ /** The agent-facing tool, to hand to an LLM's tool list (HOST-13). */
55
+ tool() {
56
+ return parse(this.#raw.tool());
57
+ }
58
+ /** Answer a tool call as the MCP server does; a malformed call is `ok: false`, never a throw. */
59
+ callTool(args = {}) {
60
+ return parse(this.#raw.callTool(JSON.stringify(args)));
61
+ }
62
+ /** Guard and action kinds the machines use that this host cannot run. */
63
+ unsupported() {
64
+ return parse(this.#raw.unsupported());
65
+ }
66
+ /** Bind a harness session (reused when `hostSession` is already bound). */
67
+ bind(harness, hostSession, cwd = "") {
68
+ return parse(this.#raw.bind(harness, hostSession, cwd));
69
+ }
70
+ /** Where the session is; changes nothing. */
71
+ view(key) {
72
+ return parse(this.#raw.view(key));
73
+ }
74
+ /** The events list of the session's state. */
75
+ events(key) {
76
+ return parse(this.#raw.events(key));
77
+ }
78
+ status(key) {
79
+ return parse(this.#raw.status(key));
80
+ }
81
+ /** Fire an event; with no key, only `enter` (it starts a session). */
82
+ fire(key, event, params = {}) {
83
+ return parse(this.#raw.fire(key, event, JSON.stringify(params)));
84
+ }
85
+ stop(key, stopHookActive = false) {
86
+ return parse(this.#raw.stop(key, stopHookActive));
87
+ }
88
+ promptSubmitted(key) {
89
+ this.#raw.promptSubmitted(key);
90
+ }
91
+ exportState() {
92
+ return parse(this.#raw.exportState());
93
+ }
94
+ importState(state) {
95
+ this.#raw.importState(typeof state === "string" ? state : JSON.stringify(state));
96
+ }
97
+ /** Free the wasm memory now, rather than when collected. */
98
+ free() {
99
+ this.#raw.free();
100
+ }
101
+ [Symbol.dispose]() {
102
+ this.free();
103
+ }
104
+ }
package/package.json CHANGED
@@ -1,10 +1,65 @@
1
1
  {
2
2
  "name": "@six5536/smllm-wasm",
3
- "version": "0.0.0",
4
- "description": "Reserves the name for smllm's first release, so that its trusted publisher can be set up. Install a later version.",
3
+ "version": "0.4.1",
4
+ "description": "smllm's engine as WebAssembly: run smllm state machines that drive an LLM agent, in a browser or Node.",
5
5
  "homepage": "https://github.com/six5536/smllm#readme",
6
- "repository": { "type": "git", "url": "git+https://github.com/six5536/smllm.git" },
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/six5536/smllm.git",
9
+ "directory": "packages/smllm-wasm"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/six5536/smllm/issues"
13
+ },
14
+ "author": "six5536 <10079653+six5536@users.noreply.github.com>",
15
+ "publishConfig": {
16
+ "registry": "https://registry.npmjs.org",
17
+ "access": "public",
18
+ "provenance": true
19
+ },
20
+ "keywords": [
21
+ "llm",
22
+ "agent",
23
+ "state-machine",
24
+ "xstate",
25
+ "wasm"
26
+ ],
27
+ "type": "module",
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./bundler": {
36
+ "types": "./dist/bundler.d.ts",
37
+ "default": "./dist/bundler.js"
38
+ },
39
+ "./node": {
40
+ "types": "./dist/node/index.d.ts",
41
+ "default": "./dist/node/index.js"
42
+ },
43
+ "./raw": {
44
+ "types": "./wasm/web/smllm_wasm.d.ts",
45
+ "default": "./wasm/web/smllm_wasm.js"
46
+ },
47
+ "./raw/bundler": {
48
+ "types": "./wasm/bundler/smllm_wasm.d.ts",
49
+ "default": "./wasm/bundler/smllm_wasm.js"
50
+ }
51
+ },
52
+ "files": [
53
+ "dist/",
54
+ "wasm/web/",
55
+ "wasm/bundler/"
56
+ ],
57
+ "sideEffects": [
58
+ "./wasm/bundler/smllm_wasm.js",
59
+ "./dist/bundler.js"
60
+ ],
7
61
  "license": "MIT",
8
- "files": ["README.md"],
9
- "publishConfig": { "registry": "https://registry.npmjs.org", "access": "public" }
62
+ "scripts": {
63
+ "test": "node --test test/*.test.mjs"
64
+ }
10
65
  }
@@ -0,0 +1,70 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * An smllm engine with an in-memory store.
6
+ */
7
+ export class Engine {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ /**
11
+ * Bind a session; returns the reply JSON (its `session` is the key).
12
+ */
13
+ bind(harness: string, host_session: string | null | undefined, cwd: string): string;
14
+ /**
15
+ * A tool call: the agent's arguments as JSON, answered as the MCP
16
+ * server answers them (HOST-13). A malformed call or an engine error is
17
+ * a reply with `ok: false` and `error: …`, never a throw: the agent
18
+ * sees its mistake as the tool's answer.
19
+ */
20
+ callTool(args: string): string;
21
+ /**
22
+ * The events list.
23
+ */
24
+ events(key: string): string;
25
+ /**
26
+ * Sessions, bindings and instances as JSON (history went to the host).
27
+ */
28
+ exportState(): string;
29
+ /**
30
+ * Fire an event; `params` is a JSON object of strings.
31
+ */
32
+ fire(key: string | null | undefined, event: string, params: string): string;
33
+ /**
34
+ * Replace the store from [`Engine::export_state`] JSON.
35
+ */
36
+ importState(state: string): void;
37
+ /**
38
+ * Load compiled machines (`smllm compile` output).
39
+ */
40
+ constructor(compiled: string, host: any);
41
+ /**
42
+ * A user prompt arrived.
43
+ */
44
+ promptSubmitted(key: string): void;
45
+ /**
46
+ * Where the session is, as the `smllm statusline --json` object (STL-8).
47
+ */
48
+ status(key: string): string;
49
+ /**
50
+ * The stop decision as JSON (TURN-4..6): `{"decision": "allow"}` = may
51
+ * stop; `{"decision": "block", "text"}` = hold the agent with the events
52
+ * list; `{"decision": "runaway", "text"}` = let it stop, showing the
53
+ * list to the user (the harness was already continuing because of a
54
+ * block, and no event was fired since).
55
+ */
56
+ stop(key: string, stop_hook_active: boolean): string;
57
+ /**
58
+ * The agent-facing tool, as JSON `{name, description, inputSchema}`:
59
+ * the core's definition, as the MCP server offers it (HOST-13).
60
+ */
61
+ tool(): string;
62
+ /**
63
+ * Guard and action kinds this host cannot run, as a JSON array.
64
+ */
65
+ unsupported(): string;
66
+ /**
67
+ * Read-only view.
68
+ */
69
+ view(key: string): string;
70
+ }
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./smllm_wasm.d.ts" */
2
+ import * as wasm from "./smllm_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./smllm_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+
7
+ export {
8
+ Engine
9
+ } from "./smllm_wasm_bg.js";