@cogitator-ai/wasm-tools 0.7.4 → 0.7.6
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 +26 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@ WASM-based tools for Cogitator agents. Secure, sandboxed tool execution using We
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- **14 pre-built tools** - calculator, JSON, hash, Base64, slug, validation, diff, regex, CSV, Markdown, XML, datetime, compression, Ed25519 signing
|
|
8
|
+
- **Isolated execution** - every call runs in an Extism sandbox in a worker thread, without filesystem or network access
|
|
9
|
+
- **Fast startup** - no container to start; compiled modules are cached per file
|
|
10
|
+
- **Custom tool framework** - `defineWasmTool()` for your own WASM modules
|
|
11
|
+
- **Hot-reload support** - `WasmToolManager` reloads modules when their files change
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
@@ -18,6 +18,8 @@ pnpm add @cogitator-ai/wasm-tools
|
|
|
18
18
|
|
|
19
19
|
`@extism/extism` (>= 2.0.0-rc13, the current `latest` on npm) is installed as a dependency; the pre-built plugins are compiled with `extism-js` and need its host functions and WASI.
|
|
20
20
|
|
|
21
|
+
Website docs: [WASM Tools](https://cogitator.app/docs/tools/wasm-tools), [Sandbox](https://cogitator.app/docs/deployment/sandbox).
|
|
22
|
+
|
|
21
23
|
## How Tools Execute
|
|
22
24
|
|
|
23
25
|
Every tool created here carries a `sandbox: { type: 'wasm', ... }` config and a real `execute()`:
|
|
@@ -60,7 +62,8 @@ import { Cogitator, Agent } from '@cogitator-ai/core';
|
|
|
60
62
|
|
|
61
63
|
const agent = new Agent({
|
|
62
64
|
name: 'utility-assistant',
|
|
63
|
-
model: 'gpt-6.1-sol',
|
|
65
|
+
model: 'openai/gpt-6.1-sol',
|
|
66
|
+
instructions: 'Use your tools for calculations and data transformations.',
|
|
64
67
|
tools: [
|
|
65
68
|
createCalcTool(),
|
|
66
69
|
createJsonTool(),
|
|
@@ -79,7 +82,9 @@ const agent = new Agent({
|
|
|
79
82
|
],
|
|
80
83
|
});
|
|
81
84
|
|
|
82
|
-
const cog = new Cogitator({
|
|
85
|
+
const cog = new Cogitator({
|
|
86
|
+
llm: { providers: { openai: { apiKey: process.env.OPENAI_API_KEY! } } },
|
|
87
|
+
});
|
|
83
88
|
const result = await cog.run(agent, {
|
|
84
89
|
input: 'Calculate the SHA-256 hash of "hello world"',
|
|
85
90
|
});
|
|
@@ -91,6 +96,7 @@ Create custom tools that run in the WASM sandbox:
|
|
|
91
96
|
|
|
92
97
|
```typescript
|
|
93
98
|
import { defineWasmTool } from '@cogitator-ai/wasm-tools';
|
|
99
|
+
import { Agent } from '@cogitator-ai/core';
|
|
94
100
|
import { z } from 'zod';
|
|
95
101
|
|
|
96
102
|
const hashTool = defineWasmTool({
|
|
@@ -109,6 +115,8 @@ const hashTool = defineWasmTool({
|
|
|
109
115
|
|
|
110
116
|
const agent = new Agent({
|
|
111
117
|
name: 'hasher',
|
|
118
|
+
model: 'openai/gpt-6.1-sol',
|
|
119
|
+
instructions: 'Hash text on request.',
|
|
112
120
|
tools: [hashTool],
|
|
113
121
|
});
|
|
114
122
|
```
|
|
@@ -137,12 +145,16 @@ const calcTool = await manager.load('./plugins/calc.wasm');
|
|
|
137
145
|
// Get all tools for agent
|
|
138
146
|
const agent = new Agent({
|
|
139
147
|
name: 'wasm-agent',
|
|
148
|
+
model: 'openai/gpt-6.1-sol',
|
|
149
|
+
instructions: 'Use the loaded tools.',
|
|
140
150
|
tools: manager.getTools(),
|
|
141
151
|
});
|
|
142
152
|
|
|
143
153
|
// Tools automatically use the latest plugin version after reload
|
|
144
|
-
const cogitator = new Cogitator({
|
|
145
|
-
|
|
154
|
+
const cogitator = new Cogitator({
|
|
155
|
+
llm: { providers: { openai: { apiKey: process.env.OPENAI_API_KEY! } } },
|
|
156
|
+
});
|
|
157
|
+
await cogitator.run(agent, { input: 'Calculate 2 + 2' });
|
|
146
158
|
|
|
147
159
|
// Cleanup when done
|
|
148
160
|
await manager.close();
|
|
@@ -360,7 +372,7 @@ const signing = createSigningTool({ timeout: 10000 });
|
|
|
360
372
|
// Verify: { operation: "verify", algorithm: "ed25519", message: "hello", publicKey: "...", signature: "..." }
|
|
361
373
|
```
|
|
362
374
|
|
|
363
|
-
WASM has no secure random source, so
|
|
375
|
+
WASM has no secure random source, so the tool generates a 32-byte seed on the host with `node:crypto` when `generateKeypair` is called without `seed`; the seed is the private key. Keys and signatures use `encoding: 'hex'` (default) or `'base64'`. Signatures are RFC 8032 Ed25519 and interoperate with `node:crypto`; non-canonical or off-curve public keys fail verification. Empty messages are allowed.
|
|
364
376
|
|
|
365
377
|
### getWasmPath(name)
|
|
366
378
|
|
|
@@ -373,6 +385,8 @@ const calcPath = getWasmPath('calc'); // Path to calc.wasm
|
|
|
373
385
|
const jsonPath = getWasmPath('json'); // Path to json.wasm
|
|
374
386
|
```
|
|
375
387
|
|
|
388
|
+
The result is an absolute path, so it works as `wasmModule` everywhere, whatever the package manager layout. With `@cogitator-ai/sandbox` you can also pass the package path `@cogitator-ai/wasm-tools/wasm/calc.wasm`: the WASM executor resolves it from your application (working directory first, then the entry script's directory).
|
|
389
|
+
|
|
376
390
|
### WasmToolManager
|
|
377
391
|
|
|
378
392
|
Manage WASM tools with hot-reload support.
|
|
@@ -391,7 +405,7 @@ interface WasmToolCallbacks {
|
|
|
391
405
|
onError?: (name: string, path: string, error: Error) => void;
|
|
392
406
|
}
|
|
393
407
|
|
|
394
|
-
class WasmToolManager {
|
|
408
|
+
declare class WasmToolManager {
|
|
395
409
|
constructor(options?: WasmToolManagerOptions);
|
|
396
410
|
|
|
397
411
|
// Watch a glob pattern for WASM files
|
|
@@ -419,7 +433,7 @@ Manager tools call the module's exported `run` function with the JSON-encoded pa
|
|
|
419
433
|
|
|
420
434
|
### Legacy Exports
|
|
421
435
|
|
|
422
|
-
For direct sandbox usage:
|
|
436
|
+
For direct sandbox usage (pre-built modules are also reachable as `@cogitator-ai/wasm-tools/wasm/<name>.wasm`):
|
|
423
437
|
|
|
424
438
|
| Export | Description |
|
|
425
439
|
| ------------------ | ----------------------------------------- |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/wasm-tools",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "WASM-based tools for Cogitator agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"node": ">=22.12.0"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@cogitator-ai/types": "0.
|
|
22
|
+
"@cogitator-ai/types": "0.30.0",
|
|
23
23
|
"@extism/extism": "^2.0.0-rc13",
|
|
24
24
|
"chokidar": "^5.0.0",
|
|
25
25
|
"zod": "^4.6.5"
|