@capsule-run/cli 0.3.2 → 0.4.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 +53 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -42,6 +42,9 @@ Run it:
|
|
|
42
42
|
capsule run hello.ts
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
> [!TIP]
|
|
46
|
+
> Use `--verbose` to display real-time task execution details.
|
|
47
|
+
|
|
45
48
|
## How It Works
|
|
46
49
|
|
|
47
50
|
Simply use a wrapper function to define your tasks:
|
|
@@ -60,7 +63,6 @@ export const analyzeData = task({
|
|
|
60
63
|
return { processed: dataset.length, status: "complete" };
|
|
61
64
|
});
|
|
62
65
|
|
|
63
|
-
// The "main" task is required as the entrypoint
|
|
64
66
|
export const main = task({
|
|
65
67
|
name: "main",
|
|
66
68
|
compute: "HIGH"
|
|
@@ -69,8 +71,38 @@ export const main = task({
|
|
|
69
71
|
});
|
|
70
72
|
```
|
|
71
73
|
|
|
74
|
+
> [!NOTE]
|
|
75
|
+
> The runtime requires a task named `"main"` as the entry point.
|
|
76
|
+
|
|
72
77
|
When you run `capsule run main.ts`, your code is compiled into a WebAssembly module and executed in a dedicated sandbox.
|
|
73
78
|
|
|
79
|
+
### Response Format
|
|
80
|
+
|
|
81
|
+
Every task returns a structured JSON envelope containing both the result and execution metadata:
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"success": true,
|
|
85
|
+
"result": { "processed": 5, "status": "complete" },
|
|
86
|
+
"error": null,
|
|
87
|
+
"execution": {
|
|
88
|
+
"task_name": "data_processor",
|
|
89
|
+
"duration_ms": 1523,
|
|
90
|
+
"retries": 0,
|
|
91
|
+
"fuel_consumed": 45000
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Response fields:**
|
|
97
|
+
- `success` — Boolean indicating whether the task completed successfully
|
|
98
|
+
- `result` — The actual return value from your task (json, string, null on failure etc..)
|
|
99
|
+
- `error` — Error details if the task failed (`{ error_type: string, message: string }`)
|
|
100
|
+
- `execution` — Performance metrics:
|
|
101
|
+
- `task_name` — Name of the executed task
|
|
102
|
+
- `duration_ms` — Execution time in milliseconds
|
|
103
|
+
- `retries` — Number of retry attempts that occurred
|
|
104
|
+
- `fuel_consumed` — CPU resources used (see [Compute Levels](#compute-levels))
|
|
105
|
+
|
|
74
106
|
## Documentation
|
|
75
107
|
|
|
76
108
|
### Task Configuration Options
|
|
@@ -91,9 +123,27 @@ When you run `capsule run main.ts`, your code is compiled into a WebAssembly mod
|
|
|
91
123
|
- **HIGH**: Maximum fuel for compute-intensive operations
|
|
92
124
|
- **CUSTOM**: Specify exact fuel value (e.g., `compute="1000000"`)
|
|
93
125
|
|
|
126
|
+
### Project Configuration (Optional)
|
|
127
|
+
|
|
128
|
+
Create a `capsule.toml` file in your project root to set default options:
|
|
129
|
+
|
|
130
|
+
```toml
|
|
131
|
+
[workflow]
|
|
132
|
+
name = "My AI Workflow"
|
|
133
|
+
version = "1.0.0"
|
|
134
|
+
entrypoint = "src/main.ts" # Run `capsule run` without specifying a file
|
|
135
|
+
|
|
136
|
+
[tasks]
|
|
137
|
+
default_compute = "MEDIUM"
|
|
138
|
+
default_ram = "256MB"
|
|
139
|
+
default_timeout = "30s"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Task-level options always override these defaults.
|
|
143
|
+
|
|
94
144
|
### File Access
|
|
95
145
|
|
|
96
|
-
|
|
146
|
+
Tasks can read and write files within directories specified in `allowedFiles`. Any attempt to access files outside these directories is not possible.
|
|
97
147
|
|
|
98
148
|
Node.js built-ins like `fs` are not available in the WebAssembly sandbox. Instead, use the `files` API provided by the SDK:
|
|
99
149
|
|
|
@@ -108,7 +158,7 @@ export const restrictedWriter = task({
|
|
|
108
158
|
});
|
|
109
159
|
|
|
110
160
|
export const main = task({ name: "main" }, async () => {
|
|
111
|
-
restrictedWriter();
|
|
161
|
+
await restrictedWriter();
|
|
112
162
|
return await files.readText("./data/input.txt");
|
|
113
163
|
});
|
|
114
164
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capsule-run/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Secure WASM runtime to isolate and manage AI agent tasks",
|
|
5
5
|
"bin": {
|
|
6
6
|
"capsule": "./bin/capsule.js"
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"node": ">=18"
|
|
30
30
|
},
|
|
31
31
|
"optionalDependencies": {
|
|
32
|
-
"@capsule-run/cli-darwin-arm64": "0.
|
|
33
|
-
"@capsule-run/cli-darwin-x64": "0.
|
|
34
|
-
"@capsule-run/cli-linux-x64": "0.
|
|
35
|
-
"@capsule-run/cli-win32-x64": "0.
|
|
32
|
+
"@capsule-run/cli-darwin-arm64": "0.4.0",
|
|
33
|
+
"@capsule-run/cli-darwin-x64": "0.4.0",
|
|
34
|
+
"@capsule-run/cli-linux-x64": "0.4.0",
|
|
35
|
+
"@capsule-run/cli-win32-x64": "0.4.0"
|
|
36
36
|
}
|
|
37
37
|
}
|