agentlang 0.0.2
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 +83 -0
- package/README.md +120 -0
- package/bin/cli.js +4 -0
- package/out/api/http.d.ts +3 -0
- package/out/api/http.d.ts.map +1 -0
- package/out/api/http.js +290 -0
- package/out/api/http.js.map +1 -0
- package/out/cli/cli-util.d.ts +7 -0
- package/out/cli/cli-util.d.ts.map +1 -0
- package/out/cli/cli-util.js +9 -0
- package/out/cli/cli-util.js.map +1 -0
- package/out/cli/docs.d.ts +2 -0
- package/out/cli/docs.d.ts.map +1 -0
- package/out/cli/docs.js +236 -0
- package/out/cli/docs.js.map +1 -0
- package/out/cli/main.d.ts +288 -0
- package/out/cli/main.d.ts.map +1 -0
- package/out/cli/main.js +119 -0
- package/out/cli/main.js.map +1 -0
- package/out/cli/openapi-docs.yml +695 -0
- package/out/extension/main.cjs +18093 -0
- package/out/extension/main.cjs.map +7 -0
- package/out/extension/main.d.ts +4 -0
- package/out/extension/main.d.ts.map +1 -0
- package/out/extension/main.js +42 -0
- package/out/extension/main.js.map +1 -0
- package/out/language/agentlang-module.d.ts +42 -0
- package/out/language/agentlang-module.d.ts.map +1 -0
- package/out/language/agentlang-module.js +42 -0
- package/out/language/agentlang-module.js.map +1 -0
- package/out/language/agentlang-validator.d.ts +15 -0
- package/out/language/agentlang-validator.d.ts.map +1 -0
- package/out/language/agentlang-validator.js +50 -0
- package/out/language/agentlang-validator.js.map +1 -0
- package/out/language/generated/ast.d.ts +491 -0
- package/out/language/generated/ast.d.ts.map +1 -0
- package/out/language/generated/ast.js +934 -0
- package/out/language/generated/ast.js.map +1 -0
- package/out/language/generated/grammar.d.ts +7 -0
- package/out/language/generated/grammar.d.ts.map +1 -0
- package/out/language/generated/grammar.js +4475 -0
- package/out/language/generated/grammar.js.map +1 -0
- package/out/language/generated/module.d.ts +14 -0
- package/out/language/generated/module.d.ts.map +1 -0
- package/out/language/generated/module.js +21 -0
- package/out/language/generated/module.js.map +1 -0
- package/out/language/main-browser.d.ts +2 -0
- package/out/language/main-browser.d.ts.map +1 -0
- package/out/language/main-browser.js +10 -0
- package/out/language/main-browser.js.map +1 -0
- package/out/language/main.cjs +36229 -0
- package/out/language/main.cjs.map +7 -0
- package/out/language/main.d.ts +2 -0
- package/out/language/main.d.ts.map +1 -0
- package/out/language/main.js +11 -0
- package/out/language/main.js.map +1 -0
- package/out/language/parser.d.ts +9 -0
- package/out/language/parser.d.ts.map +1 -0
- package/out/language/parser.js +273 -0
- package/out/language/parser.js.map +1 -0
- package/out/language/syntax.d.ts +155 -0
- package/out/language/syntax.d.ts.map +1 -0
- package/out/language/syntax.js +527 -0
- package/out/language/syntax.js.map +1 -0
- package/out/runtime/agents/common.d.ts +2 -0
- package/out/runtime/agents/common.d.ts.map +1 -0
- package/out/runtime/agents/common.js +178 -0
- package/out/runtime/agents/common.js.map +1 -0
- package/out/runtime/agents/impl/openai.d.ts +8 -0
- package/out/runtime/agents/impl/openai.d.ts.map +1 -0
- package/out/runtime/agents/impl/openai.js +15 -0
- package/out/runtime/agents/impl/openai.js.map +1 -0
- package/out/runtime/agents/provider.d.ts +21 -0
- package/out/runtime/agents/provider.d.ts.map +1 -0
- package/out/runtime/agents/provider.js +32 -0
- package/out/runtime/agents/provider.js.map +1 -0
- package/out/runtime/agents/registry.d.ts +2 -0
- package/out/runtime/agents/registry.d.ts.map +1 -0
- package/out/runtime/agents/registry.js +10 -0
- package/out/runtime/agents/registry.js.map +1 -0
- package/out/runtime/auth/cognito.d.ts +16 -0
- package/out/runtime/auth/cognito.d.ts.map +1 -0
- package/out/runtime/auth/cognito.js +186 -0
- package/out/runtime/auth/cognito.js.map +1 -0
- package/out/runtime/auth/defs.d.ts +11 -0
- package/out/runtime/auth/defs.d.ts.map +1 -0
- package/out/runtime/auth/defs.js +24 -0
- package/out/runtime/auth/defs.js.map +1 -0
- package/out/runtime/auth/interface.d.ts +22 -0
- package/out/runtime/auth/interface.d.ts.map +1 -0
- package/out/runtime/auth/interface.js +2 -0
- package/out/runtime/auth/interface.js.map +1 -0
- package/out/runtime/defs.js +24 -0
- package/out/runtime/defs.js.map +1 -0
- package/out/runtime/interpreter.d.ts +69 -0
- package/out/runtime/interpreter.d.ts.map +1 -0
- package/out/runtime/interpreter.js +1163 -0
- package/out/runtime/interpreter.js.map +1 -0
- package/out/runtime/loader.d.ts +25 -0
- package/out/runtime/loader.d.ts.map +1 -0
- package/out/runtime/loader.js +346 -0
- package/out/runtime/loader.js.map +1 -0
- package/out/runtime/logger.d.ts +2 -0
- package/out/runtime/logger.d.ts.map +1 -0
- package/out/runtime/logger.js +44 -0
- package/out/runtime/logger.js.map +1 -0
- package/out/runtime/module.d.ts +273 -0
- package/out/runtime/module.d.ts.map +1 -0
- package/out/runtime/module.js +1786 -0
- package/out/runtime/module.js.map +1 -0
- package/out/runtime/modules/ai.d.ts +26 -0
- package/out/runtime/modules/ai.d.ts.map +1 -0
- package/out/runtime/modules/ai.js +211 -0
- package/out/runtime/modules/ai.js.map +1 -0
- package/out/runtime/modules/auth.d.ts +39 -0
- package/out/runtime/modules/auth.d.ts.map +1 -0
- package/out/runtime/modules/auth.js +359 -0
- package/out/runtime/modules/auth.js.map +1 -0
- package/out/runtime/modules/core.d.ts +2 -0
- package/out/runtime/modules/core.d.ts.map +1 -0
- package/out/runtime/modules/core.js +67 -0
- package/out/runtime/modules/core.js.map +1 -0
- package/out/runtime/relgraph.d.ts +21 -0
- package/out/runtime/relgraph.d.ts.map +1 -0
- package/out/runtime/relgraph.js +156 -0
- package/out/runtime/relgraph.js.map +1 -0
- package/out/runtime/resolvers/interface.d.ts +59 -0
- package/out/runtime/resolvers/interface.d.ts.map +1 -0
- package/out/runtime/resolvers/interface.js +111 -0
- package/out/runtime/resolvers/interface.js.map +1 -0
- package/out/runtime/resolvers/registry.d.ts +8 -0
- package/out/runtime/resolvers/registry.d.ts.map +1 -0
- package/out/runtime/resolvers/registry.js +26 -0
- package/out/runtime/resolvers/registry.js.map +1 -0
- package/out/runtime/resolvers/sqldb/database.d.ts +50 -0
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/database.js +618 -0
- package/out/runtime/resolvers/sqldb/database.js.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts +18 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.js +221 -0
- package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts +26 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.js +300 -0
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -0
- package/out/runtime/state.js +83 -0
- package/out/runtime/state.js.map +1 -0
- package/out/runtime/util.d.ts +43 -0
- package/out/runtime/util.d.ts.map +1 -0
- package/out/runtime/util.js +447 -0
- package/out/runtime/util.js.map +1 -0
- package/out/setupClassic.d.ts +98 -0
- package/out/setupClassic.d.ts.map +1 -0
- package/out/setupClassic.js +38 -0
- package/out/setupClassic.js.map +1 -0
- package/out/setupCommon.d.ts +2 -0
- package/out/setupCommon.d.ts.map +1 -0
- package/out/setupCommon.js +33 -0
- package/out/setupCommon.js.map +1 -0
- package/out/setupExtended.d.ts +40 -0
- package/out/setupExtended.d.ts.map +1 -0
- package/out/setupExtended.js +67 -0
- package/out/setupExtended.js.map +1 -0
- package/out/syntaxes/agentlang.monarch.d.ts +77 -0
- package/out/syntaxes/agentlang.monarch.d.ts.map +1 -0
- package/out/syntaxes/agentlang.monarch.js +31 -0
- package/out/syntaxes/agentlang.monarch.js.map +1 -0
- package/out/utils/fs/index.d.ts +14 -0
- package/out/utils/fs/index.d.ts.map +1 -0
- package/out/utils/fs/index.js +26 -0
- package/out/utils/fs/index.js.map +1 -0
- package/out/utils/fs/interfaces.d.ts +105 -0
- package/out/utils/fs/interfaces.d.ts.map +1 -0
- package/out/utils/fs/interfaces.js +5 -0
- package/out/utils/fs/interfaces.js.map +1 -0
- package/out/utils/fs/lightning-fs.d.ts +116 -0
- package/out/utils/fs/lightning-fs.d.ts.map +1 -0
- package/out/utils/fs/lightning-fs.js +243 -0
- package/out/utils/fs/lightning-fs.js.map +1 -0
- package/out/utils/fs/node-fs.d.ts +93 -0
- package/out/utils/fs/node-fs.d.ts.map +1 -0
- package/out/utils/fs/node-fs.js +169 -0
- package/out/utils/fs/node-fs.js.map +1 -0
- package/out/utils/fs-utils.d.ts +153 -0
- package/out/utils/fs-utils.d.ts.map +1 -0
- package/out/utils/fs-utils.js +271 -0
- package/out/utils/fs-utils.js.map +1 -0
- package/out/utils/runtime.d.ts +36 -0
- package/out/utils/runtime.d.ts.map +1 -0
- package/out/utils/runtime.js +39 -0
- package/out/utils/runtime.js.map +1 -0
- package/package.json +155 -0
- package/src/api/http.ts +361 -0
- package/src/cli/cli-util.ts +18 -0
- package/src/cli/main.ts +146 -0
- package/src/extension/main.ts +51 -0
- package/src/language/agentlang-module.ts +75 -0
- package/src/language/agentlang-validator.ts +60 -0
- package/src/language/agentlang.langium +178 -0
- package/src/language/generated/ast.ts +1698 -0
- package/src/language/generated/grammar.ts +4477 -0
- package/src/language/generated/module.ts +25 -0
- package/src/language/main-browser.ts +19 -0
- package/src/language/main.ts +13 -0
- package/src/language/parser.ts +329 -0
- package/src/language/syntax.ts +646 -0
- package/src/runtime/agents/common.ts +177 -0
- package/src/runtime/agents/impl/openai.ts +19 -0
- package/src/runtime/agents/provider.ts +58 -0
- package/src/runtime/agents/registry.ts +9 -0
- package/src/runtime/auth/cognito.ts +225 -0
- package/src/runtime/auth/defs.ts +33 -0
- package/src/runtime/auth/interface.ts +31 -0
- package/src/runtime/defs.ts +33 -0
- package/src/runtime/interpreter.ts +1352 -0
- package/src/runtime/loader.ts +450 -0
- package/src/runtime/logger.ts +51 -0
- package/src/runtime/module.ts +2188 -0
- package/src/runtime/modules/ai.ts +257 -0
- package/src/runtime/modules/auth.ts +489 -0
- package/src/runtime/modules/core.ts +95 -0
- package/src/runtime/relgraph.ts +195 -0
- package/src/runtime/resolvers/interface.ts +160 -0
- package/src/runtime/resolvers/registry.ts +30 -0
- package/src/runtime/resolvers/sqldb/database.ts +823 -0
- package/src/runtime/resolvers/sqldb/dbutil.ts +257 -0
- package/src/runtime/resolvers/sqldb/impl.ts +471 -0
- package/src/runtime/state.ts +87 -0
- package/src/runtime/util.ts +513 -0
- package/src/setupClassic.ts +43 -0
- package/src/setupCommon.ts +33 -0
- package/src/setupExtended.ts +79 -0
- package/src/syntaxes/agentlang.monarch.ts +31 -0
- package/src/utils/fs/index.ts +28 -0
- package/src/utils/fs/interfaces.ts +118 -0
- package/src/utils/fs/lightning-fs.ts +284 -0
- package/src/utils/fs/node-fs.ts +185 -0
- package/src/utils/fs-utils.ts +304 -0
- package/src/utils/runtime.ts +43 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser filesystem implementation using Lightning FS
|
|
3
|
+
*/
|
|
4
|
+
import { ExtendedFileSystem, FileStat } from './interfaces.js';
|
|
5
|
+
/**
|
|
6
|
+
* Browser filesystem implementation using Lightning FS
|
|
7
|
+
*/
|
|
8
|
+
export declare class LightningFileSystem implements ExtendedFileSystem {
|
|
9
|
+
private fs;
|
|
10
|
+
private initialized;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize Lightning FS
|
|
13
|
+
* @param options Lightning FS options
|
|
14
|
+
* @returns Promise that resolves when Lightning FS is initialized
|
|
15
|
+
*/
|
|
16
|
+
initialize(options?: {
|
|
17
|
+
name?: string;
|
|
18
|
+
wipe?: boolean;
|
|
19
|
+
persistentStorage?: boolean;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Ensure Lightning FS is initialized
|
|
23
|
+
*/
|
|
24
|
+
private ensureInitialized;
|
|
25
|
+
/**
|
|
26
|
+
* Read a file as text
|
|
27
|
+
* @param filePath path to the file
|
|
28
|
+
* @returns Promise resolving to file content as string
|
|
29
|
+
*/
|
|
30
|
+
readFile(filePath: string): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Read a file as binary
|
|
33
|
+
* @param filePath Path to the file
|
|
34
|
+
* @returns Promise resolving to file content as Buffer
|
|
35
|
+
*/
|
|
36
|
+
readFileBuffer(filePath: string): Promise<Buffer>;
|
|
37
|
+
/**
|
|
38
|
+
* Write content to a file
|
|
39
|
+
* @param filePath Path to the file
|
|
40
|
+
* @param data Content to write (string or Buffer)
|
|
41
|
+
* @returns Promise that resolves when write is complete
|
|
42
|
+
*/
|
|
43
|
+
writeFile(filePath: string, data: string | Buffer): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a file or directory exists
|
|
46
|
+
* @param filePath Path to check
|
|
47
|
+
* @returns Promise resolving to boolean indicate existence
|
|
48
|
+
*/
|
|
49
|
+
exists(filePath: string): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a directory
|
|
52
|
+
* @param dirPath Directory path to create
|
|
53
|
+
* @returns Promise that resolves when directory is created
|
|
54
|
+
*/
|
|
55
|
+
mkdir(dirPath: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* List files in a directory
|
|
58
|
+
* @param dirPath Directory path
|
|
59
|
+
* @returns Promise resolving to an array of file names
|
|
60
|
+
*/
|
|
61
|
+
readdir(dirPath: string): Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Get stats for a file or directory
|
|
64
|
+
* @param filePath Path to check
|
|
65
|
+
* @returns Promise resolving to stats object
|
|
66
|
+
*/
|
|
67
|
+
stat(filePath: string): Promise<FileStat>;
|
|
68
|
+
/**
|
|
69
|
+
* Remove a file
|
|
70
|
+
* @param filePath Path to the file
|
|
71
|
+
* @returns Promise that resolves when a file is removed
|
|
72
|
+
*/
|
|
73
|
+
unlink(filePath: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Remove a directory
|
|
76
|
+
* @param dirPath Path to the directory
|
|
77
|
+
* @returns Promise that resolves when directory is removed
|
|
78
|
+
*/
|
|
79
|
+
rmdir(dirPath: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Copy a file
|
|
82
|
+
* @param src Source path
|
|
83
|
+
* @param dest Destination path
|
|
84
|
+
* @returns Promise that resolves when copy is complete
|
|
85
|
+
*/
|
|
86
|
+
copyFile(src: string, dest: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Move a file
|
|
89
|
+
* @param src Source path
|
|
90
|
+
* @param dest Destination path
|
|
91
|
+
* @returns Promise that resolves when move is complete
|
|
92
|
+
*/
|
|
93
|
+
moveFile(src: string, dest: string): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Ensure a directory exists, creating it and any parent directories if needed
|
|
96
|
+
* @param dirPath Directory path
|
|
97
|
+
* @returns Promise that resolves when directory exists
|
|
98
|
+
*/
|
|
99
|
+
ensureDir(dirPath: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Remove a directory and all its contents recursively
|
|
102
|
+
* @param dirPath Directory path
|
|
103
|
+
* @returns Promise that resolves when directory is removed
|
|
104
|
+
*/
|
|
105
|
+
removeDir(dirPath: string): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a new Lightning FS instance
|
|
109
|
+
* @param options Configuration options
|
|
110
|
+
* @returns Promise resolving to LightningFileSystem instance
|
|
111
|
+
*/
|
|
112
|
+
export declare function createLightningFS(options?: {
|
|
113
|
+
name?: string;
|
|
114
|
+
wipe?: boolean;
|
|
115
|
+
}): Promise<ExtendedFileSystem>;
|
|
116
|
+
//# sourceMappingURL=lightning-fs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightning-fs.d.ts","sourceRoot":"","sources":["../../../src/utils/fs/lightning-fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE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,OAAO,CAAC,IAAI,CAAC;IAcxD;;;;;OAKG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcxD;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB/C;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA6BhD;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAI9B"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import LightningFS from '@isomorphic-git/lightning-fs';
|
|
2
|
+
/**
|
|
3
|
+
* Convert Lightning FS stats to our FileStat interface
|
|
4
|
+
*/
|
|
5
|
+
function convertStats(stats) {
|
|
6
|
+
return {
|
|
7
|
+
isFile: () => stats.isFile(),
|
|
8
|
+
isDirectory: () => stats.isDirectory(),
|
|
9
|
+
isSymbolicLink: () => false,
|
|
10
|
+
size: stats.size,
|
|
11
|
+
mtime: stats.mtime,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Browser filesystem implementation using Lightning FS
|
|
16
|
+
*/
|
|
17
|
+
export class LightningFileSystem {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.initialized = false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initialize Lightning FS
|
|
23
|
+
* @param options Lightning FS options
|
|
24
|
+
* @returns Promise that resolves when Lightning FS is initialized
|
|
25
|
+
*/
|
|
26
|
+
async initialize(options = {}) {
|
|
27
|
+
if (this.initialized) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const name = options.name || 'fs';
|
|
31
|
+
const lfs = new LightningFS(name, { wipe: options.wipe });
|
|
32
|
+
this.fs = lfs.promises;
|
|
33
|
+
this.initialized = true;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Ensure Lightning FS is initialized
|
|
37
|
+
*/
|
|
38
|
+
ensureInitialized() {
|
|
39
|
+
if (!this.initialized) {
|
|
40
|
+
throw new Error('LightningFileSystem is not initialized. Call initialize() first.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Read a file as text
|
|
45
|
+
* @param filePath path to the file
|
|
46
|
+
* @returns Promise resolving to file content as string
|
|
47
|
+
*/
|
|
48
|
+
async readFile(filePath) {
|
|
49
|
+
this.ensureInitialized();
|
|
50
|
+
const buffer = await this.fs.readFile(filePath, { encoding: 'utf8' });
|
|
51
|
+
return buffer.toString();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Read a file as binary
|
|
55
|
+
* @param filePath Path to the file
|
|
56
|
+
* @returns Promise resolving to file content as Buffer
|
|
57
|
+
*/
|
|
58
|
+
async readFileBuffer(filePath) {
|
|
59
|
+
this.ensureInitialized();
|
|
60
|
+
return this.fs.readFile(filePath);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Write content to a file
|
|
64
|
+
* @param filePath Path to the file
|
|
65
|
+
* @param data Content to write (string or Buffer)
|
|
66
|
+
* @returns Promise that resolves when write is complete
|
|
67
|
+
*/
|
|
68
|
+
async writeFile(filePath, data) {
|
|
69
|
+
this.ensureInitialized();
|
|
70
|
+
// Ensure the directory exists
|
|
71
|
+
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
72
|
+
if (dir) {
|
|
73
|
+
await this.ensureDir(dir);
|
|
74
|
+
}
|
|
75
|
+
return this.fs.writeFile(filePath, data);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if a file or directory exists
|
|
79
|
+
* @param filePath Path to check
|
|
80
|
+
* @returns Promise resolving to boolean indicate existence
|
|
81
|
+
*/
|
|
82
|
+
async exists(filePath) {
|
|
83
|
+
this.ensureInitialized();
|
|
84
|
+
try {
|
|
85
|
+
await this.fs.stat(filePath);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
catch (_a) {
|
|
89
|
+
// Just catch any error without binding it to a variable
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a directory
|
|
95
|
+
* @param dirPath Directory path to create
|
|
96
|
+
* @returns Promise that resolves when directory is created
|
|
97
|
+
*/
|
|
98
|
+
async mkdir(dirPath) {
|
|
99
|
+
this.ensureInitialized();
|
|
100
|
+
try {
|
|
101
|
+
return await this.fs.mkdir(dirPath);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
// Ignore if the directory already exists
|
|
105
|
+
if (err.code !== 'EEXIST') {
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* List files in a directory
|
|
112
|
+
* @param dirPath Directory path
|
|
113
|
+
* @returns Promise resolving to an array of file names
|
|
114
|
+
*/
|
|
115
|
+
async readdir(dirPath) {
|
|
116
|
+
this.ensureInitialized();
|
|
117
|
+
return this.fs.readdir(dirPath);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get stats for a file or directory
|
|
121
|
+
* @param filePath Path to check
|
|
122
|
+
* @returns Promise resolving to stats object
|
|
123
|
+
*/
|
|
124
|
+
async stat(filePath) {
|
|
125
|
+
this.ensureInitialized();
|
|
126
|
+
const stats = await this.fs.stat(filePath);
|
|
127
|
+
return convertStats(stats);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Remove a file
|
|
131
|
+
* @param filePath Path to the file
|
|
132
|
+
* @returns Promise that resolves when a file is removed
|
|
133
|
+
*/
|
|
134
|
+
async unlink(filePath) {
|
|
135
|
+
this.ensureInitialized();
|
|
136
|
+
return this.fs.unlink(filePath);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Remove a directory
|
|
140
|
+
* @param dirPath Path to the directory
|
|
141
|
+
* @returns Promise that resolves when directory is removed
|
|
142
|
+
*/
|
|
143
|
+
async rmdir(dirPath) {
|
|
144
|
+
this.ensureInitialized();
|
|
145
|
+
return this.fs.rmdir(dirPath);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Copy a file
|
|
149
|
+
* @param src Source path
|
|
150
|
+
* @param dest Destination path
|
|
151
|
+
* @returns Promise that resolves when copy is complete
|
|
152
|
+
*/
|
|
153
|
+
async copyFile(src, dest) {
|
|
154
|
+
this.ensureInitialized();
|
|
155
|
+
// Ensure destination directory exists
|
|
156
|
+
const destDir = dest.substring(0, dest.lastIndexOf('/'));
|
|
157
|
+
if (destDir) {
|
|
158
|
+
await this.ensureDir(destDir);
|
|
159
|
+
}
|
|
160
|
+
// Manual implementation
|
|
161
|
+
const content = await this.readFileBuffer(src);
|
|
162
|
+
return this.writeFile(dest, content);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Move a file
|
|
166
|
+
* @param src Source path
|
|
167
|
+
* @param dest Destination path
|
|
168
|
+
* @returns Promise that resolves when move is complete
|
|
169
|
+
*/
|
|
170
|
+
async moveFile(src, dest) {
|
|
171
|
+
this.ensureInitialized();
|
|
172
|
+
// Ensure destination directory exists
|
|
173
|
+
const destDir = dest.substring(0, dest.lastIndexOf('/'));
|
|
174
|
+
if (destDir) {
|
|
175
|
+
await this.ensureDir(destDir);
|
|
176
|
+
}
|
|
177
|
+
// Copy then delete the original
|
|
178
|
+
await this.copyFile(src, dest);
|
|
179
|
+
await this.unlink(src);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Ensure a directory exists, creating it and any parent directories if needed
|
|
183
|
+
* @param dirPath Directory path
|
|
184
|
+
* @returns Promise that resolves when directory exists
|
|
185
|
+
*/
|
|
186
|
+
async ensureDir(dirPath) {
|
|
187
|
+
this.ensureInitialized();
|
|
188
|
+
// Check if the directory already exists
|
|
189
|
+
const exists = await this.exists(dirPath);
|
|
190
|
+
if (exists) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// Create with a recursive option (Lightning FS supports this)
|
|
194
|
+
try {
|
|
195
|
+
await this.fs.mkdir(dirPath, { recursive: true });
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
// Ignore if the directory already exists (race condition)
|
|
199
|
+
if (err.code !== 'EEXIST') {
|
|
200
|
+
throw err;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Remove a directory and all its contents recursively
|
|
206
|
+
* @param dirPath Directory path
|
|
207
|
+
* @returns Promise that resolves when directory is removed
|
|
208
|
+
*/
|
|
209
|
+
async removeDir(dirPath) {
|
|
210
|
+
this.ensureInitialized();
|
|
211
|
+
// Check if path exists
|
|
212
|
+
const exists = await this.exists(dirPath);
|
|
213
|
+
if (!exists) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// Get stats to check if it's a file or directory
|
|
217
|
+
const stats = await this.stat(dirPath);
|
|
218
|
+
if (stats.isFile()) {
|
|
219
|
+
// If it's a file, just unlink it
|
|
220
|
+
return this.unlink(dirPath);
|
|
221
|
+
}
|
|
222
|
+
// If it's a directory, remove all contents first
|
|
223
|
+
const files = await this.readdir(dirPath);
|
|
224
|
+
// Remove each file/directory in the directory
|
|
225
|
+
for (const file of files) {
|
|
226
|
+
const filePath = `${dirPath}/${file}`;
|
|
227
|
+
await this.removeDir(filePath);
|
|
228
|
+
}
|
|
229
|
+
// Finally, remove the empty directory
|
|
230
|
+
return this.rmdir(dirPath);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Create a new Lightning FS instance
|
|
235
|
+
* @param options Configuration options
|
|
236
|
+
* @returns Promise resolving to LightningFileSystem instance
|
|
237
|
+
*/
|
|
238
|
+
export async function createLightningFS(options) {
|
|
239
|
+
const fs = new LightningFileSystem();
|
|
240
|
+
await fs.initialize(options);
|
|
241
|
+
return fs;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=lightning-fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightning-fs.js","sourceRoot":"","sources":["../../../src/utils/fs/lightning-fs.ts"],"names":[],"mappings":"AAIA,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAEvD;;GAEG;AACH,SAAS,YAAY,CAAC,KAAU;IAC9B,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;QAC5B,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE;QACtC,cAAc,EAAE,GAAG,EAAE,CAAC,KAAK;QAC3B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAAhC;QAEU,gBAAW,GAAY,KAAK,CAAC;IAqPvC,CAAC;IAnPC;;;;OAIG;IACH,KAAK,CAAC,UAAU,CACd,UAII,EAAE;QAEN,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;QAClC,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,QAAQ,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED;;OAEG;IACK,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;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eFileSystem implements ExtendedFileSystem {
|
|
6
|
+
/**
|
|
7
|
+
* Read a file as text
|
|
8
|
+
* @param filePath Path to the file
|
|
9
|
+
* @returns Promise resolving to file content as string
|
|
10
|
+
*/
|
|
11
|
+
readFile(filePath: string): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Read a file as binary
|
|
14
|
+
* @param filePath Path to the file
|
|
15
|
+
* @returns Promise resolving to file content as Buffer
|
|
16
|
+
*/
|
|
17
|
+
readFileBuffer(filePath: string): Promise<Buffer>;
|
|
18
|
+
/**
|
|
19
|
+
* Write content to a file
|
|
20
|
+
* @param filePath Path to the file
|
|
21
|
+
* @param data Content to write (string or Buffer)
|
|
22
|
+
* @returns Promise that resolves when write is complete
|
|
23
|
+
*/
|
|
24
|
+
writeFile(filePath: string, data: string | Buffer): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a file or directory exists
|
|
27
|
+
* @param filePath Path to check
|
|
28
|
+
* @returns Promise resolving to boolean which indicates existence
|
|
29
|
+
*/
|
|
30
|
+
exists(filePath: string): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a directory
|
|
33
|
+
* @param dirPath Directory path to create
|
|
34
|
+
* @returns Promise that resolves when directory is created
|
|
35
|
+
*/
|
|
36
|
+
mkdir(dirPath: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* List files in a directory
|
|
39
|
+
* @param dirPath Directory path
|
|
40
|
+
* @returns Promise resolving to an array of file names
|
|
41
|
+
*/
|
|
42
|
+
readdir(dirPath: string): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Get stats for a file or directory
|
|
45
|
+
* @param filePath Path to check
|
|
46
|
+
* @returns Promise resolving to stats object
|
|
47
|
+
*/
|
|
48
|
+
stat(filePath: string): Promise<FileStat>;
|
|
49
|
+
/**
|
|
50
|
+
* Remove a file
|
|
51
|
+
* @param filePath Path to the file
|
|
52
|
+
* @returns Promise that resolves when a file is removed
|
|
53
|
+
*/
|
|
54
|
+
unlink(filePath: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Remove a directory
|
|
57
|
+
* @param dirPath Path to the directory
|
|
58
|
+
* @returns Promise that resolves when directory is removed
|
|
59
|
+
*/
|
|
60
|
+
rmdir(dirPath: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Copy a file
|
|
63
|
+
* @param src Source path
|
|
64
|
+
* @param dest Destination path
|
|
65
|
+
* @returns Promise that resolves when copy is complete
|
|
66
|
+
*/
|
|
67
|
+
copyFile(src: string, dest: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Move a file
|
|
70
|
+
* @param src Source path
|
|
71
|
+
* @param dest Destination path
|
|
72
|
+
* @returns Promise that resolves when move is complete
|
|
73
|
+
*/
|
|
74
|
+
moveFile(src: string, dest: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Ensure a directory exists, creating it and any parent directories if needed
|
|
77
|
+
* @param dirPath Directory path
|
|
78
|
+
* @returns Promise that resolves when directory exists
|
|
79
|
+
*/
|
|
80
|
+
ensureDir(dirPath: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Remove a directory and all its contents recursively
|
|
83
|
+
* @param dirPath Directory path
|
|
84
|
+
* @returns Promise that resolves when directory is removed
|
|
85
|
+
*/
|
|
86
|
+
removeDir(dirPath: string): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a new Node.js filesystem instance
|
|
90
|
+
* @returns NodeFileSystem instance
|
|
91
|
+
*/
|
|
92
|
+
export declare function createNodeFS(): ExtendedFileSystem;
|
|
93
|
+
//# sourceMappingURL=node-fs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fs.d.ts","sourceRoot":"","sources":["../../../src/utils/fs/node-fs.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAe/D;;GAEG;AAC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AAY,IAAI,kBAAkB,CAEjD"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js filesystem implementation
|
|
3
|
+
*/
|
|
4
|
+
import * as fs from 'node:fs/promises';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
/**
|
|
7
|
+
* Convert Node.js fs.Stats to our FileStat interface
|
|
8
|
+
*/
|
|
9
|
+
function convertStats(stats) {
|
|
10
|
+
return {
|
|
11
|
+
isFile: () => stats.isFile(),
|
|
12
|
+
isDirectory: () => stats.isDirectory(),
|
|
13
|
+
isSymbolicLink: () => stats.isSymbolicLink(),
|
|
14
|
+
size: stats.size,
|
|
15
|
+
mtime: stats.mtime,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Node.js filesystem implementation
|
|
20
|
+
*/
|
|
21
|
+
export class NodeFileSystem {
|
|
22
|
+
/**
|
|
23
|
+
* Read a file as text
|
|
24
|
+
* @param filePath Path to the file
|
|
25
|
+
* @returns Promise resolving to file content as string
|
|
26
|
+
*/
|
|
27
|
+
async readFile(filePath) {
|
|
28
|
+
return fs.readFile(filePath, 'utf8');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Read a file as binary
|
|
32
|
+
* @param filePath Path to the file
|
|
33
|
+
* @returns Promise resolving to file content as Buffer
|
|
34
|
+
*/
|
|
35
|
+
async readFileBuffer(filePath) {
|
|
36
|
+
return fs.readFile(filePath);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Write content to a file
|
|
40
|
+
* @param filePath Path to the file
|
|
41
|
+
* @param data Content to write (string or Buffer)
|
|
42
|
+
* @returns Promise that resolves when write is complete
|
|
43
|
+
*/
|
|
44
|
+
async writeFile(filePath, data) {
|
|
45
|
+
// Ensure the directory exists
|
|
46
|
+
const dir = path.dirname(filePath);
|
|
47
|
+
await this.ensureDir(dir);
|
|
48
|
+
return fs.writeFile(filePath, data);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if a file or directory exists
|
|
52
|
+
* @param filePath Path to check
|
|
53
|
+
* @returns Promise resolving to boolean which indicates existence
|
|
54
|
+
*/
|
|
55
|
+
async exists(filePath) {
|
|
56
|
+
try {
|
|
57
|
+
await fs.access(filePath);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch (_a) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create a directory
|
|
66
|
+
* @param dirPath Directory path to create
|
|
67
|
+
* @returns Promise that resolves when directory is created
|
|
68
|
+
*/
|
|
69
|
+
async mkdir(dirPath) {
|
|
70
|
+
try {
|
|
71
|
+
await fs.mkdir(dirPath);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
// Ignore if the directory already exists
|
|
75
|
+
if (err.code !== 'EEXIST') {
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* List files in a directory
|
|
82
|
+
* @param dirPath Directory path
|
|
83
|
+
* @returns Promise resolving to an array of file names
|
|
84
|
+
*/
|
|
85
|
+
async readdir(dirPath) {
|
|
86
|
+
return fs.readdir(dirPath);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get stats for a file or directory
|
|
90
|
+
* @param filePath Path to check
|
|
91
|
+
* @returns Promise resolving to stats object
|
|
92
|
+
*/
|
|
93
|
+
async stat(filePath) {
|
|
94
|
+
const stats = await fs.stat(filePath);
|
|
95
|
+
return convertStats(stats);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Remove a file
|
|
99
|
+
* @param filePath Path to the file
|
|
100
|
+
* @returns Promise that resolves when a file is removed
|
|
101
|
+
*/
|
|
102
|
+
async unlink(filePath) {
|
|
103
|
+
return fs.unlink(filePath);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Remove a directory
|
|
107
|
+
* @param dirPath Path to the directory
|
|
108
|
+
* @returns Promise that resolves when directory is removed
|
|
109
|
+
*/
|
|
110
|
+
async rmdir(dirPath) {
|
|
111
|
+
return fs.rmdir(dirPath);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Copy a file
|
|
115
|
+
* @param src Source path
|
|
116
|
+
* @param dest Destination path
|
|
117
|
+
* @returns Promise that resolves when copy is complete
|
|
118
|
+
*/
|
|
119
|
+
async copyFile(src, dest) {
|
|
120
|
+
// Ensure destination directory exists
|
|
121
|
+
const destDir = path.dirname(dest);
|
|
122
|
+
await this.ensureDir(destDir);
|
|
123
|
+
return fs.copyFile(src, dest);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Move a file
|
|
127
|
+
* @param src Source path
|
|
128
|
+
* @param dest Destination path
|
|
129
|
+
* @returns Promise that resolves when move is complete
|
|
130
|
+
*/
|
|
131
|
+
async moveFile(src, dest) {
|
|
132
|
+
// Ensure destination directory exists
|
|
133
|
+
const destDir = path.dirname(dest);
|
|
134
|
+
await this.ensureDir(destDir);
|
|
135
|
+
return fs.rename(src, dest);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Ensure a directory exists, creating it and any parent directories if needed
|
|
139
|
+
* @param dirPath Directory path
|
|
140
|
+
* @returns Promise that resolves when directory exists
|
|
141
|
+
*/
|
|
142
|
+
async ensureDir(dirPath) {
|
|
143
|
+
try {
|
|
144
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
// Ignore if the directory already exists
|
|
148
|
+
if (err.code !== 'EEXIST') {
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Remove a directory and all its contents recursively
|
|
155
|
+
* @param dirPath Directory path
|
|
156
|
+
* @returns Promise that resolves when directory is removed
|
|
157
|
+
*/
|
|
158
|
+
async removeDir(dirPath) {
|
|
159
|
+
return fs.rm(dirPath, { recursive: true, force: true });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a new Node.js filesystem instance
|
|
164
|
+
* @returns NodeFileSystem instance
|
|
165
|
+
*/
|
|
166
|
+
export function createNodeFS() {
|
|
167
|
+
return new NodeFileSystem();
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=node-fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fs.js","sourceRoot":"","sources":["../../../src/utils/fs/node-fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC;;GAEG;AACH,SAAS,YAAY,CAAC,KAAY;IAChC,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;QAC5B,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE;QACtC,cAAc,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE;QAC5C,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,cAAc;IACzB;;;;OAIG;IACH,KAAK,CAAC,QAAQ,CAAC,QAAgB;QAC7B,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,cAAc,CAAC,QAAgB;QACnC,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,QAAgB,EAAE,IAAqB;QACrD,8BAA8B;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CA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