@elizaos/interop 2.0.0-alpha.52 → 2.0.0-alpha.521
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/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +121 -0
- package/dist/python-bridge.d.ts +96 -0
- package/dist/python-bridge.d.ts.map +1 -0
- package/dist/python-bridge.js +391 -0
- package/dist/types.d.ts +301 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/wasm-loader.d.ts +36 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +314 -0
- package/package.json +7 -6
- package/python/tests/test_rust_ffi_loader.py +2 -2
- package/dist/packages/interop/tsconfig.tsbuildinfo +0 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-language interop types for elizaOS
|
|
3
|
+
*
|
|
4
|
+
* These types define the wire format for communication between
|
|
5
|
+
* different language runtimes (Rust, TypeScript, Python).
|
|
6
|
+
*
|
|
7
|
+
* Standalone definitions matching proto schemas in /schemas/eliza/v1/ipc.proto.
|
|
8
|
+
* For full proto-generated types, import from @elizaos/core.
|
|
9
|
+
*/
|
|
10
|
+
import type { Content, Memory, State } from "@elizaos/core";
|
|
11
|
+
/**
|
|
12
|
+
* Supported interop protocols
|
|
13
|
+
*/
|
|
14
|
+
export type InteropProtocol = "wasm" | "ffi" | "ipc" | "native";
|
|
15
|
+
/**
|
|
16
|
+
* Supported plugin languages
|
|
17
|
+
*/
|
|
18
|
+
export type PluginLanguage = "typescript" | "rust" | "python";
|
|
19
|
+
/**
|
|
20
|
+
* Plugin interop configuration
|
|
21
|
+
*/
|
|
22
|
+
export interface PluginInteropConfig {
|
|
23
|
+
/** Communication protocol */
|
|
24
|
+
protocol: InteropProtocol;
|
|
25
|
+
/** Path to WASM module (for wasm protocol) */
|
|
26
|
+
wasmPath?: string;
|
|
27
|
+
/** Path to shared library (for ffi protocol) */
|
|
28
|
+
sharedLibPath?: string;
|
|
29
|
+
/** IPC command to spawn subprocess */
|
|
30
|
+
ipcCommand?: string;
|
|
31
|
+
/** IPC port for TCP communication */
|
|
32
|
+
ipcPort?: number;
|
|
33
|
+
/** Working directory for subprocess */
|
|
34
|
+
cwd?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Cross-language plugin manifest
|
|
38
|
+
*/
|
|
39
|
+
export interface PluginManifest {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
version: string;
|
|
43
|
+
language: PluginLanguage;
|
|
44
|
+
interop?: PluginInteropConfig;
|
|
45
|
+
config?: Record<string, string | number | boolean | null>;
|
|
46
|
+
dependencies?: string[];
|
|
47
|
+
actions?: ActionManifest[];
|
|
48
|
+
providers?: ProviderManifest[];
|
|
49
|
+
evaluators?: EvaluatorManifest[];
|
|
50
|
+
services?: ServiceManifest[];
|
|
51
|
+
routes?: RouteManifest[];
|
|
52
|
+
events?: Record<string, string[]>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Action manifest (metadata only, no handlers)
|
|
56
|
+
*/
|
|
57
|
+
export interface ActionManifest {
|
|
58
|
+
name: string;
|
|
59
|
+
description: string;
|
|
60
|
+
similes?: string[];
|
|
61
|
+
examples?: ActionExample[][];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Action example for documentation
|
|
65
|
+
*/
|
|
66
|
+
export interface ActionExample {
|
|
67
|
+
name: string;
|
|
68
|
+
content: Content;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Provider manifest
|
|
72
|
+
*/
|
|
73
|
+
export interface ProviderManifest {
|
|
74
|
+
name: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
dynamic?: boolean;
|
|
77
|
+
position?: number;
|
|
78
|
+
private?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Evaluator manifest
|
|
82
|
+
*/
|
|
83
|
+
export interface EvaluatorManifest {
|
|
84
|
+
name: string;
|
|
85
|
+
description: string;
|
|
86
|
+
alwaysRun?: boolean;
|
|
87
|
+
similes?: string[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Service manifest
|
|
91
|
+
*/
|
|
92
|
+
export interface ServiceManifest {
|
|
93
|
+
type: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Route manifest
|
|
98
|
+
*/
|
|
99
|
+
export interface RouteManifest {
|
|
100
|
+
path: string;
|
|
101
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "STATIC";
|
|
102
|
+
name?: string;
|
|
103
|
+
public?: boolean;
|
|
104
|
+
isMultipart?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Base IPC message
|
|
108
|
+
*/
|
|
109
|
+
export interface IPCMessage {
|
|
110
|
+
type: string;
|
|
111
|
+
id: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Action invocation request
|
|
115
|
+
*/
|
|
116
|
+
export interface ActionInvokeRequest extends IPCMessage {
|
|
117
|
+
type: "action.invoke";
|
|
118
|
+
action: string;
|
|
119
|
+
memory: Memory;
|
|
120
|
+
state: State | null;
|
|
121
|
+
options: Record<string, unknown> | null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Action result response
|
|
125
|
+
*/
|
|
126
|
+
export interface ActionResultResponse extends IPCMessage {
|
|
127
|
+
type: "action.result";
|
|
128
|
+
result: ActionResultPayload;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Action result payload
|
|
132
|
+
*/
|
|
133
|
+
export interface ActionResultPayload {
|
|
134
|
+
success: boolean;
|
|
135
|
+
text?: string;
|
|
136
|
+
error?: string;
|
|
137
|
+
data?: Record<string, unknown>;
|
|
138
|
+
values?: Record<string, unknown>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Action validation request
|
|
142
|
+
*/
|
|
143
|
+
export interface ActionValidateRequest extends IPCMessage {
|
|
144
|
+
type: "action.validate";
|
|
145
|
+
action: string;
|
|
146
|
+
memory: Memory;
|
|
147
|
+
state: State | null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validation result response
|
|
151
|
+
*/
|
|
152
|
+
export interface ValidationResponse extends IPCMessage {
|
|
153
|
+
type: "validate.result";
|
|
154
|
+
valid: boolean;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Provider get request
|
|
158
|
+
*/
|
|
159
|
+
export interface ProviderGetRequest extends IPCMessage {
|
|
160
|
+
type: "provider.get";
|
|
161
|
+
provider: string;
|
|
162
|
+
memory: Memory;
|
|
163
|
+
state: State;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Provider result response
|
|
167
|
+
*/
|
|
168
|
+
export interface ProviderResultResponse extends IPCMessage {
|
|
169
|
+
type: "provider.result";
|
|
170
|
+
result: ProviderResultPayload;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Provider result payload
|
|
174
|
+
*/
|
|
175
|
+
export interface ProviderResultPayload {
|
|
176
|
+
text?: string;
|
|
177
|
+
values?: Record<string, unknown>;
|
|
178
|
+
data?: Record<string, unknown>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Evaluator invocation request
|
|
182
|
+
*/
|
|
183
|
+
export interface EvaluatorInvokeRequest extends IPCMessage {
|
|
184
|
+
type: "evaluator.invoke";
|
|
185
|
+
evaluator: string;
|
|
186
|
+
memory: Memory;
|
|
187
|
+
state: State | null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Service start request
|
|
191
|
+
*/
|
|
192
|
+
export interface ServiceStartRequest extends IPCMessage {
|
|
193
|
+
type: "service.start";
|
|
194
|
+
service: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Service stop request
|
|
198
|
+
*/
|
|
199
|
+
export interface ServiceStopRequest extends IPCMessage {
|
|
200
|
+
type: "service.stop";
|
|
201
|
+
service: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Service response
|
|
205
|
+
*/
|
|
206
|
+
export interface ServiceResponse extends IPCMessage {
|
|
207
|
+
type: "service.response";
|
|
208
|
+
success: boolean;
|
|
209
|
+
error?: string;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Route handler request
|
|
213
|
+
*/
|
|
214
|
+
export interface RouteHandlerRequest extends IPCMessage {
|
|
215
|
+
type: "route.handle";
|
|
216
|
+
path: string;
|
|
217
|
+
method: string;
|
|
218
|
+
body?: unknown;
|
|
219
|
+
params?: Record<string, string>;
|
|
220
|
+
query?: Record<string, unknown>;
|
|
221
|
+
headers?: Record<string, string | string[]>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Route handler response
|
|
225
|
+
*/
|
|
226
|
+
export interface RouteHandlerResponse extends IPCMessage {
|
|
227
|
+
type: "route.response";
|
|
228
|
+
status: number;
|
|
229
|
+
headers?: Record<string, string | string[]>;
|
|
230
|
+
body?: unknown;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Plugin initialization request
|
|
234
|
+
*/
|
|
235
|
+
export interface PluginInitRequest extends IPCMessage {
|
|
236
|
+
type: "plugin.init";
|
|
237
|
+
config: Record<string, string>;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Plugin initialization response
|
|
241
|
+
*/
|
|
242
|
+
export interface PluginInitResponse extends IPCMessage {
|
|
243
|
+
type: "plugin.init.result";
|
|
244
|
+
success: boolean;
|
|
245
|
+
error?: string;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Error response
|
|
249
|
+
*/
|
|
250
|
+
export interface ErrorResponse extends IPCMessage {
|
|
251
|
+
type: "error";
|
|
252
|
+
error: string;
|
|
253
|
+
details?: unknown;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* All possible IPC request types
|
|
257
|
+
*/
|
|
258
|
+
export type IPCRequest = ActionInvokeRequest | ActionValidateRequest | ProviderGetRequest | EvaluatorInvokeRequest | ServiceStartRequest | ServiceStopRequest | RouteHandlerRequest | PluginInitRequest;
|
|
259
|
+
/**
|
|
260
|
+
* All possible IPC response types
|
|
261
|
+
*/
|
|
262
|
+
export type IPCResponse = ActionResultResponse | ValidationResponse | ProviderResultResponse | ServiceResponse | RouteHandlerResponse | PluginInitResponse | ErrorResponse;
|
|
263
|
+
/**
|
|
264
|
+
* WASM plugin exports interface
|
|
265
|
+
*/
|
|
266
|
+
export interface WasmPluginExports {
|
|
267
|
+
/** Get plugin manifest as JSON string */
|
|
268
|
+
get_manifest(): string;
|
|
269
|
+
/** Initialize the plugin with config JSON */
|
|
270
|
+
init(config_json: string): void;
|
|
271
|
+
/** Validate an action (returns boolean) */
|
|
272
|
+
validate_action(action: string, memory_json: string, state_json: string): boolean;
|
|
273
|
+
/** Invoke an action (returns result JSON) */
|
|
274
|
+
invoke_action(action: string, memory_json: string, state_json: string, options_json: string): string;
|
|
275
|
+
/** Get provider data (returns result JSON) */
|
|
276
|
+
get_provider(provider: string, memory_json: string, state_json: string): string;
|
|
277
|
+
/** Validate an evaluator */
|
|
278
|
+
validate_evaluator(evaluator: string, memory_json: string, state_json: string): boolean;
|
|
279
|
+
/** Invoke an evaluator (returns result JSON) */
|
|
280
|
+
invoke_evaluator(evaluator: string, memory_json: string, state_json: string): string;
|
|
281
|
+
/** Handle a route (returns response JSON) */
|
|
282
|
+
handle_route(path: string, method: string, request_json: string): string;
|
|
283
|
+
/** Memory allocation for passing strings */
|
|
284
|
+
alloc(size: number): number;
|
|
285
|
+
/** Memory deallocation */
|
|
286
|
+
dealloc(ptr: number, size: number): void;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* WASM memory interface
|
|
290
|
+
*/
|
|
291
|
+
export interface WasmMemory {
|
|
292
|
+
buffer: ArrayBuffer;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* WASM instance with memory and exports
|
|
296
|
+
*/
|
|
297
|
+
export interface WasmPluginInstance {
|
|
298
|
+
exports: WasmPluginExports;
|
|
299
|
+
memory: WasmMemory;
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../typescript/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,6BAA6B;IAC7B,QAAQ,EAAE,eAAe,CAAC;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC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AM,EAAE,UAAU,CAAC;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-language interop types for elizaOS
|
|
3
|
+
*
|
|
4
|
+
* These types define the wire format for communication between
|
|
5
|
+
* different language runtimes (Rust, TypeScript, Python).
|
|
6
|
+
*
|
|
7
|
+
* Standalone definitions matching proto schemas in /schemas/eliza/v1/ipc.proto.
|
|
8
|
+
* For full proto-generated types, import from @elizaos/core.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Plugin Loader for elizaOS
|
|
3
|
+
*
|
|
4
|
+
* Loads Rust (or other) plugins compiled to WebAssembly and adapts them
|
|
5
|
+
* to the TypeScript Plugin interface.
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from "@elizaos/core";
|
|
8
|
+
import type { PluginManifest } from "./types";
|
|
9
|
+
/**
|
|
10
|
+
* Options for loading a WASM plugin
|
|
11
|
+
*/
|
|
12
|
+
export interface WasmLoaderOptions {
|
|
13
|
+
/** Path or URL to the WASM file */
|
|
14
|
+
wasmPath: string;
|
|
15
|
+
/** Optional path to plugin.json manifest (auto-detected if not provided) */
|
|
16
|
+
manifestPath?: string;
|
|
17
|
+
/** Import object for WASM instantiation */
|
|
18
|
+
imports?: WebAssembly.Imports;
|
|
19
|
+
/** Maximum allowed WASM binary size in bytes. */
|
|
20
|
+
maxWasmBytes?: number;
|
|
21
|
+
/** Maximum allowed initial memory size in bytes (post-instantiation). */
|
|
22
|
+
maxMemoryBytes?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load a WASM plugin and return an elizaOS Plugin interface
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadWasmPlugin(options: WasmLoaderOptions): Promise<Plugin>;
|
|
28
|
+
/**
|
|
29
|
+
* Preload and validate a WASM plugin without fully loading it
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateWasmPlugin(wasmPath: string): Promise<{
|
|
32
|
+
valid: boolean;
|
|
33
|
+
manifest?: PluginManifest;
|
|
34
|
+
error?: string;
|
|
35
|
+
}>;
|
|
36
|
+
//# sourceMappingURL=wasm-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-loader.d.ts","sourceRoot":"","sources":["../typescript/wasm-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EASV,MAAM,EAKP,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAEV,cAAc,EAIf,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC;IAC9B,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAQD;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAmZD;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAClE,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAkBD"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Plugin Loader for elizaOS
|
|
3
|
+
*
|
|
4
|
+
* Loads Rust (or other) plugins compiled to WebAssembly and adapts them
|
|
5
|
+
* to the TypeScript Plugin interface.
|
|
6
|
+
*/
|
|
7
|
+
import { logger } from "@elizaos/core";
|
|
8
|
+
/**
|
|
9
|
+
* Text encoder/decoder for string passing
|
|
10
|
+
*/
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
const decoder = new TextDecoder();
|
|
13
|
+
/**
|
|
14
|
+
* Load a WASM plugin and return an elizaOS Plugin interface
|
|
15
|
+
*/
|
|
16
|
+
export async function loadWasmPlugin(options) {
|
|
17
|
+
const { wasmPath, manifestPath } = options;
|
|
18
|
+
// Load the WASM module
|
|
19
|
+
const wasmInstance = await loadWasmModule(wasmPath, options);
|
|
20
|
+
// Get the manifest from the WASM module or external file
|
|
21
|
+
let manifest;
|
|
22
|
+
if (manifestPath) {
|
|
23
|
+
manifest = await loadManifest(manifestPath);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// Try to get manifest from WASM exports
|
|
27
|
+
const manifestJson = wasmInstance.exports.get_manifest();
|
|
28
|
+
manifest = JSON.parse(manifestJson);
|
|
29
|
+
}
|
|
30
|
+
// Create the plugin adapter
|
|
31
|
+
return createPluginFromWasm(manifest, wasmInstance);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Load a WASM module and instantiate it
|
|
35
|
+
*/
|
|
36
|
+
async function loadWasmModule(wasmPath, options) {
|
|
37
|
+
// Default imports for WASM
|
|
38
|
+
const defaultImports = {
|
|
39
|
+
env: {
|
|
40
|
+
// Console logging
|
|
41
|
+
console_log: (_ptr, _len) => {
|
|
42
|
+
// Will be resolved once we have memory
|
|
43
|
+
},
|
|
44
|
+
console_error: (_ptr, _len) => {
|
|
45
|
+
// Will be resolved once we have memory
|
|
46
|
+
},
|
|
47
|
+
// Abort handler
|
|
48
|
+
abort: (_msg, file, line, column) => {
|
|
49
|
+
throw new Error(`WASM abort at ${file}:${line}:${column}`);
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
wasi_snapshot_preview1: {
|
|
53
|
+
// Minimal WASI stubs for compatibility
|
|
54
|
+
proc_exit: (code) => {
|
|
55
|
+
throw new Error(`WASM exit with code ${code}`);
|
|
56
|
+
},
|
|
57
|
+
fd_write: () => 0,
|
|
58
|
+
fd_read: () => 0,
|
|
59
|
+
fd_close: () => 0,
|
|
60
|
+
fd_seek: () => 0,
|
|
61
|
+
environ_get: () => 0,
|
|
62
|
+
environ_sizes_get: () => 0,
|
|
63
|
+
clock_time_get: () => 0,
|
|
64
|
+
random_get: (_buf, _len) => {
|
|
65
|
+
// Fill with random bytes
|
|
66
|
+
return 0;
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const imports = { ...defaultImports, ...options.imports };
|
|
71
|
+
// Determine if we're in Node.js or browser
|
|
72
|
+
const isNode = typeof globalThis.process !== "undefined" &&
|
|
73
|
+
globalThis.process.versions &&
|
|
74
|
+
globalThis.process.versions.node;
|
|
75
|
+
let wasmModule;
|
|
76
|
+
if (isNode) {
|
|
77
|
+
// Node.js: read file
|
|
78
|
+
const fs = await import("node:fs/promises");
|
|
79
|
+
if (typeof options.maxWasmBytes === "number") {
|
|
80
|
+
const st = await fs.stat(wasmPath);
|
|
81
|
+
if (st.size > options.maxWasmBytes) {
|
|
82
|
+
throw new Error(`WASM binary too large (${st.size} bytes > ${options.maxWasmBytes} bytes)`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const wasmBuffer = await fs.readFile(wasmPath);
|
|
86
|
+
if (typeof options.maxWasmBytes === "number" &&
|
|
87
|
+
wasmBuffer.byteLength > options.maxWasmBytes) {
|
|
88
|
+
throw new Error(`WASM binary too large (${wasmBuffer.byteLength} bytes > ${options.maxWasmBytes} bytes)`);
|
|
89
|
+
}
|
|
90
|
+
wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Browser: fetch
|
|
94
|
+
const response = await fetch(wasmPath);
|
|
95
|
+
const wasmBuffer = await response.arrayBuffer();
|
|
96
|
+
if (typeof options.maxWasmBytes === "number" &&
|
|
97
|
+
wasmBuffer.byteLength > options.maxWasmBytes) {
|
|
98
|
+
throw new Error(`WASM binary too large (${wasmBuffer.byteLength} bytes > ${options.maxWasmBytes} bytes)`);
|
|
99
|
+
}
|
|
100
|
+
wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
101
|
+
}
|
|
102
|
+
const instance = await WebAssembly.instantiate(wasmModule, imports);
|
|
103
|
+
// Set up console logging now that we have memory
|
|
104
|
+
const memory = instance.exports.memory;
|
|
105
|
+
if (typeof options.maxMemoryBytes === "number" &&
|
|
106
|
+
memory.buffer.byteLength > options.maxMemoryBytes) {
|
|
107
|
+
throw new Error(`WASM memory too large (${memory.buffer.byteLength} bytes > ${options.maxMemoryBytes} bytes)`);
|
|
108
|
+
}
|
|
109
|
+
if (imports.env) {
|
|
110
|
+
const env = imports.env;
|
|
111
|
+
env.console_log = (ptr, len) => {
|
|
112
|
+
const bytes = new Uint8Array(memory.buffer, ptr, len);
|
|
113
|
+
logger.info({ src: "interop:wasm", event: "interop.wasm.stdout", stream: "stdout" }, decoder.decode(bytes));
|
|
114
|
+
};
|
|
115
|
+
env.console_error = (ptr, len) => {
|
|
116
|
+
const bytes = new Uint8Array(memory.buffer, ptr, len);
|
|
117
|
+
logger.error({ src: "interop:wasm", event: "interop.wasm.stderr", stream: "stderr" }, decoder.decode(bytes));
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// Provide secure randomness for WASI random_get if present
|
|
121
|
+
if (imports.wasi_snapshot_preview1) {
|
|
122
|
+
const wasi = imports.wasi_snapshot_preview1;
|
|
123
|
+
wasi.random_get = (buf, len) => {
|
|
124
|
+
const view = new Uint8Array(memory.buffer, buf, len);
|
|
125
|
+
const cryptoObj = globalThis.crypto;
|
|
126
|
+
if (!cryptoObj || typeof cryptoObj.getRandomValues !== "function") {
|
|
127
|
+
throw new Error("No secure random source available for WASI random_get");
|
|
128
|
+
}
|
|
129
|
+
cryptoObj.getRandomValues(view);
|
|
130
|
+
return 0;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Type guard to validate exports match WasmPluginExports interface
|
|
134
|
+
const exports = instance.exports;
|
|
135
|
+
const typedExports = {
|
|
136
|
+
get_manifest: exports.get_manifest,
|
|
137
|
+
init: exports.init,
|
|
138
|
+
validate_action: exports.validate_action,
|
|
139
|
+
invoke_action: exports.invoke_action,
|
|
140
|
+
get_provider: exports.get_provider,
|
|
141
|
+
validate_evaluator: exports.validate_evaluator,
|
|
142
|
+
invoke_evaluator: exports.invoke_evaluator,
|
|
143
|
+
handle_route: exports.handle_route,
|
|
144
|
+
alloc: exports.alloc,
|
|
145
|
+
dealloc: exports.dealloc,
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
exports: typedExports,
|
|
149
|
+
memory: { buffer: memory.buffer },
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Load manifest from external JSON file
|
|
154
|
+
*/
|
|
155
|
+
async function loadManifest(manifestPath) {
|
|
156
|
+
const isNode = typeof globalThis.process !== "undefined" &&
|
|
157
|
+
globalThis.process.versions &&
|
|
158
|
+
globalThis.process.versions.node;
|
|
159
|
+
if (isNode) {
|
|
160
|
+
const fs = await import("node:fs/promises");
|
|
161
|
+
const content = await fs.readFile(manifestPath, "utf-8");
|
|
162
|
+
return JSON.parse(content);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const response = await fetch(manifestPath);
|
|
166
|
+
return response.json();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Helper to pass a string to WASM and get result
|
|
171
|
+
*/
|
|
172
|
+
function _callWasmWithString(instance, fn, ...strings) {
|
|
173
|
+
const { exports, memory } = instance;
|
|
174
|
+
const ptrs = [];
|
|
175
|
+
const lens = [];
|
|
176
|
+
// Allocate and write strings
|
|
177
|
+
for (const str of strings) {
|
|
178
|
+
const bytes = encoder.encode(str);
|
|
179
|
+
const ptr = exports.alloc(bytes.length);
|
|
180
|
+
const view = new Uint8Array(memory.buffer, ptr, bytes.length);
|
|
181
|
+
view.set(bytes);
|
|
182
|
+
ptrs.push(ptr);
|
|
183
|
+
lens.push(bytes.length);
|
|
184
|
+
}
|
|
185
|
+
// Call the function
|
|
186
|
+
const args = [];
|
|
187
|
+
for (let i = 0; i < strings.length; i++) {
|
|
188
|
+
args.push(ptrs[i], lens[i]);
|
|
189
|
+
}
|
|
190
|
+
const resultPtr = fn(...args);
|
|
191
|
+
// Read result (assuming null-terminated or length-prefixed)
|
|
192
|
+
// For now, assume it returns a pointer to a null-terminated string
|
|
193
|
+
let resultLen = 0;
|
|
194
|
+
const view = new Uint8Array(memory.buffer);
|
|
195
|
+
while (view[resultPtr + resultLen] !== 0 &&
|
|
196
|
+
resultPtr + resultLen < view.length) {
|
|
197
|
+
resultLen++;
|
|
198
|
+
}
|
|
199
|
+
const result = decoder.decode(new Uint8Array(memory.buffer, resultPtr, resultLen));
|
|
200
|
+
// Deallocate input strings
|
|
201
|
+
for (let i = 0; i < strings.length; i++) {
|
|
202
|
+
exports.dealloc(ptrs[i], lens[i]);
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Create a Plugin from a WASM instance
|
|
208
|
+
*/
|
|
209
|
+
function createPluginFromWasm(manifest, instance) {
|
|
210
|
+
const { exports } = instance;
|
|
211
|
+
// Create action wrappers
|
|
212
|
+
const actions = (manifest.actions ?? []).map((actionDef) => ({
|
|
213
|
+
name: actionDef.name,
|
|
214
|
+
description: actionDef.description,
|
|
215
|
+
similes: actionDef.similes,
|
|
216
|
+
examples: actionDef.examples,
|
|
217
|
+
validate: async (_runtime, message, state) => {
|
|
218
|
+
const result = exports.validate_action(actionDef.name, JSON.stringify(message), JSON.stringify(state ?? null));
|
|
219
|
+
return typeof result === "boolean" ? result : result !== 0;
|
|
220
|
+
},
|
|
221
|
+
handler: async (_runtime, message, state, options, _callback) => {
|
|
222
|
+
const resultJson = exports.invoke_action(actionDef.name, JSON.stringify(message), JSON.stringify(state ?? null), JSON.stringify(options ?? {}));
|
|
223
|
+
const result = JSON.parse(resultJson);
|
|
224
|
+
return {
|
|
225
|
+
success: result.success,
|
|
226
|
+
text: result.text,
|
|
227
|
+
error: result.error ? new Error(result.error) : undefined,
|
|
228
|
+
data: result.data,
|
|
229
|
+
values: result.values,
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
}));
|
|
233
|
+
// Create provider wrappers
|
|
234
|
+
const providers = (manifest.providers ?? []).map((providerDef) => ({
|
|
235
|
+
name: providerDef.name,
|
|
236
|
+
description: providerDef.description,
|
|
237
|
+
dynamic: providerDef.dynamic,
|
|
238
|
+
position: providerDef.position,
|
|
239
|
+
private: providerDef.private,
|
|
240
|
+
get: async (_runtime, message, state) => {
|
|
241
|
+
const resultJson = exports.get_provider(providerDef.name, JSON.stringify(message), JSON.stringify(state));
|
|
242
|
+
const result = JSON.parse(resultJson);
|
|
243
|
+
return {
|
|
244
|
+
text: result.text,
|
|
245
|
+
values: result.values,
|
|
246
|
+
data: result.data,
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
}));
|
|
250
|
+
// Create evaluator wrappers
|
|
251
|
+
const evaluators = (manifest.evaluators ?? []).map((evalDef) => ({
|
|
252
|
+
name: evalDef.name,
|
|
253
|
+
description: evalDef.description,
|
|
254
|
+
alwaysRun: evalDef.alwaysRun,
|
|
255
|
+
similes: evalDef.similes,
|
|
256
|
+
examples: [],
|
|
257
|
+
validate: async (_runtime, message, state) => {
|
|
258
|
+
const result = exports.validate_evaluator(evalDef.name, JSON.stringify(message), JSON.stringify(state ?? null));
|
|
259
|
+
return typeof result === "boolean" ? result : result !== 0;
|
|
260
|
+
},
|
|
261
|
+
handler: async (_runtime, message, state) => {
|
|
262
|
+
const resultJson = exports.invoke_evaluator(evalDef.name, JSON.stringify(message), JSON.stringify(state ?? null));
|
|
263
|
+
if (!resultJson || resultJson === "null") {
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
const result = JSON.parse(resultJson);
|
|
267
|
+
return {
|
|
268
|
+
success: result.success,
|
|
269
|
+
text: result.text,
|
|
270
|
+
error: result.error ? new Error(result.error) : undefined,
|
|
271
|
+
data: result.data,
|
|
272
|
+
values: result.values,
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
}));
|
|
276
|
+
// Return the plugin
|
|
277
|
+
return {
|
|
278
|
+
name: manifest.name,
|
|
279
|
+
description: manifest.description,
|
|
280
|
+
config: manifest.config ?? {},
|
|
281
|
+
dependencies: manifest.dependencies,
|
|
282
|
+
actions,
|
|
283
|
+
providers,
|
|
284
|
+
evaluators,
|
|
285
|
+
// Routes would need special handling for WASM
|
|
286
|
+
routes: [],
|
|
287
|
+
// Services need special handling
|
|
288
|
+
services: [],
|
|
289
|
+
async init(config) {
|
|
290
|
+
exports.init(JSON.stringify(config));
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Preload and validate a WASM plugin without fully loading it
|
|
296
|
+
*/
|
|
297
|
+
export async function validateWasmPlugin(wasmPath) {
|
|
298
|
+
try {
|
|
299
|
+
const instance = await loadWasmModule(wasmPath, {});
|
|
300
|
+
const manifestJson = instance.exports.get_manifest();
|
|
301
|
+
const manifest = JSON.parse(manifestJson);
|
|
302
|
+
// Basic validation
|
|
303
|
+
if (!manifest.name || !manifest.description) {
|
|
304
|
+
return { valid: false, error: "Missing required manifest fields" };
|
|
305
|
+
}
|
|
306
|
+
return { valid: true, manifest };
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
return {
|
|
310
|
+
valid: false,
|
|
311
|
+
error: error instanceof Error ? error.message : String(error),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|