@six5536/smllm-wasm 0.5.0 → 0.6.0

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/README.md CHANGED
@@ -6,11 +6,13 @@ or Node. The large language model (LLM) can run anywhere. The API is typed: it t
6
6
  objects, and the package includes TypeScript declarations.
7
7
 
8
8
  This README helps you run the engine in your own host. It shows a first example, then describes
9
- the host methods, storage, the Node helpers, and when to use the WebAssembly engine instead of the
10
- CLI.
9
+ the host methods, storage, the events that only the host fires, machines that the host drives for
10
+ a model without tools, the Node helpers, and when to use the WebAssembly engine instead of the CLI.
11
11
 
12
12
  - [Host](#host)
13
13
  - [Storage](#storage)
14
+ - [Host-only events](#host-only-events)
15
+ - [Host-driven machines](#host-driven-machines)
14
16
  - [Run in Node](#run-in-node)
15
17
  - [WebAssembly or CLI](#webassembly-or-cli)
16
18
  - [Licence](#licence)
@@ -43,6 +45,10 @@ const stop = engine.stop(session, stopHookActive);
43
45
  // "runaway": let it stop, show stop.text to the user; "allow": let it stop.
44
46
  ```
45
47
 
48
+ A param takes a string. A param that the machine declares with `type: json` takes any JSON value,
49
+ in `callTool`, `fire`, and `fireAsHost`, and the host receives its compact JSON text. A JSON string stays a string, even when its text spells an object. The events list shows
50
+ the param as a JSON value, with its JSON Schema.
51
+
46
52
  The `examples/wasm` folder of the [smllm repository](https://github.com/six5536/smllm) holds a
47
53
  whole agent loop, in TypeScript.
48
54
 
@@ -63,6 +69,7 @@ host leaves the method out:
63
69
  - `random()` returns a random number. By default, it uses `crypto.getRandomValues`.
64
70
  - `history(machine, id, entry)` and `put(kind, key, record)` receive writes. By default, the
65
71
  engine drops them.
72
+ - `wantsAudit()` and `audit(entry, reply)` keep an audit, as the following section describes.
66
73
 
67
74
  A host method that throws is a host failure: a failed guard or action, or a rejected pattern. The
68
75
  reply text shows the failure, and the engine stays usable.
@@ -80,6 +87,133 @@ write.
80
87
  IndexedDB, or one that sends the records to a server. `exportState()` and `importState(state)`
81
88
  move the whole state at once, for backups and moves.
82
89
 
90
+ ## Audit
91
+
92
+ An audit records every call that drove a session, accepted or refused: `bind`, `callTool`,
93
+ `events`, `fire`, `fireAsHost`, and `stop`. `view`, `status`, and `promptSubmitted` record
94
+ nothing. To keep an audit, give the storage or the host `wantsAudit()`, which returns true, and
95
+ `audit(entry, reply)`, which receives each `AuditEntry` and the text of the call's reply:
96
+
97
+ ```ts
98
+ const storage = {
99
+ ...memoryStorage(),
100
+ wantsAudit: () => true,
101
+ audit(entry: AuditEntry, reply: string) {
102
+ console.log(entry.source, entry.call, entry.event, entry.outcome, entry.reason);
103
+ },
104
+ };
105
+ ```
106
+
107
+ An entry holds the time, the session, the source (`agent`, or `host` for `fireAsHost`), the call,
108
+ the instance with its states before and after, the params, the names of the events that the reply
109
+ offered, the outcome with the reason for a refusal, and for a call that created the session its
110
+ binding. Keep what you need of the reply's text. A hash names its algorithm, as `sha256:` and the
111
+ hex of the SHA-256 of the text's UTF-8 bytes, which is the default that the `smllm` CLI uses.
112
+
113
+ ## Host-only events
114
+
115
+ A host-only event is an event that only the host fires, such as the result of checks that the host
116
+ runs outside the machine. A machine marks it with `source: host` in `meta.events`:
117
+
118
+ ```yaml
119
+ meta:
120
+ smllm: 1
121
+ events:
122
+ checksPassed: { source: host }
123
+ checksFailed: { source: host }
124
+ states:
125
+ WORK:
126
+ on: { submit: CHECKING }
127
+ CHECKING:
128
+ on: { checksPassed: DONE, checksFailed: WORK }
129
+ DONE: { type: final }
130
+ ```
131
+
132
+ The agent never sees a host-only event: the events lists of the tool's replies, of `view`, of
133
+ `events`, and of `stop` leave it out. `fire` and `callTool` refuse it with an error that names it
134
+ as an event that only the host fires. The host fires it with `fireAsHost`, which takes the same
135
+ arguments as `fire` and fires any event that the state offers:
136
+
137
+ ```js
138
+ engine.callTool({ session, event: "submit" }); // the agent: WORK → CHECKING
139
+ const passed = await runChecks(); // your own checks, which can be async
140
+ engine.fireAsHost(session, passed ? "checksPassed" : "checksFailed");
141
+ ```
142
+
143
+ Fire an event that the agent chose with `fire` or `callTool`, never with `fireAsHost`, because
144
+ `fireAsHost` would then take a host-only event from the agent. Keep `fireAsHost` for the host's
145
+ own events.
146
+
147
+ `source: host` is a security boundary only when the host drives a model without tools. An agent
148
+ that runs under a harness, such as Claude Code, usually has a shell, and there the marker
149
+ prevents mistakes rather than an attack. A harness has no host to fire the events, so the smllm
150
+ CLI refuses to start an instance of such a machine, and `smllm validate` notes that the machine
151
+ needs a host to drive it.
152
+
153
+ ## Host-driven machines
154
+
155
+ A host can drive a machine for a model that has no tools and only answers in text, such as a
156
+ model that the host calls through the Messages API with no tools. The host shows the model the
157
+ state, reads its answer as one event, runs its own checks, and fires the results. Four methods
158
+ serve it, and none of them changes anything:
159
+
160
+ - `hostView(key)` returns `{ location, model, host }`: where the session is, the events that the
161
+ model can fire, and the events that only the host fires. Each event has its `name`,
162
+ `description`, and `params`, and a JSON param has its bundled `schema` as an object.
163
+ - `stateText(key, { schemas })` returns the state's text for the model: its instructions, the
164
+ model's events with their params, and a request to answer with one event as JSON. Each JSON
165
+ param shows its schema, unless `schemas` is `false`.
166
+ - `answerSchema(key)` returns a JSON Schema of a valid answer, as an object, for a model that can
167
+ constrain its output, such as the Claude API's structured outputs.
168
+ - `checkAnswer(key, text)` reads the model's answer, a bare JSON object or one fenced block with
169
+ nothing outside it. It returns `{ ok: true, event, params }`, whose params are plain
170
+ JavaScript values ready for `fire`, or `{ ok: false, error }`, whose error the host sends back
171
+ to the model as it stands. Every malformed answer gets the same error.
172
+
173
+ This loop runs a machine from start to end. The machine is an extractor builder for bank
174
+ statements, which is in the `examples/extractor` folder of the smllm repository. The model
175
+ answers with an extractor, a JSON value with a schema, or asks for more pages. The host checks
176
+ the extractor and fires `checks_passed` or `checks_failed`, and the machine gives up after five
177
+ attempts:
178
+
179
+ ```js
180
+ const engine = new Engine(compiled, {}, memoryStorage());
181
+ // A keyless `enter` creates the session and starts the machine in one call.
182
+ const { session } = engine.fire(undefined, "enter", { stateMachine: "extractor-build" });
183
+ for (;;) {
184
+ const view = engine.hostView(session);
185
+ if (view.location.machine === null) break; // a final state: the session is idle again
186
+ if (view.model.length > 0) {
187
+ let prompt = `${engine.stateText(session)}\n${statement}`;
188
+ for (;;) {
189
+ const answer = engine.checkAnswer(session, await askModel(prompt)); // your adapter
190
+ if (answer.ok) {
191
+ engine.fire(session, answer.event, answer.params); // the model chose the event
192
+ if (answer.event === "extractor") extractor = answer.params.json;
193
+ break;
194
+ }
195
+ prompt = answer.error; // the refusal, as it stands; count it as an attempt
196
+ }
197
+ } else {
198
+ const errors = await runChecks(extractor); // your checks, which can be async
199
+ if (errors.length === 0) engine.fireAsHost(session, "checks_passed");
200
+ else engine.fireAsHost(session, "checks_failed", { errors: errors.join("\n") });
201
+ }
202
+ }
203
+ ```
204
+
205
+ The model is never offered a built-in event, such as `yield`, `pause`, or `unmatched`, or a
206
+ host-only event, because those belong to whoever drives the session, which here is the host. The
207
+ host fires them as it needs them. An outcome that the model can choose, such as "I can't do this"
208
+ or "ask the user", is an event that the machine declares.
209
+
210
+ One machine can mix the model's steps, the host's deterministic steps, and a person's steps. A
211
+ state that offers the model events is a step of the model. A state whose events are all the
212
+ host's is a step of the host, such as `CHECKING`, or a person's step, such as an approval for
213
+ which the host fires the person's decision. A state that offers both lists is a step of the model
214
+ that the host can interrupt: the extractor builder's `READ` offers the host `timed_out`, which the
215
+ host fires when the model takes too long.
216
+
83
217
  ## Run in Node
84
218
 
85
219
  `@six5536/smllm-wasm/node` provides a host and a storage for Node:
package/dist/types.d.ts CHANGED
@@ -53,6 +53,43 @@ export interface HistoryEntry {
53
53
  params: Record<string, string>;
54
54
  trace: string[];
55
55
  }
56
+ /**
57
+ * One audit entry: a call that drove a session, accepted or refused, handed
58
+ * to `audit` with the text of its reply when the host or the storage wants
59
+ * an audit.
60
+ */
61
+ export interface AuditEntry {
62
+ /** Unix ms. */
63
+ at: number;
64
+ session: string;
65
+ /** `host` for `fireAsHost`, else `agent`. */
66
+ source: "agent" | "host";
67
+ /** `view` is a tool call with no event. */
68
+ call: "bind" | "view" | "menu" | "fire" | "stop";
69
+ event: string | null;
70
+ machine: string | null;
71
+ instance: string | null;
72
+ /** The instance's state before the call. */
73
+ from: string | null;
74
+ /** The state where the session is after the call. */
75
+ to: string | null;
76
+ /** Each param as its text, a JSON value as its compact JSON. */
77
+ params: Record<string, string>;
78
+ /** The names of the events that the reply offered. */
79
+ offered: string[];
80
+ /** `accepted` or `refused`; for `stop`, the decision. */
81
+ outcome: "accepted" | "refused" | "allow" | "block" | "runaway";
82
+ /** Why the engine refused the call. */
83
+ reason: string | null;
84
+ trace: string[];
85
+ /** The binding of the session that the call created. */
86
+ binding: {
87
+ harness: string;
88
+ hostSession: string | null;
89
+ cwd: string;
90
+ configs: string[];
91
+ } | null;
92
+ }
56
93
  /**
57
94
  * What the engine needs from its host. Every method is optional:
58
95
  * - `supports`, `check`, `run`: host guard/action kinds (`command`); none by default.
@@ -62,6 +99,9 @@ export interface HistoryEntry {
62
99
  * - `now`, `random`: `Date.now()` and `crypto.getRandomValues` by default.
63
100
  * - `history`: each history entry as it happens; dropped by default.
64
101
  * - `put`: each session, binding and instance as it is saved (write-through storage); dropped by default.
102
+ * - `wantsAudit`, `audit`: whether to keep an audit, false by default, and each audit entry with the
103
+ * text of its reply. The host keeps what it likes of the text, such as `sha256:` and the hex of the
104
+ * SHA-256 of its UTF-8 bytes, the default that `smllm` uses.
65
105
  * A method that throws is a host failure the engine reports, never a broken engine.
66
106
  */
67
107
  export interface Host {
@@ -75,18 +115,25 @@ export interface Host {
75
115
  random?(): number;
76
116
  history?(machine: string, id: string, entry: HistoryEntry): void;
77
117
  put?(kind: RecordKind, key: string, record: unknown): void;
118
+ wantsAudit?(): boolean;
119
+ audit?(entry: AuditEntry, reply: string): void;
78
120
  }
79
121
  /** What `put` hands on: a session (key: its key), a binding (`harness/hostSession`, record: the session key) or an instance (`machine/id`). */
80
122
  export type RecordKind = "session" | "binding" | "instance";
81
123
  /**
82
124
  * Where an engine's state lives (WASM-2): `load` once, into `importState`;
83
125
  * then each saved record through `put` and each history entry through
84
- * `history`, as they happen, so persisting costs what changed.
126
+ * `history`, as they happen, so persisting costs what changed; and, when
127
+ * `wantsAudit` returns true, each audit entry through `audit`.
85
128
  */
86
129
  export interface Storage {
87
130
  load(): State | undefined;
88
131
  put(kind: RecordKind, key: string, record: unknown): void;
89
132
  history(machine: string, id: string, entry: HistoryEntry): void;
133
+ /** Whether the storage keeps an audit; false when absent. */
134
+ wantsAudit?(): boolean;
135
+ /** Each audit entry, with the text of the call's reply. */
136
+ audit?(entry: AuditEntry, reply: string): void;
90
137
  }
91
138
  /** The agent-facing `smllm` tool: the same definition the MCP server offers. */
92
139
  export interface Tool {
@@ -99,8 +146,53 @@ export interface Tool {
99
146
  export interface ToolArgs {
100
147
  session?: string;
101
148
  event?: string;
102
- params?: Record<string, string>;
149
+ /** A string for each param, or any JSON value for a param that the events list shows as a JSON value. */
150
+ params?: Record<string, unknown>;
103
151
  }
152
+ /** How `stateText` renders the state. */
153
+ export interface StateTextOptions {
154
+ /** Show each JSON param's schema; `true` by default. */
155
+ schemas?: boolean;
156
+ }
157
+ /** A param of an offered event. */
158
+ export interface OfferedParam {
159
+ name: string;
160
+ required: boolean;
161
+ /** `json`: the param takes any JSON value. */
162
+ type: "string" | "json";
163
+ /** The allowed values; empty when any string is allowed. */
164
+ enum: string[];
165
+ pattern: string | null;
166
+ description: string | null;
167
+ /** A JSON param's JSON Schema, bundled, or `null`. */
168
+ schema: Record<string, unknown> | boolean | null;
169
+ }
170
+ /** An event that the state offers. */
171
+ export interface Offered {
172
+ name: string;
173
+ description: string | null;
174
+ params: OfferedParam[];
175
+ }
176
+ /**
177
+ * The state as a host that drives the machine sees it: the events that the
178
+ * model can answer with, and the events that only the host fires (with
179
+ * `fireAsHost`). Neither list holds the built-in events, which the host
180
+ * fires as it needs them.
181
+ */
182
+ export interface HostView {
183
+ location: Location;
184
+ model: Offered[];
185
+ host: Offered[];
186
+ }
187
+ /** A model's answer, checked: the event and its params, ready for `fire`, or the refusal to send back to the model. */
188
+ export type CheckedAnswer = {
189
+ ok: true;
190
+ event: string;
191
+ params: Record<string, unknown>;
192
+ } | {
193
+ ok: false;
194
+ error: string;
195
+ };
104
196
  /** Sessions, bindings and instances by key, as `exportState` returns them and `importState` takes them. */
105
197
  export interface State {
106
198
  sessions: Record<string, unknown>;
package/dist/wrap.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Host, RecordKind, Reply, SessionStatus, State, Storage, StopDecision, Tool, ToolArgs } from "./types.js";
1
+ import type { CheckedAnswer, Host, HostView, RecordKind, Reply, SessionStatus, State, StateTextOptions, Storage, StopDecision, Tool, ToolArgs } from "./types.js";
2
2
  /** The host the wasm calls: strings in, strings out, every method there. */
3
3
  export interface RawHost {
4
4
  supports(kind: string): boolean;
@@ -10,6 +10,8 @@ export interface RawHost {
10
10
  random(): number;
11
11
  history(machine: string, id: string, entry: string): void;
12
12
  put(kind: RecordKind, key: string, record: string): void;
13
+ wantsAudit(): boolean;
14
+ audit(entry: string, reply: string): void;
13
15
  }
14
16
  /** A build's wasm-bindgen `Engine`: JSON text in and out. */
15
17
  export interface RawEngine {
@@ -21,8 +23,13 @@ export interface RawEngine {
21
23
  events(key: string): string;
22
24
  status(key: string): string;
23
25
  fire(key: string | null | undefined, event: string, params: string): string;
26
+ fireAsHost(key: string | null | undefined, event: string, params: string): string;
24
27
  stop(key: string, stopHookActive: boolean): string;
25
28
  promptSubmitted(key: string): void;
29
+ stateText(key: string, schemas: boolean): string;
30
+ answerSchema(key: string): string;
31
+ checkAnswer(key: string, text: string): string;
32
+ hostView(key: string): string;
26
33
  exportState(): string;
27
34
  importState(state: string): void;
28
35
  free(): void;
@@ -36,7 +43,8 @@ export declare class Engine {
36
43
  protected static Raw: RawClass;
37
44
  /**
38
45
  * `storage`, when given, is loaded now and then receives every saved
39
- * record and history entry (its `put` and `history` go before `host`'s).
46
+ * record and history entry, and each audit entry when it wants an audit
47
+ * (its `put`, `history` and `audit` go before `host`'s).
40
48
  */
41
49
  constructor(compiled: string | object, host?: Host, storage?: Storage);
42
50
  /** The agent-facing tool, to hand to an LLM's tool list (WASM-1). */
@@ -47,15 +55,41 @@ export declare class Engine {
47
55
  unsupported(): string[];
48
56
  /** Bind a harness session (reused when `hostSession` is already bound). */
49
57
  bind(harness: string, hostSession?: string, cwd?: string): Reply;
50
- /** Where the session is; changes nothing. */
58
+ /** Where the session is; changes nothing and records no audit entry. A look of the agent's is `callTool` with no event. */
51
59
  view(key: string): Reply;
52
60
  /** The events list of the session's state. */
53
61
  events(key: string): Reply;
54
62
  status(key: string): SessionStatus;
55
- /** Fire an event; with no key, only `enter` (it starts a session). */
56
- fire(key: string | undefined, event: string, params?: Record<string, string>): Reply;
63
+ /**
64
+ * Fire an event for the agent; with no key, only `enter` (it starts a
65
+ * session). An event that the machine marks with `source: host` is
66
+ * refused: fire it with `fireAsHost`. Fire an event that the agent chose
67
+ * here, never with `fireAsHost`. A param takes a string, or any JSON
68
+ * value when the events list shows it as a JSON value.
69
+ */
70
+ fire(key: string | undefined, event: string, params?: Record<string, unknown>): Reply;
71
+ /**
72
+ * Fire an event as the host: as `fire`, and also an event that the machine
73
+ * marks with `source: host`, such as the result of the host's own checks.
74
+ */
75
+ fireAsHost(key: string | undefined, event: string, params?: Record<string, unknown>): Reply;
57
76
  stop(key: string, stopHookActive?: boolean): StopDecision;
58
77
  promptSubmitted(key: string): void;
78
+ /**
79
+ * The state's text for a model without tools: its instructions, the
80
+ * events that the model can answer with, and how to answer. Each JSON
81
+ * param shows its schema unless `schemas` is `false`.
82
+ */
83
+ stateText(key: string, options?: StateTextOptions): string;
84
+ /** The JSON Schema of a valid answer: a `oneOf` with one branch for each event of the model. */
85
+ answerSchema(key: string): Record<string, unknown>;
86
+ /**
87
+ * Check the model's text answer: the event and its params, ready for
88
+ * `fire`, or a refusal to send back to the model. It fires nothing.
89
+ */
90
+ checkAnswer(key: string, text: string): CheckedAnswer;
91
+ /** The state's offered events in two lists: the model's, and the host's own. */
92
+ hostView(key: string): HostView;
59
93
  exportState(): State;
60
94
  importState(state: State | string): void;
61
95
  /** Free the wasm memory now, rather than when collected. */
package/dist/wrap.js CHANGED
@@ -18,6 +18,10 @@ function adapt(host) {
18
18
  put: (kind, key, record) => {
19
19
  host.put?.(kind, key, parse(record));
20
20
  },
21
+ wantsAudit: () => Boolean(host.wantsAudit?.()),
22
+ audit: (entry, reply) => {
23
+ host.audit?.(parse(entry), reply);
24
+ },
21
25
  };
22
26
  }
23
27
  /** smllm's engine over compiled machines (`smllm compile` output). */
@@ -27,7 +31,8 @@ export class Engine {
27
31
  #raw;
28
32
  /**
29
33
  * `storage`, when given, is loaded now and then receives every saved
30
- * record and history entry (its `put` and `history` go before `host`'s).
34
+ * record and history entry, and each audit entry when it wants an audit
35
+ * (its `put`, `history` and `audit` go before `host`'s).
31
36
  */
32
37
  constructor(compiled, host = {}, storage) {
33
38
  const json = typeof compiled === "string" ? compiled : JSON.stringify(compiled);
@@ -43,6 +48,15 @@ export class Engine {
43
48
  storage.history(machine, id, entry);
44
49
  host.history?.(machine, id, entry);
45
50
  },
51
+ wantsAudit: () => Boolean(storage.wantsAudit?.() || host.wantsAudit?.()),
52
+ audit: (entry, reply) => {
53
+ if (storage.wantsAudit?.()) {
54
+ storage.audit?.(entry, reply);
55
+ }
56
+ if (host.wantsAudit?.()) {
57
+ host.audit?.(entry, reply);
58
+ }
59
+ },
46
60
  }
47
61
  : host;
48
62
  this.#raw = new Raw(json, adapt(all));
@@ -68,7 +82,7 @@ export class Engine {
68
82
  bind(harness, hostSession, cwd = "") {
69
83
  return parse(this.#raw.bind(harness, hostSession, cwd));
70
84
  }
71
- /** Where the session is; changes nothing. */
85
+ /** Where the session is; changes nothing and records no audit entry. A look of the agent's is `callTool` with no event. */
72
86
  view(key) {
73
87
  return parse(this.#raw.view(key));
74
88
  }
@@ -79,16 +93,52 @@ export class Engine {
79
93
  status(key) {
80
94
  return parse(this.#raw.status(key));
81
95
  }
82
- /** Fire an event; with no key, only `enter` (it starts a session). */
96
+ /**
97
+ * Fire an event for the agent; with no key, only `enter` (it starts a
98
+ * session). An event that the machine marks with `source: host` is
99
+ * refused: fire it with `fireAsHost`. Fire an event that the agent chose
100
+ * here, never with `fireAsHost`. A param takes a string, or any JSON
101
+ * value when the events list shows it as a JSON value.
102
+ */
83
103
  fire(key, event, params = {}) {
84
104
  return parse(this.#raw.fire(key, event, JSON.stringify(params)));
85
105
  }
106
+ /**
107
+ * Fire an event as the host: as `fire`, and also an event that the machine
108
+ * marks with `source: host`, such as the result of the host's own checks.
109
+ */
110
+ fireAsHost(key, event, params = {}) {
111
+ return parse(this.#raw.fireAsHost(key, event, JSON.stringify(params)));
112
+ }
86
113
  stop(key, stopHookActive = false) {
87
114
  return parse(this.#raw.stop(key, stopHookActive));
88
115
  }
89
116
  promptSubmitted(key) {
90
117
  this.#raw.promptSubmitted(key);
91
118
  }
119
+ /**
120
+ * The state's text for a model without tools: its instructions, the
121
+ * events that the model can answer with, and how to answer. Each JSON
122
+ * param shows its schema unless `schemas` is `false`.
123
+ */
124
+ stateText(key, options = {}) {
125
+ return this.#raw.stateText(key, options.schemas ?? true);
126
+ }
127
+ /** The JSON Schema of a valid answer: a `oneOf` with one branch for each event of the model. */
128
+ answerSchema(key) {
129
+ return parse(this.#raw.answerSchema(key));
130
+ }
131
+ /**
132
+ * Check the model's text answer: the event and its params, ready for
133
+ * `fire`, or a refusal to send back to the model. It fires nothing.
134
+ */
135
+ checkAnswer(key, text) {
136
+ return parse(this.#raw.checkAnswer(key, text));
137
+ }
138
+ /** The state's offered events in two lists: the model's, and the host's own. */
139
+ hostView(key) {
140
+ return parse(this.#raw.hostView(key));
141
+ }
92
142
  exportState() {
93
143
  return parse(this.#raw.exportState());
94
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@six5536/smllm-wasm",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
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
6
  "repository": {
@@ -7,6 +7,10 @@
7
7
  export class Engine {
8
8
  free(): void;
9
9
  [Symbol.dispose](): void;
10
+ /**
11
+ * The JSON Schema of a valid answer, as JSON (ENG-8).
12
+ */
13
+ answerSchema(key: string): string;
10
14
  /**
11
15
  * Bind a session; returns the reply JSON (its `session` is the key).
12
16
  */
@@ -18,6 +22,12 @@ export class Engine {
18
22
  * sees its mistake as the tool's answer.
19
23
  */
20
24
  callTool(args: string): string;
25
+ /**
26
+ * A model's answer checked (ENG-9), as JSON: `{"ok": true, "event",
27
+ * "params"}`, whose params are JSON values ready for `fire`, or
28
+ * `{"ok": false, "error"}`.
29
+ */
30
+ checkAnswer(key: string, text: string): string;
21
31
  /**
22
32
  * The events list.
23
33
  */
@@ -27,9 +37,19 @@ export class Engine {
27
37
  */
28
38
  exportState(): string;
29
39
  /**
30
- * Fire an event; `params` is a JSON object of strings.
40
+ * Fire an event as the host, host-only events included (ENG-6).
41
+ */
42
+ fireAsHost(key: string | null | undefined, event: string, params: string): string;
43
+ /**
44
+ * Fire an event for the agent; `params` is a JSON object, of strings
45
+ * except for a JSON param's value.
31
46
  */
32
47
  fire(key: string | null | undefined, event: string, params: string): string;
48
+ /**
49
+ * The state's offered events in two lists, the model's and the
50
+ * host's, with where the session is, as JSON (ENG-10).
51
+ */
52
+ hostView(key: string): string;
33
53
  /**
34
54
  * Replace the store from [`Engine::export_state`] JSON.
35
55
  */
@@ -42,6 +62,11 @@ export class Engine {
42
62
  * A user prompt arrived.
43
63
  */
44
64
  promptSubmitted(key: string): void;
65
+ /**
66
+ * The state's text for a model without tools; `schemas` shows each
67
+ * JSON param's schema (ENG-7).
68
+ */
69
+ stateText(key: string, schemas: boolean): string;
45
70
  /**
46
71
  * Where the session is, as the `smllm statusline --json` object (ENG-3).
47
72
  */
@@ -12,6 +12,37 @@ export class Engine {
12
12
  const ptr = this.__destroy_into_raw();
13
13
  wasm.__wbg_engine_free(ptr, 0);
14
14
  }
15
+ /**
16
+ * The JSON Schema of a valid answer, as JSON (ENG-8).
17
+ * @param {string} key
18
+ * @returns {string}
19
+ */
20
+ answerSchema(key) {
21
+ let deferred3_0;
22
+ let deferred3_1;
23
+ try {
24
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
25
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
26
+ const len0 = WASM_VECTOR_LEN;
27
+ wasm.engine_answerSchema(retptr, this.__wbg_ptr, ptr0, len0);
28
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
29
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
30
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
31
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
32
+ var ptr2 = r0;
33
+ var len2 = r1;
34
+ if (r3) {
35
+ ptr2 = 0; len2 = 0;
36
+ throw takeObject(r2);
37
+ }
38
+ deferred3_0 = ptr2;
39
+ deferred3_1 = len2;
40
+ return getStringFromWasm0(ptr2, len2);
41
+ } finally {
42
+ wasm.__wbindgen_add_to_stack_pointer(16);
43
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
44
+ }
45
+ }
15
46
  /**
16
47
  * Bind a session; returns the reply JSON (its `session` is the key).
17
48
  * @param {string} harness
@@ -75,6 +106,42 @@ export class Engine {
75
106
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
76
107
  }
77
108
  }
109
+ /**
110
+ * A model's answer checked (ENG-9), as JSON: `{"ok": true, "event",
111
+ * "params"}`, whose params are JSON values ready for `fire`, or
112
+ * `{"ok": false, "error"}`.
113
+ * @param {string} key
114
+ * @param {string} text
115
+ * @returns {string}
116
+ */
117
+ checkAnswer(key, text) {
118
+ let deferred4_0;
119
+ let deferred4_1;
120
+ try {
121
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
122
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ const ptr1 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
125
+ const len1 = WASM_VECTOR_LEN;
126
+ wasm.engine_checkAnswer(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
127
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
128
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
129
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
130
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
131
+ var ptr3 = r0;
132
+ var len3 = r1;
133
+ if (r3) {
134
+ ptr3 = 0; len3 = 0;
135
+ throw takeObject(r2);
136
+ }
137
+ deferred4_0 = ptr3;
138
+ deferred4_1 = len3;
139
+ return getStringFromWasm0(ptr3, len3);
140
+ } finally {
141
+ wasm.__wbindgen_add_to_stack_pointer(16);
142
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
143
+ }
144
+ }
78
145
  /**
79
146
  * The events list.
80
147
  * @param {string} key
@@ -127,7 +194,45 @@ export class Engine {
127
194
  }
128
195
  }
129
196
  /**
130
- * Fire an event; `params` is a JSON object of strings.
197
+ * Fire an event as the host, host-only events included (ENG-6).
198
+ * @param {string | null | undefined} key
199
+ * @param {string} event
200
+ * @param {string} params
201
+ * @returns {string}
202
+ */
203
+ fireAsHost(key, event, params) {
204
+ let deferred5_0;
205
+ let deferred5_1;
206
+ try {
207
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
208
+ var ptr0 = isLikeNone(key) ? 0 : passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
209
+ var len0 = WASM_VECTOR_LEN;
210
+ const ptr1 = passStringToWasm0(event, wasm.__wbindgen_export, wasm.__wbindgen_export2);
211
+ const len1 = WASM_VECTOR_LEN;
212
+ const ptr2 = passStringToWasm0(params, wasm.__wbindgen_export, wasm.__wbindgen_export2);
213
+ const len2 = WASM_VECTOR_LEN;
214
+ wasm.engine_fireAsHost(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
215
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
216
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
217
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
218
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
219
+ var ptr4 = r0;
220
+ var len4 = r1;
221
+ if (r3) {
222
+ ptr4 = 0; len4 = 0;
223
+ throw takeObject(r2);
224
+ }
225
+ deferred5_0 = ptr4;
226
+ deferred5_1 = len4;
227
+ return getStringFromWasm0(ptr4, len4);
228
+ } finally {
229
+ wasm.__wbindgen_add_to_stack_pointer(16);
230
+ wasm.__wbindgen_export4(deferred5_0, deferred5_1, 1);
231
+ }
232
+ }
233
+ /**
234
+ * Fire an event for the agent; `params` is a JSON object, of strings
235
+ * except for a JSON param's value.
131
236
  * @param {string | null | undefined} key
132
237
  * @param {string} event
133
238
  * @param {string} params
@@ -163,6 +268,38 @@ export class Engine {
163
268
  wasm.__wbindgen_export4(deferred5_0, deferred5_1, 1);
164
269
  }
165
270
  }
271
+ /**
272
+ * The state's offered events in two lists, the model's and the
273
+ * host's, with where the session is, as JSON (ENG-10).
274
+ * @param {string} key
275
+ * @returns {string}
276
+ */
277
+ hostView(key) {
278
+ let deferred3_0;
279
+ let deferred3_1;
280
+ try {
281
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
282
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
283
+ const len0 = WASM_VECTOR_LEN;
284
+ wasm.engine_hostView(retptr, this.__wbg_ptr, ptr0, len0);
285
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
286
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
287
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
288
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
289
+ var ptr2 = r0;
290
+ var len2 = r1;
291
+ if (r3) {
292
+ ptr2 = 0; len2 = 0;
293
+ throw takeObject(r2);
294
+ }
295
+ deferred3_0 = ptr2;
296
+ deferred3_1 = len2;
297
+ return getStringFromWasm0(ptr2, len2);
298
+ } finally {
299
+ wasm.__wbindgen_add_to_stack_pointer(16);
300
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
301
+ }
302
+ }
166
303
  /**
167
304
  * Replace the store from [`Engine::export_state`] JSON.
168
305
  * @param {string} state
@@ -225,6 +362,39 @@ export class Engine {
225
362
  wasm.__wbindgen_add_to_stack_pointer(16);
226
363
  }
227
364
  }
365
+ /**
366
+ * The state's text for a model without tools; `schemas` shows each
367
+ * JSON param's schema (ENG-7).
368
+ * @param {string} key
369
+ * @param {boolean} schemas
370
+ * @returns {string}
371
+ */
372
+ stateText(key, schemas) {
373
+ let deferred3_0;
374
+ let deferred3_1;
375
+ try {
376
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
377
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
378
+ const len0 = WASM_VECTOR_LEN;
379
+ wasm.engine_stateText(retptr, this.__wbg_ptr, ptr0, len0, schemas);
380
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
381
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
382
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
383
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
384
+ var ptr2 = r0;
385
+ var len2 = r1;
386
+ if (r3) {
387
+ ptr2 = 0; len2 = 0;
388
+ throw takeObject(r2);
389
+ }
390
+ deferred3_0 = ptr2;
391
+ deferred3_1 = len2;
392
+ return getStringFromWasm0(ptr2, len2);
393
+ } finally {
394
+ wasm.__wbindgen_add_to_stack_pointer(16);
395
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
396
+ }
397
+ }
228
398
  /**
229
399
  * Where the session is, as the `smllm statusline --json` object (ENG-3).
230
400
  * @param {string} key
@@ -370,7 +540,7 @@ export function __wbg_Error_30c8987f7c2ed4e2(arg0, arg1) {
370
540
  const ret = Error(getStringFromWasm0(arg0, arg1));
371
541
  return addHeapObject(ret);
372
542
  }
373
- export function __wbg_String_bbd7b99db50d2c72(arg0, arg1) {
543
+ export function __wbg_String_a5249499d8036ec9(arg0, arg1) {
374
544
  const ret = String(getObject(arg1));
375
545
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
376
546
  const len1 = WASM_VECTOR_LEN;
@@ -380,46 +550,53 @@ export function __wbg_String_bbd7b99db50d2c72(arg0, arg1) {
380
550
  export function __wbg___wbindgen_throw_41e9ee4f547fc59a(arg0, arg1) {
381
551
  throw new Error(getStringFromWasm0(arg0, arg1));
382
552
  }
383
- export function __wbg_check_6dfc683de5752eb9() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
553
+ export function __wbg_audit_85f5bb21263e0644() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
554
+ getObject(arg0).audit(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
555
+ }, arguments); }
556
+ export function __wbg_check_e9ea28c77bd41729() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
384
557
  const ret = getObject(arg0).check(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6), getStringFromWasm0(arg7, arg8));
385
558
  return ret;
386
559
  }, arguments); }
387
- export function __wbg_history_ed6a3249cdbf6fba() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
560
+ export function __wbg_history_ba99161437b60e0e() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
388
561
  getObject(arg0).history(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6));
389
562
  }, arguments); }
390
- export function __wbg_isMatch_b6fb6fb03924405a() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
563
+ export function __wbg_isMatch_57a619cdd9087ba8() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
391
564
  const ret = getObject(arg0).isMatch(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
392
565
  return ret;
393
566
  }, arguments); }
394
- export function __wbg_now_976fd88331086448() { return handleError(function (arg0) {
567
+ export function __wbg_now_1a669daa685d184d() { return handleError(function (arg0) {
395
568
  const ret = getObject(arg0).now();
396
569
  return ret;
397
570
  }, arguments); }
398
- export function __wbg_put_9cd5b2a059778929() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
571
+ export function __wbg_put_8270908aa8f03c2a() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
399
572
  getObject(arg0).put(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6));
400
573
  }, arguments); }
401
- export function __wbg_random_5e704a8263f19bfe() { return handleError(function (arg0) {
574
+ export function __wbg_random_a2849827a284f2d5() { return handleError(function (arg0) {
402
575
  const ret = getObject(arg0).random();
403
576
  return ret;
404
577
  }, arguments); }
405
- export function __wbg_read_3a7eb14b88f4a798() { return handleError(function (arg0, arg1, arg2, arg3) {
578
+ export function __wbg_read_e79d6ea23600ac6f() { return handleError(function (arg0, arg1, arg2, arg3) {
406
579
  const ret = getObject(arg1).read(getStringFromWasm0(arg2, arg3));
407
580
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
408
581
  var len1 = WASM_VECTOR_LEN;
409
582
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
410
583
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
411
584
  }, arguments); }
412
- export function __wbg_run_9856da75a23eb26d() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
585
+ export function __wbg_run_e1681363901db5c8() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
413
586
  const ret = getObject(arg1).run(getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7), getStringFromWasm0(arg8, arg9));
414
587
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
415
588
  const len1 = WASM_VECTOR_LEN;
416
589
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
417
590
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
418
591
  }, arguments); }
419
- export function __wbg_supports_ecfa18db153d083b() { return handleError(function (arg0, arg1, arg2) {
592
+ export function __wbg_supports_5e904725127552cf() { return handleError(function (arg0, arg1, arg2) {
420
593
  const ret = getObject(arg0).supports(getStringFromWasm0(arg1, arg2));
421
594
  return ret;
422
595
  }, arguments); }
596
+ export function __wbg_wantsAudit_27e6b386da9d3696() { return handleError(function (arg0) {
597
+ const ret = getObject(arg0).wantsAudit();
598
+ return ret;
599
+ }, arguments); }
423
600
  export function __wbindgen_object_drop_ref(arg0) {
424
601
  takeObject(arg0);
425
602
  }
Binary file
@@ -2,14 +2,19 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_engine_free: (a: number, b: number) => void;
5
+ export const engine_answerSchema: (a: number, b: number, c: number, d: number) => void;
5
6
  export const engine_bind: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
6
7
  export const engine_callTool: (a: number, b: number, c: number, d: number) => void;
8
+ export const engine_checkAnswer: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
7
9
  export const engine_events: (a: number, b: number, c: number, d: number) => void;
8
10
  export const engine_exportState: (a: number, b: number) => void;
9
11
  export const engine_fire: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
12
+ export const engine_fireAsHost: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
13
+ export const engine_hostView: (a: number, b: number, c: number, d: number) => void;
10
14
  export const engine_importState: (a: number, b: number, c: number, d: number) => void;
11
15
  export const engine_new: (a: number, b: number, c: number, d: number) => void;
12
16
  export const engine_promptSubmitted: (a: number, b: number, c: number, d: number) => void;
17
+ export const engine_stateText: (a: number, b: number, c: number, d: number, e: number) => void;
13
18
  export const engine_status: (a: number, b: number, c: number, d: number) => void;
14
19
  export const engine_stop: (a: number, b: number, c: number, d: number, e: number) => void;
15
20
  export const engine_tool: (a: number, b: number) => void;
@@ -7,6 +7,10 @@
7
7
  export class Engine {
8
8
  free(): void;
9
9
  [Symbol.dispose](): void;
10
+ /**
11
+ * The JSON Schema of a valid answer, as JSON (ENG-8).
12
+ */
13
+ answerSchema(key: string): string;
10
14
  /**
11
15
  * Bind a session; returns the reply JSON (its `session` is the key).
12
16
  */
@@ -18,6 +22,12 @@ export class Engine {
18
22
  * sees its mistake as the tool's answer.
19
23
  */
20
24
  callTool(args: string): string;
25
+ /**
26
+ * A model's answer checked (ENG-9), as JSON: `{"ok": true, "event",
27
+ * "params"}`, whose params are JSON values ready for `fire`, or
28
+ * `{"ok": false, "error"}`.
29
+ */
30
+ checkAnswer(key: string, text: string): string;
21
31
  /**
22
32
  * The events list.
23
33
  */
@@ -27,9 +37,19 @@ export class Engine {
27
37
  */
28
38
  exportState(): string;
29
39
  /**
30
- * Fire an event; `params` is a JSON object of strings.
40
+ * Fire an event as the host, host-only events included (ENG-6).
41
+ */
42
+ fireAsHost(key: string | null | undefined, event: string, params: string): string;
43
+ /**
44
+ * Fire an event for the agent; `params` is a JSON object, of strings
45
+ * except for a JSON param's value.
31
46
  */
32
47
  fire(key: string | null | undefined, event: string, params: string): string;
48
+ /**
49
+ * The state's offered events in two lists, the model's and the
50
+ * host's, with where the session is, as JSON (ENG-10).
51
+ */
52
+ hostView(key: string): string;
33
53
  /**
34
54
  * Replace the store from [`Engine::export_state`] JSON.
35
55
  */
@@ -42,6 +62,11 @@ export class Engine {
42
62
  * A user prompt arrived.
43
63
  */
44
64
  promptSubmitted(key: string): void;
65
+ /**
66
+ * The state's text for a model without tools; `schemas` shows each
67
+ * JSON param's schema (ENG-7).
68
+ */
69
+ stateText(key: string, schemas: boolean): string;
45
70
  /**
46
71
  * Where the session is, as the `smllm statusline --json` object (ENG-3).
47
72
  */
@@ -74,14 +99,19 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
74
99
  export interface InitOutput {
75
100
  readonly memory: WebAssembly.Memory;
76
101
  readonly __wbg_engine_free: (a: number, b: number) => void;
102
+ readonly engine_answerSchema: (a: number, b: number, c: number, d: number) => void;
77
103
  readonly engine_bind: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
78
104
  readonly engine_callTool: (a: number, b: number, c: number, d: number) => void;
105
+ readonly engine_checkAnswer: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
79
106
  readonly engine_events: (a: number, b: number, c: number, d: number) => void;
80
107
  readonly engine_exportState: (a: number, b: number) => void;
81
108
  readonly engine_fire: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
109
+ readonly engine_fireAsHost: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
110
+ readonly engine_hostView: (a: number, b: number, c: number, d: number) => void;
82
111
  readonly engine_importState: (a: number, b: number, c: number, d: number) => void;
83
112
  readonly engine_new: (a: number, b: number, c: number, d: number) => void;
84
113
  readonly engine_promptSubmitted: (a: number, b: number, c: number, d: number) => void;
114
+ readonly engine_stateText: (a: number, b: number, c: number, d: number, e: number) => void;
85
115
  readonly engine_status: (a: number, b: number, c: number, d: number) => void;
86
116
  readonly engine_stop: (a: number, b: number, c: number, d: number, e: number) => void;
87
117
  readonly engine_tool: (a: number, b: number) => void;
@@ -14,6 +14,37 @@ export class Engine {
14
14
  const ptr = this.__destroy_into_raw();
15
15
  wasm.__wbg_engine_free(ptr, 0);
16
16
  }
17
+ /**
18
+ * The JSON Schema of a valid answer, as JSON (ENG-8).
19
+ * @param {string} key
20
+ * @returns {string}
21
+ */
22
+ answerSchema(key) {
23
+ let deferred3_0;
24
+ let deferred3_1;
25
+ try {
26
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
27
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
28
+ const len0 = WASM_VECTOR_LEN;
29
+ wasm.engine_answerSchema(retptr, this.__wbg_ptr, ptr0, len0);
30
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
31
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
32
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
33
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
34
+ var ptr2 = r0;
35
+ var len2 = r1;
36
+ if (r3) {
37
+ ptr2 = 0; len2 = 0;
38
+ throw takeObject(r2);
39
+ }
40
+ deferred3_0 = ptr2;
41
+ deferred3_1 = len2;
42
+ return getStringFromWasm0(ptr2, len2);
43
+ } finally {
44
+ wasm.__wbindgen_add_to_stack_pointer(16);
45
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
46
+ }
47
+ }
17
48
  /**
18
49
  * Bind a session; returns the reply JSON (its `session` is the key).
19
50
  * @param {string} harness
@@ -77,6 +108,42 @@ export class Engine {
77
108
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
78
109
  }
79
110
  }
111
+ /**
112
+ * A model's answer checked (ENG-9), as JSON: `{"ok": true, "event",
113
+ * "params"}`, whose params are JSON values ready for `fire`, or
114
+ * `{"ok": false, "error"}`.
115
+ * @param {string} key
116
+ * @param {string} text
117
+ * @returns {string}
118
+ */
119
+ checkAnswer(key, text) {
120
+ let deferred4_0;
121
+ let deferred4_1;
122
+ try {
123
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
124
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
125
+ const len0 = WASM_VECTOR_LEN;
126
+ const ptr1 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
127
+ const len1 = WASM_VECTOR_LEN;
128
+ wasm.engine_checkAnswer(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
129
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
130
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
131
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
132
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
133
+ var ptr3 = r0;
134
+ var len3 = r1;
135
+ if (r3) {
136
+ ptr3 = 0; len3 = 0;
137
+ throw takeObject(r2);
138
+ }
139
+ deferred4_0 = ptr3;
140
+ deferred4_1 = len3;
141
+ return getStringFromWasm0(ptr3, len3);
142
+ } finally {
143
+ wasm.__wbindgen_add_to_stack_pointer(16);
144
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
145
+ }
146
+ }
80
147
  /**
81
148
  * The events list.
82
149
  * @param {string} key
@@ -129,7 +196,45 @@ export class Engine {
129
196
  }
130
197
  }
131
198
  /**
132
- * Fire an event; `params` is a JSON object of strings.
199
+ * Fire an event as the host, host-only events included (ENG-6).
200
+ * @param {string | null | undefined} key
201
+ * @param {string} event
202
+ * @param {string} params
203
+ * @returns {string}
204
+ */
205
+ fireAsHost(key, event, params) {
206
+ let deferred5_0;
207
+ let deferred5_1;
208
+ try {
209
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
210
+ var ptr0 = isLikeNone(key) ? 0 : passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
211
+ var len0 = WASM_VECTOR_LEN;
212
+ const ptr1 = passStringToWasm0(event, wasm.__wbindgen_export, wasm.__wbindgen_export2);
213
+ const len1 = WASM_VECTOR_LEN;
214
+ const ptr2 = passStringToWasm0(params, wasm.__wbindgen_export, wasm.__wbindgen_export2);
215
+ const len2 = WASM_VECTOR_LEN;
216
+ wasm.engine_fireAsHost(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
217
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
218
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
219
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
220
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
221
+ var ptr4 = r0;
222
+ var len4 = r1;
223
+ if (r3) {
224
+ ptr4 = 0; len4 = 0;
225
+ throw takeObject(r2);
226
+ }
227
+ deferred5_0 = ptr4;
228
+ deferred5_1 = len4;
229
+ return getStringFromWasm0(ptr4, len4);
230
+ } finally {
231
+ wasm.__wbindgen_add_to_stack_pointer(16);
232
+ wasm.__wbindgen_export4(deferred5_0, deferred5_1, 1);
233
+ }
234
+ }
235
+ /**
236
+ * Fire an event for the agent; `params` is a JSON object, of strings
237
+ * except for a JSON param's value.
133
238
  * @param {string | null | undefined} key
134
239
  * @param {string} event
135
240
  * @param {string} params
@@ -165,6 +270,38 @@ export class Engine {
165
270
  wasm.__wbindgen_export4(deferred5_0, deferred5_1, 1);
166
271
  }
167
272
  }
273
+ /**
274
+ * The state's offered events in two lists, the model's and the
275
+ * host's, with where the session is, as JSON (ENG-10).
276
+ * @param {string} key
277
+ * @returns {string}
278
+ */
279
+ hostView(key) {
280
+ let deferred3_0;
281
+ let deferred3_1;
282
+ try {
283
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
284
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
285
+ const len0 = WASM_VECTOR_LEN;
286
+ wasm.engine_hostView(retptr, this.__wbg_ptr, ptr0, len0);
287
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
288
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
289
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
290
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
291
+ var ptr2 = r0;
292
+ var len2 = r1;
293
+ if (r3) {
294
+ ptr2 = 0; len2 = 0;
295
+ throw takeObject(r2);
296
+ }
297
+ deferred3_0 = ptr2;
298
+ deferred3_1 = len2;
299
+ return getStringFromWasm0(ptr2, len2);
300
+ } finally {
301
+ wasm.__wbindgen_add_to_stack_pointer(16);
302
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
303
+ }
304
+ }
168
305
  /**
169
306
  * Replace the store from [`Engine::export_state`] JSON.
170
307
  * @param {string} state
@@ -227,6 +364,39 @@ export class Engine {
227
364
  wasm.__wbindgen_add_to_stack_pointer(16);
228
365
  }
229
366
  }
367
+ /**
368
+ * The state's text for a model without tools; `schemas` shows each
369
+ * JSON param's schema (ENG-7).
370
+ * @param {string} key
371
+ * @param {boolean} schemas
372
+ * @returns {string}
373
+ */
374
+ stateText(key, schemas) {
375
+ let deferred3_0;
376
+ let deferred3_1;
377
+ try {
378
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
379
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
380
+ const len0 = WASM_VECTOR_LEN;
381
+ wasm.engine_stateText(retptr, this.__wbg_ptr, ptr0, len0, schemas);
382
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
383
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
384
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
385
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
386
+ var ptr2 = r0;
387
+ var len2 = r1;
388
+ if (r3) {
389
+ ptr2 = 0; len2 = 0;
390
+ throw takeObject(r2);
391
+ }
392
+ deferred3_0 = ptr2;
393
+ deferred3_1 = len2;
394
+ return getStringFromWasm0(ptr2, len2);
395
+ } finally {
396
+ wasm.__wbindgen_add_to_stack_pointer(16);
397
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
398
+ }
399
+ }
230
400
  /**
231
401
  * Where the session is, as the `smllm statusline --json` object (ENG-3).
232
402
  * @param {string} key
@@ -375,7 +545,7 @@ function __wbg_get_imports() {
375
545
  const ret = Error(getStringFromWasm0(arg0, arg1));
376
546
  return addHeapObject(ret);
377
547
  },
378
- __wbg_String_bbd7b99db50d2c72: function(arg0, arg1) {
548
+ __wbg_String_a5249499d8036ec9: function(arg0, arg1) {
379
549
  const ret = String(getObject(arg1));
380
550
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
381
551
  const len1 = WASM_VECTOR_LEN;
@@ -385,46 +555,53 @@ function __wbg_get_imports() {
385
555
  __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
386
556
  throw new Error(getStringFromWasm0(arg0, arg1));
387
557
  },
388
- __wbg_check_6dfc683de5752eb9: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
558
+ __wbg_audit_85f5bb21263e0644: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
559
+ getObject(arg0).audit(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
560
+ }, arguments); },
561
+ __wbg_check_e9ea28c77bd41729: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
389
562
  const ret = getObject(arg0).check(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6), getStringFromWasm0(arg7, arg8));
390
563
  return ret;
391
564
  }, arguments); },
392
- __wbg_history_ed6a3249cdbf6fba: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
565
+ __wbg_history_ba99161437b60e0e: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
393
566
  getObject(arg0).history(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6));
394
567
  }, arguments); },
395
- __wbg_isMatch_b6fb6fb03924405a: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
568
+ __wbg_isMatch_57a619cdd9087ba8: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
396
569
  const ret = getObject(arg0).isMatch(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
397
570
  return ret;
398
571
  }, arguments); },
399
- __wbg_now_976fd88331086448: function() { return handleError(function (arg0) {
572
+ __wbg_now_1a669daa685d184d: function() { return handleError(function (arg0) {
400
573
  const ret = getObject(arg0).now();
401
574
  return ret;
402
575
  }, arguments); },
403
- __wbg_put_9cd5b2a059778929: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
576
+ __wbg_put_8270908aa8f03c2a: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
404
577
  getObject(arg0).put(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6));
405
578
  }, arguments); },
406
- __wbg_random_5e704a8263f19bfe: function() { return handleError(function (arg0) {
579
+ __wbg_random_a2849827a284f2d5: function() { return handleError(function (arg0) {
407
580
  const ret = getObject(arg0).random();
408
581
  return ret;
409
582
  }, arguments); },
410
- __wbg_read_3a7eb14b88f4a798: function() { return handleError(function (arg0, arg1, arg2, arg3) {
583
+ __wbg_read_e79d6ea23600ac6f: function() { return handleError(function (arg0, arg1, arg2, arg3) {
411
584
  const ret = getObject(arg1).read(getStringFromWasm0(arg2, arg3));
412
585
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
413
586
  var len1 = WASM_VECTOR_LEN;
414
587
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
415
588
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
416
589
  }, arguments); },
417
- __wbg_run_9856da75a23eb26d: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
590
+ __wbg_run_e1681363901db5c8: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
418
591
  const ret = getObject(arg1).run(getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7), getStringFromWasm0(arg8, arg9));
419
592
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
420
593
  const len1 = WASM_VECTOR_LEN;
421
594
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
422
595
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
423
596
  }, arguments); },
424
- __wbg_supports_ecfa18db153d083b: function() { return handleError(function (arg0, arg1, arg2) {
597
+ __wbg_supports_5e904725127552cf: function() { return handleError(function (arg0, arg1, arg2) {
425
598
  const ret = getObject(arg0).supports(getStringFromWasm0(arg1, arg2));
426
599
  return ret;
427
600
  }, arguments); },
601
+ __wbg_wantsAudit_27e6b386da9d3696: function() { return handleError(function (arg0) {
602
+ const ret = getObject(arg0).wantsAudit();
603
+ return ret;
604
+ }, arguments); },
428
605
  __wbindgen_object_drop_ref: function(arg0) {
429
606
  takeObject(arg0);
430
607
  },
Binary file
@@ -2,14 +2,19 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_engine_free: (a: number, b: number) => void;
5
+ export const engine_answerSchema: (a: number, b: number, c: number, d: number) => void;
5
6
  export const engine_bind: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
6
7
  export const engine_callTool: (a: number, b: number, c: number, d: number) => void;
8
+ export const engine_checkAnswer: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
7
9
  export const engine_events: (a: number, b: number, c: number, d: number) => void;
8
10
  export const engine_exportState: (a: number, b: number) => void;
9
11
  export const engine_fire: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
12
+ export const engine_fireAsHost: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
13
+ export const engine_hostView: (a: number, b: number, c: number, d: number) => void;
10
14
  export const engine_importState: (a: number, b: number, c: number, d: number) => void;
11
15
  export const engine_new: (a: number, b: number, c: number, d: number) => void;
12
16
  export const engine_promptSubmitted: (a: number, b: number, c: number, d: number) => void;
17
+ export const engine_stateText: (a: number, b: number, c: number, d: number, e: number) => void;
13
18
  export const engine_status: (a: number, b: number, c: number, d: number) => void;
14
19
  export const engine_stop: (a: number, b: number, c: number, d: number, e: number) => void;
15
20
  export const engine_tool: (a: number, b: number) => void;