@elizaos/interop 2.0.0-alpha → 2.0.0-alpha.10

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.
@@ -1,301 +0,0 @@
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
@@ -1 +0,0 @@
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,MA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MAAM,GACjB,MAAM,CAAC;IAEV,4BAA4B;IAC5B,kBAAkB,CAChB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;IAEX,gDAAgD;IAChD,gBAAgB,CACd,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC;IAEV,6CAA6C;IAC7C,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzE,4CAA4C;IAC5C,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAE5B,0BAA0B;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,MAAM,EAAE,UAAU,CAAC;CACpB"}
@@ -1,10 +0,0 @@
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 {};
@@ -1,32 +0,0 @@
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
- }
20
- /**
21
- * Load a WASM plugin and return an elizaOS Plugin interface
22
- */
23
- export declare function loadWasmPlugin(options: WasmLoaderOptions): Promise<Plugin>;
24
- /**
25
- * Preload and validate a WASM plugin without fully loading it
26
- */
27
- export declare function validateWasmPlugin(wasmPath: string): Promise<{
28
- valid: boolean;
29
- manifest?: PluginManifest;
30
- error?: string;
31
- }>;
32
- //# sourceMappingURL=wasm-loader.d.ts.map
@@ -1 +0,0 @@
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;AAEvB,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;CAC/B;AAQD;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAsTD;;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"}
@@ -1,269 +0,0 @@
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
- /**
8
- * Text encoder/decoder for string passing
9
- */
10
- const encoder = new TextEncoder();
11
- const decoder = new TextDecoder();
12
- /**
13
- * Load a WASM plugin and return an elizaOS Plugin interface
14
- */
15
- export async function loadWasmPlugin(options) {
16
- const { wasmPath, manifestPath } = options;
17
- // Load the WASM module
18
- const wasmInstance = await loadWasmModule(wasmPath, options.imports);
19
- // Get the manifest from the WASM module or external file
20
- let manifest;
21
- if (manifestPath) {
22
- manifest = await loadManifest(manifestPath);
23
- }
24
- else {
25
- // Try to get manifest from WASM exports
26
- const manifestJson = wasmInstance.exports.get_manifest();
27
- manifest = JSON.parse(manifestJson);
28
- }
29
- // Create the plugin adapter
30
- return createPluginFromWasm(manifest, wasmInstance);
31
- }
32
- /**
33
- * Load a WASM module and instantiate it
34
- */
35
- async function loadWasmModule(wasmPath, customImports) {
36
- // Default imports for WASM
37
- const defaultImports = {
38
- env: {
39
- // Console logging
40
- console_log: (_ptr, _len) => {
41
- // Will be resolved once we have memory
42
- },
43
- console_error: (_ptr, _len) => {
44
- // Will be resolved once we have memory
45
- },
46
- // Abort handler
47
- abort: (_msg, file, line, column) => {
48
- throw new Error(`WASM abort at ${file}:${line}:${column}`);
49
- },
50
- },
51
- wasi_snapshot_preview1: {
52
- // Minimal WASI stubs for compatibility
53
- proc_exit: (code) => {
54
- throw new Error(`WASM exit with code ${code}`);
55
- },
56
- fd_write: () => 0,
57
- fd_read: () => 0,
58
- fd_close: () => 0,
59
- fd_seek: () => 0,
60
- environ_get: () => 0,
61
- environ_sizes_get: () => 0,
62
- clock_time_get: () => 0,
63
- random_get: (_buf, _len) => {
64
- // Fill with random bytes
65
- return 0;
66
- },
67
- },
68
- };
69
- const imports = { ...defaultImports, ...customImports };
70
- // Determine if we're in Node.js or browser
71
- const isNode = typeof globalThis.process !== "undefined" &&
72
- globalThis.process.versions &&
73
- globalThis.process.versions.node;
74
- let wasmModule;
75
- if (isNode) {
76
- // Node.js: read file
77
- const fs = await import("node:fs/promises");
78
- const wasmBuffer = await fs.readFile(wasmPath);
79
- wasmModule = await WebAssembly.compile(wasmBuffer);
80
- }
81
- else {
82
- // Browser: fetch
83
- const response = await fetch(wasmPath);
84
- const wasmBuffer = await response.arrayBuffer();
85
- wasmModule = await WebAssembly.compile(wasmBuffer);
86
- }
87
- let instance = await WebAssembly.instantiate(wasmModule, defaultImports);
88
- instance = await WebAssembly.instantiate(wasmModule, imports);
89
- // Set up console logging now that we have memory
90
- const memory = instance.exports.memory;
91
- if (imports.env) {
92
- const env = imports.env;
93
- env.console_log = (ptr, len) => {
94
- const bytes = new Uint8Array(memory.buffer, ptr, len);
95
- console.log(decoder.decode(bytes));
96
- };
97
- env.console_error = (ptr, len) => {
98
- const bytes = new Uint8Array(memory.buffer, ptr, len);
99
- console.error(decoder.decode(bytes));
100
- };
101
- }
102
- return {
103
- exports: instance.exports,
104
- memory: { buffer: memory.buffer },
105
- };
106
- }
107
- /**
108
- * Load manifest from external JSON file
109
- */
110
- async function loadManifest(manifestPath) {
111
- const isNode = typeof globalThis.process !== "undefined" &&
112
- globalThis.process.versions &&
113
- globalThis.process.versions.node;
114
- if (isNode) {
115
- const fs = await import("node:fs/promises");
116
- const content = await fs.readFile(manifestPath, "utf-8");
117
- return JSON.parse(content);
118
- }
119
- else {
120
- const response = await fetch(manifestPath);
121
- return response.json();
122
- }
123
- }
124
- /**
125
- * Helper to pass a string to WASM and get result
126
- */
127
- function _callWasmWithString(instance, fn, ...strings) {
128
- const { exports, memory } = instance;
129
- const ptrs = [];
130
- const lens = [];
131
- // Allocate and write strings
132
- for (const str of strings) {
133
- const bytes = encoder.encode(str);
134
- const ptr = exports.alloc(bytes.length);
135
- const view = new Uint8Array(memory.buffer, ptr, bytes.length);
136
- view.set(bytes);
137
- ptrs.push(ptr);
138
- lens.push(bytes.length);
139
- }
140
- // Call the function
141
- const args = [];
142
- for (let i = 0; i < strings.length; i++) {
143
- args.push(ptrs[i], lens[i]);
144
- }
145
- const resultPtr = fn(...args);
146
- // Read result (assuming null-terminated or length-prefixed)
147
- // For now, assume it returns a pointer to a null-terminated string
148
- let resultLen = 0;
149
- const view = new Uint8Array(memory.buffer);
150
- while (view[resultPtr + resultLen] !== 0 &&
151
- resultPtr + resultLen < view.length) {
152
- resultLen++;
153
- }
154
- const result = decoder.decode(new Uint8Array(memory.buffer, resultPtr, resultLen));
155
- // Deallocate input strings
156
- for (let i = 0; i < strings.length; i++) {
157
- exports.dealloc(ptrs[i], lens[i]);
158
- }
159
- return result;
160
- }
161
- /**
162
- * Create a Plugin from a WASM instance
163
- */
164
- function createPluginFromWasm(manifest, instance) {
165
- const { exports } = instance;
166
- // Create action wrappers
167
- const actions = (manifest.actions ?? []).map((actionDef) => ({
168
- name: actionDef.name,
169
- description: actionDef.description,
170
- similes: actionDef.similes,
171
- examples: actionDef.examples,
172
- validate: async (_runtime, message, state) => {
173
- const result = exports.validate_action(actionDef.name, JSON.stringify(message), JSON.stringify(state ?? null));
174
- return typeof result === "boolean" ? result : result !== 0;
175
- },
176
- handler: async (_runtime, message, state, options, _callback) => {
177
- const resultJson = exports.invoke_action(actionDef.name, JSON.stringify(message), JSON.stringify(state ?? null), JSON.stringify(options ?? {}));
178
- const result = JSON.parse(resultJson);
179
- return {
180
- success: result.success,
181
- text: result.text,
182
- error: result.error ? new Error(result.error) : undefined,
183
- data: result.data,
184
- values: result.values,
185
- };
186
- },
187
- }));
188
- // Create provider wrappers
189
- const providers = (manifest.providers ?? []).map((providerDef) => ({
190
- name: providerDef.name,
191
- description: providerDef.description,
192
- dynamic: providerDef.dynamic,
193
- position: providerDef.position,
194
- private: providerDef.private,
195
- get: async (_runtime, message, state) => {
196
- const resultJson = exports.get_provider(providerDef.name, JSON.stringify(message), JSON.stringify(state));
197
- const result = JSON.parse(resultJson);
198
- return {
199
- text: result.text,
200
- values: result.values,
201
- data: result.data,
202
- };
203
- },
204
- }));
205
- // Create evaluator wrappers
206
- const evaluators = (manifest.evaluators ?? []).map((evalDef) => ({
207
- name: evalDef.name,
208
- description: evalDef.description,
209
- alwaysRun: evalDef.alwaysRun,
210
- similes: evalDef.similes,
211
- examples: [],
212
- validate: async (_runtime, message, state) => {
213
- const result = exports.validate_evaluator(evalDef.name, JSON.stringify(message), JSON.stringify(state ?? null));
214
- return typeof result === "boolean" ? result : result !== 0;
215
- },
216
- handler: async (_runtime, message, state) => {
217
- const resultJson = exports.invoke_evaluator(evalDef.name, JSON.stringify(message), JSON.stringify(state ?? null));
218
- if (!resultJson || resultJson === "null") {
219
- return undefined;
220
- }
221
- const result = JSON.parse(resultJson);
222
- return {
223
- success: result.success,
224
- text: result.text,
225
- error: result.error ? new Error(result.error) : undefined,
226
- data: result.data,
227
- values: result.values,
228
- };
229
- },
230
- }));
231
- // Return the plugin
232
- return {
233
- name: manifest.name,
234
- description: manifest.description,
235
- config: manifest.config ?? {},
236
- dependencies: manifest.dependencies,
237
- actions,
238
- providers,
239
- evaluators,
240
- // Routes would need special handling for WASM
241
- routes: [],
242
- // Services need special handling
243
- services: [],
244
- async init(config) {
245
- exports.init(JSON.stringify(config));
246
- },
247
- };
248
- }
249
- /**
250
- * Preload and validate a WASM plugin without fully loading it
251
- */
252
- export async function validateWasmPlugin(wasmPath) {
253
- try {
254
- const instance = await loadWasmModule(wasmPath, {});
255
- const manifestJson = instance.exports.get_manifest();
256
- const manifest = JSON.parse(manifestJson);
257
- // Basic validation
258
- if (!manifest.name || !manifest.description) {
259
- return { valid: false, error: "Missing required manifest fields" };
260
- }
261
- return { valid: true, manifest };
262
- }
263
- catch (error) {
264
- return {
265
- valid: false,
266
- error: error instanceof Error ? error.message : String(error),
267
- };
268
- }
269
- }