@aigne/afs-json 1.0.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.
@@ -0,0 +1,470 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSJSON = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const node_path_1 = require("node:path");
6
+ const schema_js_1 = require("@aigne/core/loader/schema.js");
7
+ const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
8
+ const yaml_1 = require("yaml");
9
+ const zod_1 = require("zod");
10
+ const LIST_MAX_LIMIT = 1000;
11
+ const afsJSONOptionsSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
12
+ name: (0, schema_js_1.optionalize)(zod_1.z.string()),
13
+ jsonPath: zod_1.z.string().describe("The path to the JSON/YAML file to mount"),
14
+ description: (0, schema_js_1.optionalize)(zod_1.z.string().describe("A description of the JSON module")),
15
+ accessMode: (0, schema_js_1.optionalize)(zod_1.z.enum(["readonly", "readwrite"]).describe("Access mode for this module")),
16
+ agentSkills: (0, schema_js_1.optionalize)(zod_1.z.boolean().describe("Enable automatic agent skill scanning for this module")),
17
+ }));
18
+ /**
19
+ * AFS module for mounting JSON/YAML files as virtual file systems.
20
+ *
21
+ * JSON/YAML objects are treated as directories, and properties/array items as files.
22
+ * Supports nested structures and path-based access to data values.
23
+ */
24
+ class AFSJSON {
25
+ options;
26
+ static schema() {
27
+ return afsJSONOptionsSchema;
28
+ }
29
+ static async load({ filepath, parsed }) {
30
+ const valid = await AFSJSON.schema().parseAsync(parsed);
31
+ return new AFSJSON({ ...valid, cwd: (0, node_path_1.dirname)(filepath) });
32
+ }
33
+ jsonData = null;
34
+ fileStats = {};
35
+ fileFormat = "json";
36
+ constructor(options) {
37
+ this.options = options;
38
+ (0, type_utils_js_1.checkArguments)("AFSJSON", afsJSONOptionsSchema, options);
39
+ let jsonPath;
40
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: explicitly replace ${CWD}
41
+ jsonPath = options.jsonPath.replaceAll("${CWD}", process.cwd());
42
+ if (jsonPath.startsWith("~/")) {
43
+ jsonPath = (0, node_path_1.join)(process.env.HOME || "", jsonPath.slice(2));
44
+ }
45
+ if (!(0, node_path_1.isAbsolute)(jsonPath)) {
46
+ jsonPath = (0, node_path_1.join)(options.cwd || process.cwd(), jsonPath);
47
+ }
48
+ // Detect file format based on extension for writing
49
+ const ext = (0, node_path_1.extname)(jsonPath).toLowerCase();
50
+ this.fileFormat = ext === ".yaml" || ext === ".yml" ? "yaml" : "json";
51
+ // Extract name without extension
52
+ const extensions = [".json", ".yaml", ".yml"];
53
+ let name = (0, node_path_1.basename)(jsonPath);
54
+ for (const e of extensions) {
55
+ if (name.endsWith(e)) {
56
+ name = name.slice(0, -e.length);
57
+ break;
58
+ }
59
+ }
60
+ this.name = options.name || name || "json";
61
+ this.description = options.description;
62
+ this.agentSkills = options.agentSkills;
63
+ // Default to "readwrite", but "readonly" if agentSkills is enabled
64
+ this.accessMode = options.accessMode ?? (options.agentSkills ? "readonly" : "readwrite");
65
+ this.options.jsonPath = jsonPath;
66
+ }
67
+ name;
68
+ description;
69
+ accessMode;
70
+ agentSkills;
71
+ /**
72
+ * Load JSON/YAML data from file. Called lazily on first access.
73
+ * Uses YAML parser which can handle both JSON and YAML formats.
74
+ */
75
+ async ensureLoaded() {
76
+ if (this.jsonData !== null)
77
+ return;
78
+ try {
79
+ const stats = await (0, promises_1.stat)(this.options.jsonPath);
80
+ this.fileStats = {
81
+ birthtime: stats.birthtime,
82
+ mtime: stats.mtime,
83
+ };
84
+ const content = await (0, promises_1.readFile)(this.options.jsonPath, "utf8");
85
+ // YAML parser can handle both JSON and YAML formats
86
+ this.jsonData = (0, yaml_1.parse)(content);
87
+ }
88
+ catch (error) {
89
+ if (error.code === "ENOENT") {
90
+ // File doesn't exist yet, start with empty object
91
+ this.jsonData = {};
92
+ }
93
+ else {
94
+ throw error;
95
+ }
96
+ }
97
+ }
98
+ /**
99
+ * Save JSON/YAML data back to file. Only called in readwrite mode.
100
+ */
101
+ async saveToFile() {
102
+ let content;
103
+ // Serialize based on file format
104
+ if (this.fileFormat === "yaml") {
105
+ content = (0, yaml_1.stringify)(this.jsonData);
106
+ }
107
+ else {
108
+ content = JSON.stringify(this.jsonData, null, 2);
109
+ }
110
+ await (0, promises_1.writeFile)(this.options.jsonPath, content, "utf8");
111
+ // Update file stats
112
+ const stats = await (0, promises_1.stat)(this.options.jsonPath);
113
+ this.fileStats = {
114
+ birthtime: this.fileStats.birthtime || stats.birthtime,
115
+ mtime: stats.mtime,
116
+ };
117
+ }
118
+ /**
119
+ * Normalize path to ensure consistent format
120
+ */
121
+ normalizePath(path) {
122
+ let normalized = path.startsWith("/") ? path : `/${path}`;
123
+ if (normalized.length > 1 && normalized.endsWith("/")) {
124
+ normalized = normalized.slice(0, -1);
125
+ }
126
+ return normalized;
127
+ }
128
+ /**
129
+ * Get path segments from normalized path
130
+ */
131
+ getPathSegments(path) {
132
+ const normalized = this.normalizePath(path);
133
+ if (normalized === "/")
134
+ return [];
135
+ return normalized.slice(1).split("/");
136
+ }
137
+ /**
138
+ * Navigate to a value in the JSON structure using path segments
139
+ */
140
+ getValueAtPath(data, segments) {
141
+ let current = data;
142
+ for (const segment of segments) {
143
+ if (current == null)
144
+ return undefined;
145
+ // Handle array indices
146
+ if (Array.isArray(current)) {
147
+ const index = Number.parseInt(segment, 10);
148
+ if (Number.isNaN(index) || index < 0 || index >= current.length) {
149
+ return undefined;
150
+ }
151
+ current = current[index];
152
+ }
153
+ else if (typeof current === "object") {
154
+ current = current[segment];
155
+ }
156
+ else {
157
+ return undefined;
158
+ }
159
+ }
160
+ return current;
161
+ }
162
+ /**
163
+ * Set a value in the JSON structure at the given path
164
+ */
165
+ setValueAtPath(data, segments, value) {
166
+ if (segments.length === 0) {
167
+ throw new Error("Cannot set value at root path");
168
+ }
169
+ let current = data;
170
+ for (let i = 0; i < segments.length - 1; i++) {
171
+ const segment = segments[i];
172
+ const nextSegment = segments[i + 1];
173
+ if (Array.isArray(current)) {
174
+ const index = Number.parseInt(segment, 10);
175
+ if (Number.isNaN(index) || index < 0) {
176
+ throw new Error(`Invalid array index: ${segment}`);
177
+ }
178
+ // Extend array if necessary
179
+ while (current.length <= index) {
180
+ current.push(null);
181
+ }
182
+ if (current[index] == null) {
183
+ // Determine if next level should be array or object
184
+ const isNextArray = !Number.isNaN(Number.parseInt(nextSegment, 10));
185
+ current[index] = isNextArray ? [] : {};
186
+ }
187
+ current = current[index];
188
+ }
189
+ else if (typeof current === "object") {
190
+ if (current[segment] == null) {
191
+ // Determine if next level should be array or object
192
+ const isNextArray = !Number.isNaN(Number.parseInt(nextSegment, 10));
193
+ current[segment] = isNextArray ? [] : {};
194
+ }
195
+ current = current[segment];
196
+ }
197
+ else {
198
+ throw new Error(`Cannot set property on non-object at ${segments.slice(0, i + 1).join("/")}`);
199
+ }
200
+ }
201
+ const lastSegment = segments[segments.length - 1];
202
+ if (Array.isArray(current)) {
203
+ const index = Number.parseInt(lastSegment, 10);
204
+ if (Number.isNaN(index) || index < 0) {
205
+ throw new Error(`Invalid array index: ${lastSegment}`);
206
+ }
207
+ current[index] = value;
208
+ }
209
+ else if (typeof current === "object") {
210
+ current[lastSegment] = value;
211
+ }
212
+ else {
213
+ throw new Error("Cannot set property on non-object");
214
+ }
215
+ }
216
+ /**
217
+ * Delete a value from the JSON structure at the given path
218
+ */
219
+ deleteValueAtPath(data, segments) {
220
+ if (segments.length === 0) {
221
+ throw new Error("Cannot delete root path");
222
+ }
223
+ let current = data;
224
+ for (let i = 0; i < segments.length - 1; i++) {
225
+ const segment = segments[i];
226
+ if (Array.isArray(current)) {
227
+ const index = Number.parseInt(segment, 10);
228
+ if (Number.isNaN(index) || index < 0 || index >= current.length) {
229
+ return false;
230
+ }
231
+ current = current[index];
232
+ }
233
+ else if (typeof current === "object") {
234
+ if (!(segment in current))
235
+ return false;
236
+ current = current[segment];
237
+ }
238
+ else {
239
+ return false;
240
+ }
241
+ }
242
+ const lastSegment = segments[segments.length - 1];
243
+ if (Array.isArray(current)) {
244
+ const index = Number.parseInt(lastSegment, 10);
245
+ if (Number.isNaN(index) || index < 0 || index >= current.length) {
246
+ return false;
247
+ }
248
+ current.splice(index, 1);
249
+ return true;
250
+ }
251
+ if (typeof current === "object") {
252
+ if (!(lastSegment in current))
253
+ return false;
254
+ delete current[lastSegment];
255
+ return true;
256
+ }
257
+ return false;
258
+ }
259
+ /**
260
+ * Check if a value is a "directory" (object or array with children)
261
+ */
262
+ isDirectory(value) {
263
+ if (Array.isArray(value))
264
+ return true;
265
+ if (typeof value === "object" && value !== null)
266
+ return true;
267
+ return false;
268
+ }
269
+ /**
270
+ * Get children of a directory value
271
+ */
272
+ getChildren(value) {
273
+ if (Array.isArray(value)) {
274
+ return value.map((item, index) => ({ key: String(index), value: item }));
275
+ }
276
+ if (typeof value === "object" && value !== null) {
277
+ return Object.entries(value).map(([key, val]) => ({ key, value: val }));
278
+ }
279
+ return [];
280
+ }
281
+ /**
282
+ * Convert a JSON value to an AFSEntry
283
+ */
284
+ valueToAFSEntry(path, value) {
285
+ const isDir = this.isDirectory(value);
286
+ const children = isDir ? this.getChildren(value) : [];
287
+ return {
288
+ id: path,
289
+ path: path,
290
+ content: isDir ? undefined : value,
291
+ createdAt: this.fileStats.birthtime,
292
+ updatedAt: this.fileStats.mtime,
293
+ metadata: {
294
+ type: isDir ? "directory" : "file",
295
+ childrenCount: isDir ? children.length : undefined,
296
+ },
297
+ };
298
+ }
299
+ async list(path, options) {
300
+ await this.ensureLoaded();
301
+ const normalizedPath = this.normalizePath(path);
302
+ const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);
303
+ const maxChildren = typeof options?.maxChildren === "number" ? options.maxChildren : Number.MAX_SAFE_INTEGER;
304
+ const maxDepth = options?.maxDepth ?? 1;
305
+ const segments = this.getPathSegments(normalizedPath);
306
+ const value = this.getValueAtPath(this.jsonData, segments);
307
+ if (value === undefined) {
308
+ throw new Error(`Path not found: ${normalizedPath}`);
309
+ }
310
+ const entries = [];
311
+ const queue = [{ path: normalizedPath, value, depth: 0 }];
312
+ while (queue.length > 0) {
313
+ const item = queue.shift();
314
+ if (!item)
315
+ break;
316
+ const { path: itemPath, value: itemValue, depth } = item;
317
+ const entry = this.valueToAFSEntry(itemPath, itemValue);
318
+ entries.push(entry);
319
+ if (entries.length >= limit) {
320
+ if (entry.metadata) {
321
+ entry.metadata.childrenTruncated = true;
322
+ }
323
+ break;
324
+ }
325
+ // Process children if within depth limit
326
+ if (this.isDirectory(itemValue) && depth < maxDepth) {
327
+ const children = this.getChildren(itemValue);
328
+ const childrenToProcess = children.length > maxChildren ? children.slice(0, maxChildren) : children;
329
+ const isTruncated = childrenToProcess.length < children.length;
330
+ if (isTruncated && entry.metadata) {
331
+ entry.metadata.childrenTruncated = true;
332
+ }
333
+ for (const child of childrenToProcess) {
334
+ const childPath = itemPath === "/" ? `/${child.key}` : `${itemPath}/${child.key}`;
335
+ queue.push({
336
+ path: childPath,
337
+ value: child.value,
338
+ depth: depth + 1,
339
+ });
340
+ }
341
+ }
342
+ }
343
+ return { data: entries };
344
+ }
345
+ async read(path, _options) {
346
+ await this.ensureLoaded();
347
+ const normalizedPath = this.normalizePath(path);
348
+ const segments = this.getPathSegments(normalizedPath);
349
+ const value = this.getValueAtPath(this.jsonData, segments);
350
+ if (value === undefined) {
351
+ return {
352
+ data: undefined,
353
+ message: `Path not found: ${normalizedPath}`,
354
+ };
355
+ }
356
+ return { data: this.valueToAFSEntry(normalizedPath, value) };
357
+ }
358
+ async write(path, entry, _options) {
359
+ await this.ensureLoaded();
360
+ const normalizedPath = this.normalizePath(path);
361
+ const segments = this.getPathSegments(normalizedPath);
362
+ // Set the value in the JSON structure
363
+ this.setValueAtPath(this.jsonData, segments, entry.content);
364
+ // Save back to file
365
+ await this.saveToFile();
366
+ const newValue = this.getValueAtPath(this.jsonData, segments);
367
+ const isDir = this.isDirectory(newValue);
368
+ const children = isDir ? this.getChildren(newValue) : [];
369
+ const writtenEntry = {
370
+ id: normalizedPath,
371
+ path: normalizedPath,
372
+ content: entry.content,
373
+ summary: entry.summary,
374
+ description: entry.description,
375
+ createdAt: this.fileStats.birthtime,
376
+ updatedAt: this.fileStats.mtime,
377
+ metadata: {
378
+ ...entry.metadata,
379
+ type: isDir ? "directory" : "file",
380
+ childrenCount: isDir ? children.length : undefined,
381
+ },
382
+ userId: entry.userId,
383
+ sessionId: entry.sessionId,
384
+ linkTo: entry.linkTo,
385
+ };
386
+ return { data: writtenEntry };
387
+ }
388
+ async delete(path, options) {
389
+ await this.ensureLoaded();
390
+ const normalizedPath = this.normalizePath(path);
391
+ const segments = this.getPathSegments(normalizedPath);
392
+ const value = this.getValueAtPath(this.jsonData, segments);
393
+ if (value === undefined) {
394
+ throw new Error(`Path not found: ${normalizedPath}`);
395
+ }
396
+ const hasChildren = this.isDirectory(value) && this.getChildren(value).length > 0;
397
+ if (hasChildren && !options?.recursive) {
398
+ throw new Error(`Cannot delete directory '${normalizedPath}' without recursive option. Set recursive: true to delete directories.`);
399
+ }
400
+ this.deleteValueAtPath(this.jsonData, segments);
401
+ await this.saveToFile();
402
+ return { message: `Successfully deleted: ${normalizedPath}` };
403
+ }
404
+ async rename(oldPath, newPath, options) {
405
+ await this.ensureLoaded();
406
+ const normalizedOldPath = this.normalizePath(oldPath);
407
+ const normalizedNewPath = this.normalizePath(newPath);
408
+ const oldSegments = this.getPathSegments(normalizedOldPath);
409
+ const newSegments = this.getPathSegments(normalizedNewPath);
410
+ const oldValue = this.getValueAtPath(this.jsonData, oldSegments);
411
+ if (oldValue === undefined) {
412
+ throw new Error(`Source path not found: ${normalizedOldPath}`);
413
+ }
414
+ const existingNewValue = this.getValueAtPath(this.jsonData, newSegments);
415
+ if (existingNewValue !== undefined && !options?.overwrite) {
416
+ throw new Error(`Destination '${normalizedNewPath}' already exists. Set overwrite: true to replace it.`);
417
+ }
418
+ // Copy to new location and delete old
419
+ this.setValueAtPath(this.jsonData, newSegments, oldValue);
420
+ this.deleteValueAtPath(this.jsonData, oldSegments);
421
+ await this.saveToFile();
422
+ return { message: `Successfully renamed '${normalizedOldPath}' to '${normalizedNewPath}'` };
423
+ }
424
+ async search(path, query, options) {
425
+ await this.ensureLoaded();
426
+ const normalizedPath = this.normalizePath(path);
427
+ const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);
428
+ const caseSensitive = options?.caseSensitive ?? false;
429
+ const segments = this.getPathSegments(normalizedPath);
430
+ const rootValue = this.getValueAtPath(this.jsonData, segments);
431
+ if (rootValue === undefined) {
432
+ throw new Error(`Path not found: ${normalizedPath}`);
433
+ }
434
+ const entries = [];
435
+ const searchQuery = caseSensitive ? query : query.toLowerCase();
436
+ const searchInValue = (valuePath, value) => {
437
+ if (entries.length >= limit)
438
+ return;
439
+ let matched = false;
440
+ // Search in the value itself
441
+ if (!this.isDirectory(value)) {
442
+ const valueStr = typeof value === "string" ? value : JSON.stringify(value);
443
+ const searchValue = caseSensitive ? valueStr : valueStr.toLowerCase();
444
+ if (searchValue.includes(searchQuery)) {
445
+ matched = true;
446
+ }
447
+ }
448
+ if (matched) {
449
+ entries.push(this.valueToAFSEntry(valuePath, value));
450
+ }
451
+ // Recursively search children
452
+ if (this.isDirectory(value)) {
453
+ const children = this.getChildren(value);
454
+ for (const child of children) {
455
+ if (entries.length >= limit)
456
+ break;
457
+ const childPath = valuePath === "/" ? `/${child.key}` : `${valuePath}/${child.key}`;
458
+ searchInValue(childPath, child.value);
459
+ }
460
+ }
461
+ };
462
+ searchInValue(normalizedPath, rootValue);
463
+ return {
464
+ data: entries,
465
+ message: entries.length >= limit ? `Results truncated to limit ${limit}` : undefined,
466
+ };
467
+ }
468
+ }
469
+ exports.AFSJSON = AFSJSON;
470
+ const _typeCheck = AFSJSON;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,108 @@
1
+ import type { AFSAccessMode, AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSReadOptions, AFSReadResult, AFSRenameOptions, AFSRenameResult, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteOptions, AFSWriteResult } from "@aigne/afs";
2
+ import { z } from "zod";
3
+ export interface AFSJSONOptions {
4
+ name?: string;
5
+ jsonPath: string;
6
+ description?: string;
7
+ /**
8
+ * Access mode for this module.
9
+ * - "readonly": Only read operations are allowed
10
+ * - "readwrite": All operations are allowed (default, unless agentSkills is enabled)
11
+ * @default "readwrite" (or "readonly" when agentSkills is true)
12
+ */
13
+ accessMode?: AFSAccessMode;
14
+ /**
15
+ * Enable automatic agent skill scanning for this module.
16
+ * When enabled, defaults accessMode to "readonly" if not explicitly set.
17
+ * @default false
18
+ */
19
+ agentSkills?: boolean;
20
+ }
21
+ /**
22
+ * AFS module for mounting JSON/YAML files as virtual file systems.
23
+ *
24
+ * JSON/YAML objects are treated as directories, and properties/array items as files.
25
+ * Supports nested structures and path-based access to data values.
26
+ */
27
+ export declare class AFSJSON implements AFSModule {
28
+ options: AFSJSONOptions & {
29
+ cwd?: string;
30
+ };
31
+ static schema(): z.ZodObject<{
32
+ name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
33
+ jsonPath: z.ZodString;
34
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
35
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
36
+ agentSkills: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
37
+ }, "strip", z.ZodTypeAny, {
38
+ jsonPath: string;
39
+ name?: string | undefined;
40
+ description?: string | undefined;
41
+ accessMode?: "readonly" | "readwrite" | undefined;
42
+ agentSkills?: boolean | undefined;
43
+ }, {
44
+ jsonPath: string;
45
+ name?: string | undefined;
46
+ description?: string | undefined;
47
+ accessMode?: "readonly" | "readwrite" | undefined;
48
+ agentSkills?: boolean | undefined;
49
+ }>;
50
+ static load({ filepath, parsed }: AFSModuleLoadParams): Promise<AFSJSON>;
51
+ private jsonData;
52
+ private fileStats;
53
+ private fileFormat;
54
+ constructor(options: AFSJSONOptions & {
55
+ cwd?: string;
56
+ });
57
+ name: string;
58
+ description?: string;
59
+ accessMode: AFSAccessMode;
60
+ agentSkills?: boolean;
61
+ /**
62
+ * Load JSON/YAML data from file. Called lazily on first access.
63
+ * Uses YAML parser which can handle both JSON and YAML formats.
64
+ */
65
+ private ensureLoaded;
66
+ /**
67
+ * Save JSON/YAML data back to file. Only called in readwrite mode.
68
+ */
69
+ private saveToFile;
70
+ /**
71
+ * Normalize path to ensure consistent format
72
+ */
73
+ private normalizePath;
74
+ /**
75
+ * Get path segments from normalized path
76
+ */
77
+ private getPathSegments;
78
+ /**
79
+ * Navigate to a value in the JSON structure using path segments
80
+ */
81
+ private getValueAtPath;
82
+ /**
83
+ * Set a value in the JSON structure at the given path
84
+ */
85
+ private setValueAtPath;
86
+ /**
87
+ * Delete a value from the JSON structure at the given path
88
+ */
89
+ private deleteValueAtPath;
90
+ /**
91
+ * Check if a value is a "directory" (object or array with children)
92
+ */
93
+ private isDirectory;
94
+ /**
95
+ * Get children of a directory value
96
+ */
97
+ private getChildren;
98
+ /**
99
+ * Convert a JSON value to an AFSEntry
100
+ */
101
+ private valueToAFSEntry;
102
+ list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
103
+ read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult>;
104
+ write(path: string, entry: AFSWriteEntryPayload, _options?: AFSWriteOptions): Promise<AFSWriteResult>;
105
+ delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
106
+ rename(oldPath: string, newPath: string, options?: AFSRenameOptions): Promise<AFSRenameResult>;
107
+ search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
108
+ }
@@ -0,0 +1,108 @@
1
+ import type { AFSAccessMode, AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSReadOptions, AFSReadResult, AFSRenameOptions, AFSRenameResult, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteOptions, AFSWriteResult } from "@aigne/afs";
2
+ import { z } from "zod";
3
+ export interface AFSJSONOptions {
4
+ name?: string;
5
+ jsonPath: string;
6
+ description?: string;
7
+ /**
8
+ * Access mode for this module.
9
+ * - "readonly": Only read operations are allowed
10
+ * - "readwrite": All operations are allowed (default, unless agentSkills is enabled)
11
+ * @default "readwrite" (or "readonly" when agentSkills is true)
12
+ */
13
+ accessMode?: AFSAccessMode;
14
+ /**
15
+ * Enable automatic agent skill scanning for this module.
16
+ * When enabled, defaults accessMode to "readonly" if not explicitly set.
17
+ * @default false
18
+ */
19
+ agentSkills?: boolean;
20
+ }
21
+ /**
22
+ * AFS module for mounting JSON/YAML files as virtual file systems.
23
+ *
24
+ * JSON/YAML objects are treated as directories, and properties/array items as files.
25
+ * Supports nested structures and path-based access to data values.
26
+ */
27
+ export declare class AFSJSON implements AFSModule {
28
+ options: AFSJSONOptions & {
29
+ cwd?: string;
30
+ };
31
+ static schema(): z.ZodObject<{
32
+ name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
33
+ jsonPath: z.ZodString;
34
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
35
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
36
+ agentSkills: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
37
+ }, "strip", z.ZodTypeAny, {
38
+ jsonPath: string;
39
+ name?: string | undefined;
40
+ description?: string | undefined;
41
+ accessMode?: "readonly" | "readwrite" | undefined;
42
+ agentSkills?: boolean | undefined;
43
+ }, {
44
+ jsonPath: string;
45
+ name?: string | undefined;
46
+ description?: string | undefined;
47
+ accessMode?: "readonly" | "readwrite" | undefined;
48
+ agentSkills?: boolean | undefined;
49
+ }>;
50
+ static load({ filepath, parsed }: AFSModuleLoadParams): Promise<AFSJSON>;
51
+ private jsonData;
52
+ private fileStats;
53
+ private fileFormat;
54
+ constructor(options: AFSJSONOptions & {
55
+ cwd?: string;
56
+ });
57
+ name: string;
58
+ description?: string;
59
+ accessMode: AFSAccessMode;
60
+ agentSkills?: boolean;
61
+ /**
62
+ * Load JSON/YAML data from file. Called lazily on first access.
63
+ * Uses YAML parser which can handle both JSON and YAML formats.
64
+ */
65
+ private ensureLoaded;
66
+ /**
67
+ * Save JSON/YAML data back to file. Only called in readwrite mode.
68
+ */
69
+ private saveToFile;
70
+ /**
71
+ * Normalize path to ensure consistent format
72
+ */
73
+ private normalizePath;
74
+ /**
75
+ * Get path segments from normalized path
76
+ */
77
+ private getPathSegments;
78
+ /**
79
+ * Navigate to a value in the JSON structure using path segments
80
+ */
81
+ private getValueAtPath;
82
+ /**
83
+ * Set a value in the JSON structure at the given path
84
+ */
85
+ private setValueAtPath;
86
+ /**
87
+ * Delete a value from the JSON structure at the given path
88
+ */
89
+ private deleteValueAtPath;
90
+ /**
91
+ * Check if a value is a "directory" (object or array with children)
92
+ */
93
+ private isDirectory;
94
+ /**
95
+ * Get children of a directory value
96
+ */
97
+ private getChildren;
98
+ /**
99
+ * Convert a JSON value to an AFSEntry
100
+ */
101
+ private valueToAFSEntry;
102
+ list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
103
+ read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult>;
104
+ write(path: string, entry: AFSWriteEntryPayload, _options?: AFSWriteOptions): Promise<AFSWriteResult>;
105
+ delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
106
+ rename(oldPath: string, newPath: string, options?: AFSRenameOptions): Promise<AFSRenameResult>;
107
+ search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
108
+ }