@aigne/afs-sandbox 1.11.0-beta.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.
- package/LICENSE.md +26 -0
- package/README.md +439 -0
- package/dist/index.d.mts +586 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2054 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import { AFSAccessMode, AFSDeleteResult, AFSEntry, AFSExecResult, AFSExplainResult, AFSListResult, AFSModuleLoadParams, AFSRoot, AFSStatResult, AFSWriteEntryPayload, AFSWriteResult, ProviderManifest } from "@aigne/afs";
|
|
2
|
+
import { AFSBaseProvider, RouteContext } from "@aigne/afs/provider";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Log levels for sandbox logging
|
|
8
|
+
*/
|
|
9
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
10
|
+
/**
|
|
11
|
+
* A single log entry from sandbox execution
|
|
12
|
+
*/
|
|
13
|
+
interface LogEntry {
|
|
14
|
+
level: LogLevel;
|
|
15
|
+
message: string;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of script execution
|
|
20
|
+
*/
|
|
21
|
+
interface ExecutionResult {
|
|
22
|
+
/** Whether execution succeeded (no uncaught errors) */
|
|
23
|
+
success: boolean;
|
|
24
|
+
/** Return value from the script (if any) */
|
|
25
|
+
result?: unknown;
|
|
26
|
+
/** Error message if execution failed */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** Stack trace for debugging */
|
|
29
|
+
stack?: string;
|
|
30
|
+
/** Log entries captured during execution */
|
|
31
|
+
logs: LogEntry[];
|
|
32
|
+
/** Execution duration in milliseconds */
|
|
33
|
+
duration: number;
|
|
34
|
+
/** Whether execution was terminated due to timeout */
|
|
35
|
+
timedOut?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runtime configuration options
|
|
39
|
+
*/
|
|
40
|
+
interface RuntimeOptions {
|
|
41
|
+
/** Execution timeout in milliseconds (default: 5000) */
|
|
42
|
+
timeout?: number;
|
|
43
|
+
/** Memory limit in MB (default: 128) */
|
|
44
|
+
memoryLimit?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Capability API configuration
|
|
48
|
+
*/
|
|
49
|
+
interface CapabilitiesConfig {
|
|
50
|
+
/** AFS access configuration */
|
|
51
|
+
afs?: {
|
|
52
|
+
/** Enable read operations */read?: boolean; /** Enable write operations (Phase 2+) */
|
|
53
|
+
write?: boolean; /** Allowed path patterns */
|
|
54
|
+
allowPaths?: string[]; /** Denied path patterns */
|
|
55
|
+
denyPaths?: string[];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Promoted action definition
|
|
60
|
+
*/
|
|
61
|
+
interface PromotedAction {
|
|
62
|
+
/** Action name (unique identifier) */
|
|
63
|
+
name: string;
|
|
64
|
+
/** Human-readable description */
|
|
65
|
+
description?: string;
|
|
66
|
+
/** Source script name */
|
|
67
|
+
sourceScript: string;
|
|
68
|
+
/** Source script version at promotion time */
|
|
69
|
+
sourceVersion: number;
|
|
70
|
+
/** JSON schema for input validation */
|
|
71
|
+
inputSchema?: Record<string, unknown>;
|
|
72
|
+
/** JSON schema for output */
|
|
73
|
+
outputSchema?: Record<string, unknown>;
|
|
74
|
+
/** When the action was promoted */
|
|
75
|
+
promotedAt: Date;
|
|
76
|
+
/** Version of this promoted action */
|
|
77
|
+
version: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Script template definition
|
|
81
|
+
*/
|
|
82
|
+
interface ScriptTemplate {
|
|
83
|
+
/** Template name (unique identifier) */
|
|
84
|
+
name: string;
|
|
85
|
+
/** Human-readable description */
|
|
86
|
+
description: string;
|
|
87
|
+
/** Template content with placeholders */
|
|
88
|
+
content: string;
|
|
89
|
+
/** Variable definitions for template */
|
|
90
|
+
variables?: {
|
|
91
|
+
name: string;
|
|
92
|
+
description: string;
|
|
93
|
+
required?: boolean;
|
|
94
|
+
default?: string;
|
|
95
|
+
}[];
|
|
96
|
+
/** Category for organization */
|
|
97
|
+
category?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Audit event types
|
|
101
|
+
*/
|
|
102
|
+
type AuditEventType = "execution" | "capability" | "security" | "script_write" | "script_delete" | "action_promote";
|
|
103
|
+
/**
|
|
104
|
+
* Audit event entry
|
|
105
|
+
*/
|
|
106
|
+
interface AuditEvent {
|
|
107
|
+
/** Event type */
|
|
108
|
+
type: AuditEventType;
|
|
109
|
+
/** When the event occurred */
|
|
110
|
+
timestamp: number;
|
|
111
|
+
/** User ID if available */
|
|
112
|
+
userId?: string;
|
|
113
|
+
/** Session ID if available */
|
|
114
|
+
sessionId?: string;
|
|
115
|
+
/** Script name if applicable */
|
|
116
|
+
scriptName?: string;
|
|
117
|
+
/** Action name if applicable */
|
|
118
|
+
actionName?: string;
|
|
119
|
+
/** Capability used if applicable */
|
|
120
|
+
capability?: string;
|
|
121
|
+
/** Path accessed if applicable */
|
|
122
|
+
path?: string;
|
|
123
|
+
/** Whether the action succeeded */
|
|
124
|
+
success?: boolean;
|
|
125
|
+
/** Error message if failed */
|
|
126
|
+
error?: string;
|
|
127
|
+
/** Additional details */
|
|
128
|
+
details?: Record<string, unknown>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Audit configuration
|
|
132
|
+
*/
|
|
133
|
+
interface AuditConfig {
|
|
134
|
+
/** Enable audit logging */
|
|
135
|
+
enabled: boolean;
|
|
136
|
+
/** Callback for audit events */
|
|
137
|
+
onEvent?: (event: AuditEvent) => void;
|
|
138
|
+
/** Maximum audit log entries to keep in memory */
|
|
139
|
+
maxEntries?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Rate limit configuration
|
|
143
|
+
*/
|
|
144
|
+
interface RateLimitConfig {
|
|
145
|
+
/** Max executions per minute globally */
|
|
146
|
+
maxExecutionsPerMinute?: number;
|
|
147
|
+
/** Max executions per minute per user */
|
|
148
|
+
maxExecutionsPerMinutePerUser?: number;
|
|
149
|
+
/** Max executions per minute per script */
|
|
150
|
+
maxExecutionsPerMinutePerScript?: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Execution metrics
|
|
154
|
+
*/
|
|
155
|
+
interface ExecutionMetrics {
|
|
156
|
+
/** Total number of executions */
|
|
157
|
+
totalExecutions: number;
|
|
158
|
+
/** Number of successful executions */
|
|
159
|
+
successCount: number;
|
|
160
|
+
/** Number of failed executions */
|
|
161
|
+
failureCount: number;
|
|
162
|
+
/** Number of timed out executions */
|
|
163
|
+
timeoutCount: number;
|
|
164
|
+
/** Average execution duration in ms */
|
|
165
|
+
averageDuration: number;
|
|
166
|
+
/** Total execution duration for averaging */
|
|
167
|
+
totalDuration: number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Options for AFSSandbox provider
|
|
171
|
+
*/
|
|
172
|
+
interface AFSSandboxOptions {
|
|
173
|
+
/** Module name (default: "sandbox") */
|
|
174
|
+
name?: string;
|
|
175
|
+
/** Module description */
|
|
176
|
+
description?: string;
|
|
177
|
+
/** Access mode (default: "readwrite") */
|
|
178
|
+
accessMode?: AFSAccessMode;
|
|
179
|
+
/** Runtime configuration */
|
|
180
|
+
runtime?: RuntimeOptions;
|
|
181
|
+
/** Capabilities configuration */
|
|
182
|
+
capabilities?: CapabilitiesConfig;
|
|
183
|
+
/** Audit configuration (Phase 3) */
|
|
184
|
+
audit?: AuditConfig;
|
|
185
|
+
/** Rate limiting configuration (Phase 3) */
|
|
186
|
+
rateLimit?: RateLimitConfig;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/index.d.ts
|
|
190
|
+
/**
|
|
191
|
+
* AFS Sandbox Provider
|
|
192
|
+
*
|
|
193
|
+
* Provides a sandboxed JavaScript execution environment for LLM-generated code.
|
|
194
|
+
* Scripts are stored at `/scripts/{name}.js` and executed directly via exec().
|
|
195
|
+
*
|
|
196
|
+
* Structure:
|
|
197
|
+
* - `/` - root directory
|
|
198
|
+
* - `/scripts` - stored scripts directory
|
|
199
|
+
* - `/scripts/{name}.js` - individual script files (executable)
|
|
200
|
+
* - `/templates` - script templates
|
|
201
|
+
* - `/templates/{name}` - individual templates
|
|
202
|
+
* - `/metrics` - execution metrics
|
|
203
|
+
* - `/audit` - audit log
|
|
204
|
+
* - `/.actions` - root-level actions (run, validate, promote, create-from-template)
|
|
205
|
+
* - `/scripts/{name}.js/.actions` - script-level actions (exec, history, exec-history)
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const sandbox = new AFSSandbox({ name: "sandbox" });
|
|
210
|
+
* afs.mount(sandbox);
|
|
211
|
+
*
|
|
212
|
+
* // Write a script
|
|
213
|
+
* await afs.write("/modules/sandbox/scripts/greet.js", {
|
|
214
|
+
* content: `
|
|
215
|
+
* afs.log("info", "Hello from sandbox!");
|
|
216
|
+
* return "Hello, " + args.name;
|
|
217
|
+
* `
|
|
218
|
+
* });
|
|
219
|
+
*
|
|
220
|
+
* // Execute the script
|
|
221
|
+
* const result = await afs.exec("/modules/sandbox/scripts/greet.js", { name: "World" });
|
|
222
|
+
* // result.data = { success: true, result: "Hello, World", logs: [...] }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
declare class AFSSandbox extends AFSBaseProvider {
|
|
226
|
+
readonly name: string;
|
|
227
|
+
readonly description?: string;
|
|
228
|
+
readonly accessMode: AFSAccessMode;
|
|
229
|
+
private readonly runtime;
|
|
230
|
+
private readonly options;
|
|
231
|
+
private readonly scripts;
|
|
232
|
+
private capabilities;
|
|
233
|
+
private readonly promotedActions;
|
|
234
|
+
private readonly auditLog;
|
|
235
|
+
private readonly auditConfig?;
|
|
236
|
+
private readonly rateLimitConfig?;
|
|
237
|
+
private readonly executionTimestamps;
|
|
238
|
+
private readonly userExecutionTimestamps;
|
|
239
|
+
private readonly scriptExecutionTimestamps;
|
|
240
|
+
private metrics;
|
|
241
|
+
private readonly scriptMetrics;
|
|
242
|
+
constructor(options?: AFSSandboxOptions);
|
|
243
|
+
/**
|
|
244
|
+
* Returns the Zod schema for configuration validation
|
|
245
|
+
*/
|
|
246
|
+
static schema(): z.ZodObject<{
|
|
247
|
+
name: z.ZodOptional<z.ZodString>;
|
|
248
|
+
description: z.ZodOptional<z.ZodString>;
|
|
249
|
+
accessMode: z.ZodOptional<z.ZodEnum<{
|
|
250
|
+
readonly: "readonly";
|
|
251
|
+
readwrite: "readwrite";
|
|
252
|
+
}>>;
|
|
253
|
+
runtime: z.ZodOptional<z.ZodObject<{
|
|
254
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
255
|
+
memoryLimit: z.ZodOptional<z.ZodNumber>;
|
|
256
|
+
}, z.core.$strip>>;
|
|
257
|
+
capabilities: z.ZodOptional<z.ZodObject<{
|
|
258
|
+
afs: z.ZodOptional<z.ZodObject<{
|
|
259
|
+
read: z.ZodOptional<z.ZodBoolean>;
|
|
260
|
+
write: z.ZodOptional<z.ZodBoolean>;
|
|
261
|
+
allowPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
262
|
+
denyPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
263
|
+
}, z.core.$strip>>;
|
|
264
|
+
}, z.core.$strip>>;
|
|
265
|
+
audit: z.ZodOptional<z.ZodObject<{
|
|
266
|
+
enabled: z.ZodBoolean;
|
|
267
|
+
onEvent: z.ZodOptional<z.ZodAny>;
|
|
268
|
+
maxEntries: z.ZodOptional<z.ZodNumber>;
|
|
269
|
+
}, z.core.$strip>>;
|
|
270
|
+
rateLimit: z.ZodOptional<z.ZodObject<{
|
|
271
|
+
maxExecutionsPerMinute: z.ZodOptional<z.ZodNumber>;
|
|
272
|
+
maxExecutionsPerMinutePerUser: z.ZodOptional<z.ZodNumber>;
|
|
273
|
+
maxExecutionsPerMinutePerScript: z.ZodOptional<z.ZodNumber>;
|
|
274
|
+
}, z.core.$strip>>;
|
|
275
|
+
}, z.core.$strip>;
|
|
276
|
+
static manifest(): ProviderManifest;
|
|
277
|
+
/**
|
|
278
|
+
* Loads a module instance from configuration
|
|
279
|
+
*/
|
|
280
|
+
static load({
|
|
281
|
+
config
|
|
282
|
+
}?: AFSModuleLoadParams): Promise<AFSSandbox>;
|
|
283
|
+
/**
|
|
284
|
+
* Called when the module is mounted to AFS
|
|
285
|
+
*/
|
|
286
|
+
onMount(afs: AFSRoot): void;
|
|
287
|
+
/**
|
|
288
|
+
* List root directory children
|
|
289
|
+
*/
|
|
290
|
+
listRoot(_ctx: RouteContext): Promise<AFSListResult>;
|
|
291
|
+
/**
|
|
292
|
+
* List all scripts
|
|
293
|
+
*/
|
|
294
|
+
listScripts(_ctx: RouteContext): Promise<AFSListResult>;
|
|
295
|
+
/**
|
|
296
|
+
* List script children (@history, @execHistory)
|
|
297
|
+
*/
|
|
298
|
+
listScript(ctx: RouteContext<{
|
|
299
|
+
scriptName: string;
|
|
300
|
+
}>): Promise<AFSListResult>;
|
|
301
|
+
/**
|
|
302
|
+
* List @history children (leaf node)
|
|
303
|
+
*/
|
|
304
|
+
listScriptHistory(ctx: RouteContext<{
|
|
305
|
+
scriptName: string;
|
|
306
|
+
}>): Promise<AFSListResult>;
|
|
307
|
+
/**
|
|
308
|
+
* List @execHistory children (leaf node)
|
|
309
|
+
*/
|
|
310
|
+
listScriptExecHistoryEntries(ctx: RouteContext<{
|
|
311
|
+
scriptName: string;
|
|
312
|
+
}>): Promise<AFSListResult>;
|
|
313
|
+
/**
|
|
314
|
+
* List all templates
|
|
315
|
+
*/
|
|
316
|
+
listTemplates(_ctx: RouteContext): Promise<AFSListResult>;
|
|
317
|
+
/**
|
|
318
|
+
* List template children (leaf node)
|
|
319
|
+
*/
|
|
320
|
+
listTemplate(ctx: RouteContext<{
|
|
321
|
+
templateName: string;
|
|
322
|
+
}>): Promise<AFSListResult>;
|
|
323
|
+
/**
|
|
324
|
+
* List metrics children
|
|
325
|
+
*/
|
|
326
|
+
listMetrics(_ctx: RouteContext): Promise<AFSListResult>;
|
|
327
|
+
/**
|
|
328
|
+
* List per-script metrics
|
|
329
|
+
*/
|
|
330
|
+
listScriptMetrics(_ctx: RouteContext): Promise<AFSListResult>;
|
|
331
|
+
/**
|
|
332
|
+
* List audit children (leaf node)
|
|
333
|
+
*/
|
|
334
|
+
listAudit(_ctx: RouteContext): Promise<AFSListResult>;
|
|
335
|
+
/**
|
|
336
|
+
* List root-level actions
|
|
337
|
+
*/
|
|
338
|
+
listRootActions(_ctx: RouteContext): Promise<AFSListResult>;
|
|
339
|
+
/**
|
|
340
|
+
* List script-level actions
|
|
341
|
+
*/
|
|
342
|
+
listScriptActions(ctx: RouteContext<{
|
|
343
|
+
scriptName: string;
|
|
344
|
+
}>): Promise<AFSListResult>;
|
|
345
|
+
/**
|
|
346
|
+
* Read root entry
|
|
347
|
+
*/
|
|
348
|
+
readRoot(_ctx: RouteContext): Promise<AFSEntry>;
|
|
349
|
+
/**
|
|
350
|
+
* Read scripts directory
|
|
351
|
+
*/
|
|
352
|
+
readScriptsDir(_ctx: RouteContext): Promise<AFSEntry>;
|
|
353
|
+
/**
|
|
354
|
+
* Read a specific script
|
|
355
|
+
*/
|
|
356
|
+
readScript(ctx: RouteContext<{
|
|
357
|
+
scriptName: string;
|
|
358
|
+
}>): Promise<AFSEntry>;
|
|
359
|
+
/**
|
|
360
|
+
* Read version history for a script
|
|
361
|
+
*/
|
|
362
|
+
readScriptHistory(ctx: RouteContext<{
|
|
363
|
+
scriptName: string;
|
|
364
|
+
}>): Promise<AFSEntry>;
|
|
365
|
+
/**
|
|
366
|
+
* Read a specific version
|
|
367
|
+
*/
|
|
368
|
+
readScriptVersion(ctx: RouteContext<{
|
|
369
|
+
scriptName: string;
|
|
370
|
+
version: string;
|
|
371
|
+
}>): Promise<AFSEntry>;
|
|
372
|
+
/**
|
|
373
|
+
* Read execution history for a script
|
|
374
|
+
*/
|
|
375
|
+
readScriptExecHistory(ctx: RouteContext<{
|
|
376
|
+
scriptName: string;
|
|
377
|
+
}>): Promise<AFSEntry>;
|
|
378
|
+
/**
|
|
379
|
+
* Read templates directory
|
|
380
|
+
*/
|
|
381
|
+
readTemplatesDir(_ctx: RouteContext): Promise<AFSEntry>;
|
|
382
|
+
/**
|
|
383
|
+
* Read a specific template
|
|
384
|
+
*/
|
|
385
|
+
readTemplate(ctx: RouteContext<{
|
|
386
|
+
templateName: string;
|
|
387
|
+
}>): Promise<AFSEntry>;
|
|
388
|
+
/**
|
|
389
|
+
* Read metrics
|
|
390
|
+
*/
|
|
391
|
+
readMetrics(_ctx: RouteContext): Promise<AFSEntry>;
|
|
392
|
+
/**
|
|
393
|
+
* Read per-script metrics
|
|
394
|
+
*/
|
|
395
|
+
readScriptMetrics(ctx: RouteContext<{
|
|
396
|
+
scriptName: string;
|
|
397
|
+
}>): Promise<AFSEntry>;
|
|
398
|
+
/**
|
|
399
|
+
* Read audit log
|
|
400
|
+
*/
|
|
401
|
+
readAudit(_ctx: RouteContext): Promise<AFSEntry>;
|
|
402
|
+
/**
|
|
403
|
+
* Root metadata
|
|
404
|
+
*/
|
|
405
|
+
readRootMeta(_ctx: RouteContext): Promise<AFSEntry>;
|
|
406
|
+
/**
|
|
407
|
+
* Scripts directory metadata
|
|
408
|
+
*/
|
|
409
|
+
readScriptsMeta(_ctx: RouteContext): Promise<AFSEntry>;
|
|
410
|
+
/**
|
|
411
|
+
* Script metadata
|
|
412
|
+
*/
|
|
413
|
+
readScriptMeta(ctx: RouteContext<{
|
|
414
|
+
scriptName: string;
|
|
415
|
+
}>): Promise<AFSEntry>;
|
|
416
|
+
/**
|
|
417
|
+
* @history metadata
|
|
418
|
+
*/
|
|
419
|
+
readScriptHistoryMeta(ctx: RouteContext<{
|
|
420
|
+
scriptName: string;
|
|
421
|
+
}>): Promise<AFSEntry>;
|
|
422
|
+
/**
|
|
423
|
+
* @execHistory metadata
|
|
424
|
+
*/
|
|
425
|
+
readScriptExecHistoryMeta(ctx: RouteContext<{
|
|
426
|
+
scriptName: string;
|
|
427
|
+
}>): Promise<AFSEntry>;
|
|
428
|
+
/**
|
|
429
|
+
* Templates directory metadata
|
|
430
|
+
*/
|
|
431
|
+
readTemplatesMeta(_ctx: RouteContext): Promise<AFSEntry>;
|
|
432
|
+
/**
|
|
433
|
+
* Template metadata
|
|
434
|
+
*/
|
|
435
|
+
readTemplateMeta(ctx: RouteContext<{
|
|
436
|
+
templateName: string;
|
|
437
|
+
}>): Promise<AFSEntry>;
|
|
438
|
+
/**
|
|
439
|
+
* Metrics metadata
|
|
440
|
+
*/
|
|
441
|
+
readMetricsMeta(_ctx: RouteContext): Promise<AFSEntry>;
|
|
442
|
+
/**
|
|
443
|
+
* Audit metadata
|
|
444
|
+
*/
|
|
445
|
+
readAuditMeta(_ctx: RouteContext): Promise<AFSEntry>;
|
|
446
|
+
/**
|
|
447
|
+
* Write (create or update) a script
|
|
448
|
+
*/
|
|
449
|
+
writeScript(ctx: RouteContext<{
|
|
450
|
+
scriptName: string;
|
|
451
|
+
}>, entry: AFSWriteEntryPayload): Promise<AFSWriteResult>;
|
|
452
|
+
/**
|
|
453
|
+
* Reject writes to @history paths
|
|
454
|
+
*/
|
|
455
|
+
writeScriptHistory(_ctx: RouteContext<{
|
|
456
|
+
scriptName: string;
|
|
457
|
+
version: string;
|
|
458
|
+
}>, _entry: AFSWriteEntryPayload): Promise<AFSWriteResult>;
|
|
459
|
+
/**
|
|
460
|
+
* Delete a stored script
|
|
461
|
+
*/
|
|
462
|
+
deleteScript(ctx: RouteContext<{
|
|
463
|
+
scriptName: string;
|
|
464
|
+
}>): Promise<AFSDeleteResult>;
|
|
465
|
+
/**
|
|
466
|
+
* Catch-all delete handler for unsupported paths
|
|
467
|
+
*/
|
|
468
|
+
deleteCatchAll(ctx: RouteContext<{
|
|
469
|
+
path: string;
|
|
470
|
+
}>): Promise<AFSDeleteResult>;
|
|
471
|
+
/**
|
|
472
|
+
* Execute a stored script directly
|
|
473
|
+
*/
|
|
474
|
+
execScript(ctx: RouteContext<{
|
|
475
|
+
scriptName: string;
|
|
476
|
+
}>, args: Record<string, unknown>): Promise<AFSExecResult>;
|
|
477
|
+
/**
|
|
478
|
+
* Execute a stored script directly via exec("/scripts/:name")
|
|
479
|
+
*/
|
|
480
|
+
execScriptDirect(ctx: RouteContext<{
|
|
481
|
+
scriptName: string;
|
|
482
|
+
}>, args: Record<string, unknown>): Promise<AFSExecResult>;
|
|
483
|
+
/**
|
|
484
|
+
* Execute root-level actions (run, validate, promote, create-from-template, promoted actions)
|
|
485
|
+
*/
|
|
486
|
+
execRootAction(ctx: RouteContext<{
|
|
487
|
+
action: string;
|
|
488
|
+
}>, args: Record<string, unknown>): Promise<AFSExecResult>;
|
|
489
|
+
/**
|
|
490
|
+
* Stat root → sandbox overview
|
|
491
|
+
*/
|
|
492
|
+
statRoot(_ctx: RouteContext): Promise<AFSStatResult>;
|
|
493
|
+
/**
|
|
494
|
+
* Stat scripts directory
|
|
495
|
+
*/
|
|
496
|
+
statScriptsDir(_ctx: RouteContext): Promise<AFSStatResult>;
|
|
497
|
+
/**
|
|
498
|
+
* Stat a specific script → runCount, lastRun, versionCount
|
|
499
|
+
*/
|
|
500
|
+
statScript(ctx: RouteContext<{
|
|
501
|
+
scriptName: string;
|
|
502
|
+
}>): Promise<AFSStatResult>;
|
|
503
|
+
/**
|
|
504
|
+
* Stat templates directory
|
|
505
|
+
*/
|
|
506
|
+
statTemplatesDir(_ctx: RouteContext): Promise<AFSStatResult>;
|
|
507
|
+
/**
|
|
508
|
+
* Stat a specific template
|
|
509
|
+
*/
|
|
510
|
+
statTemplate(ctx: RouteContext<{
|
|
511
|
+
templateName: string;
|
|
512
|
+
}>): Promise<AFSStatResult>;
|
|
513
|
+
/**
|
|
514
|
+
* Stat metrics directory
|
|
515
|
+
*/
|
|
516
|
+
statMetricsDir(_ctx: RouteContext): Promise<AFSStatResult>;
|
|
517
|
+
/**
|
|
518
|
+
* Stat audit directory
|
|
519
|
+
*/
|
|
520
|
+
statAuditDir(_ctx: RouteContext): Promise<AFSStatResult>;
|
|
521
|
+
/**
|
|
522
|
+
* Explain root → sandbox overview with security limits, templates, metrics
|
|
523
|
+
*/
|
|
524
|
+
explainRoot(_ctx: RouteContext): Promise<AFSExplainResult>;
|
|
525
|
+
/**
|
|
526
|
+
* Explain a specific script → run count, code summary
|
|
527
|
+
*/
|
|
528
|
+
explainScript(ctx: RouteContext<{
|
|
529
|
+
scriptName: string;
|
|
530
|
+
}>): Promise<AFSExplainResult>;
|
|
531
|
+
/**
|
|
532
|
+
* Read /.meta/.capabilities → capabilities manifest with action catalog
|
|
533
|
+
*/
|
|
534
|
+
readCapabilities(_ctx: RouteContext): Promise<AFSEntry>;
|
|
535
|
+
/**
|
|
536
|
+
* Build AFSEntry for a stored script
|
|
537
|
+
*/
|
|
538
|
+
private buildScriptEntry;
|
|
539
|
+
/**
|
|
540
|
+
* Build scripts directory entry
|
|
541
|
+
*/
|
|
542
|
+
private buildScriptsDirectoryEntry;
|
|
543
|
+
/**
|
|
544
|
+
* Build templates directory entry
|
|
545
|
+
*/
|
|
546
|
+
private buildTemplatesDirectoryEntry;
|
|
547
|
+
/**
|
|
548
|
+
* Build metrics directory entry
|
|
549
|
+
*/
|
|
550
|
+
private buildMetricsDirectoryEntry;
|
|
551
|
+
/**
|
|
552
|
+
* Build audit directory entry
|
|
553
|
+
*/
|
|
554
|
+
private buildAuditDirectoryEntry;
|
|
555
|
+
/**
|
|
556
|
+
* Log an audit event
|
|
557
|
+
*/
|
|
558
|
+
private logAudit;
|
|
559
|
+
/**
|
|
560
|
+
* Check if execution is rate limited
|
|
561
|
+
*/
|
|
562
|
+
private checkRateLimit;
|
|
563
|
+
/**
|
|
564
|
+
* Record execution for rate limiting
|
|
565
|
+
*/
|
|
566
|
+
private recordExecution;
|
|
567
|
+
/**
|
|
568
|
+
* Update execution metrics
|
|
569
|
+
*/
|
|
570
|
+
private updateMetrics;
|
|
571
|
+
/**
|
|
572
|
+
* Validate action name
|
|
573
|
+
*/
|
|
574
|
+
private isValidActionName;
|
|
575
|
+
/**
|
|
576
|
+
* Apply template variables to content
|
|
577
|
+
*/
|
|
578
|
+
private applyTemplate;
|
|
579
|
+
/**
|
|
580
|
+
* Execute a built-in or promoted action
|
|
581
|
+
*/
|
|
582
|
+
private executeAction;
|
|
583
|
+
}
|
|
584
|
+
//#endregion
|
|
585
|
+
export { AFSSandbox, AFSSandbox as default, type AFSSandboxOptions, type AuditConfig, type AuditEvent, type AuditEventType, type ExecutionMetrics, type ExecutionResult, type LogEntry, type LogLevel, type PromotedAction, type RateLimitConfig, type ScriptTemplate };
|
|
586
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/index.ts"],"mappings":";;;;;;;;KAKY,QAAA;AAAZ;;;AAAA,UAKiB,QAAA;EACf,KAAA,EAAO,QAAA;EACP,OAAA;EACA,SAAA;AAAA;;;;UAMe,eAAA;EANf;EAQA,OAAA;EARS;EAUT,MAAA;EAJ8B;EAM9B,KAAA;EAIc;EAFd,KAAA;EAJA;EAMA,IAAA,EAAM,QAAA;EAFN;EAIA,QAAA;EAFM;EAIN,QAAA;AAAA;;;;UA0Fe,cAAA;EAiHf;EA/GA,OAAA;EA+GW;EA7GX,WAAA;AAAA;;AAqHF;;UA/GiB,kBAAA;EA+Ge;EA7G9B,GAAA;IAiHA,6BA/GE,IAAA,YAiH6B;IA/G7B,KAAA,YAqHa;IAnHb,UAAA,aAmH6B;IAjH7B,SAAA;EAAA;AAAA;;;;UAOa,cAAA;EAsHF;EApHb,IAAA;EA0He;EAxHf,WAAA;;EAEA,YAAA;EA+HU;EA7HV,aAA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