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,304 @@
|
|
|
1
|
+
import { ExtendedFileSystem, createFS } from '../utils/fs/index.js';
|
|
2
|
+
import { URI as VSCodeURI } from 'vscode-uri';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Re-export the URI type from vscode-uri
|
|
6
|
+
*/
|
|
7
|
+
export type URI = VSCodeURI;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a URI from a string
|
|
11
|
+
* @param uriString String representation of a URI
|
|
12
|
+
* @returns URI object
|
|
13
|
+
*/
|
|
14
|
+
export function createURI(uriString: string): URI {
|
|
15
|
+
return VSCodeURI.parse(uriString);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a file URI from a file path
|
|
20
|
+
* @param filePath File path (can be absolute or relative)
|
|
21
|
+
* @returns File URI object
|
|
22
|
+
*/
|
|
23
|
+
export function createFileURI(filePath: string): URI {
|
|
24
|
+
return VSCodeURI.file(filePath);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a directory URI from a directory path
|
|
29
|
+
* @param dirPath Directory path (can be absolute or relative)
|
|
30
|
+
* @returns Directory URI object
|
|
31
|
+
*/
|
|
32
|
+
export function createDirectoryURI(dirPath: string): URI {
|
|
33
|
+
// Ensure path ends with a slash for directories
|
|
34
|
+
if (!dirPath.endsWith('/') && !dirPath.endsWith('\\')) {
|
|
35
|
+
dirPath = `${dirPath}/`;
|
|
36
|
+
}
|
|
37
|
+
return VSCodeURI.file(dirPath);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Helper function to extract filesystem path from URI or string
|
|
42
|
+
* @param uri URI or string representation of URI
|
|
43
|
+
* @returns Filesystem path
|
|
44
|
+
*/
|
|
45
|
+
export function toFsPath(uri: URI | string): string {
|
|
46
|
+
return typeof uri === 'string' ? VSCodeURI.parse(uri).fsPath : uri.fsPath;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Singleton instance of the filesystem
|
|
51
|
+
*/
|
|
52
|
+
let fsInstance: ExtendedFileSystem | null = null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Initialize the filesystem with the appropriate implementation based on environment
|
|
56
|
+
* @param options Optional configuration for the filesystem
|
|
57
|
+
* @returns Promise resolving to the filesystem instance
|
|
58
|
+
*/
|
|
59
|
+
export async function initializeFileSystem(options?: any): Promise<ExtendedFileSystem> {
|
|
60
|
+
if (!fsInstance) {
|
|
61
|
+
fsInstance = await createFS(options);
|
|
62
|
+
}
|
|
63
|
+
return fsInstance;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get the filesystem instance, initializing it if necessary
|
|
68
|
+
* @param options Optional configuration for the filesystem
|
|
69
|
+
* @returns Promise resolving to the filesystem instance
|
|
70
|
+
*/
|
|
71
|
+
export async function getFileSystem(options?: any): Promise<ExtendedFileSystem> {
|
|
72
|
+
return fsInstance || initializeFileSystem(options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Read a file as text
|
|
77
|
+
* @param uri URI to the file
|
|
78
|
+
* @returns Promise resolving to file content as string
|
|
79
|
+
*/
|
|
80
|
+
export async function readFile(uri: URI | string): Promise<string> {
|
|
81
|
+
const fs = await getFileSystem();
|
|
82
|
+
const path = toFsPath(uri);
|
|
83
|
+
return fs.readFile(path);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Read a file as binary
|
|
88
|
+
* @param uri URI to the file
|
|
89
|
+
* @returns Promise resolving to file content as Buffer
|
|
90
|
+
*/
|
|
91
|
+
export async function readFileBuffer(uri: URI | string): Promise<Buffer> {
|
|
92
|
+
const fs = await getFileSystem();
|
|
93
|
+
const path = toFsPath(uri);
|
|
94
|
+
return fs.readFileBuffer(path);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Write content to a file
|
|
99
|
+
* @param uri URI to the file
|
|
100
|
+
* @param data Content to write (string or Buffer)
|
|
101
|
+
* @returns Promise that resolves when write is complete
|
|
102
|
+
*/
|
|
103
|
+
export async function writeFile(uri: URI | string, data: string | Buffer): Promise<void> {
|
|
104
|
+
const fs = await getFileSystem();
|
|
105
|
+
const path = toFsPath(uri);
|
|
106
|
+
return fs.writeFile(path, data);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Check if a file or directory exists
|
|
111
|
+
* @param uri URI to check
|
|
112
|
+
* @returns Promise resolving to boolean indicating existence
|
|
113
|
+
*/
|
|
114
|
+
export async function exists(uri: URI | string): Promise<boolean> {
|
|
115
|
+
const fs = await getFileSystem();
|
|
116
|
+
const path = toFsPath(uri);
|
|
117
|
+
return fs.exists(path);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Create a directory
|
|
122
|
+
* @param uri Directory URI to create
|
|
123
|
+
* @returns Promise that resolves when directory is created
|
|
124
|
+
*/
|
|
125
|
+
export async function mkdir(uri: URI | string): Promise<void> {
|
|
126
|
+
const fs = await getFileSystem();
|
|
127
|
+
const path = toFsPath(uri);
|
|
128
|
+
return fs.mkdir(path);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* List files in a directory
|
|
133
|
+
* @param uri Directory URI
|
|
134
|
+
* @returns Promise resolving to array of file names
|
|
135
|
+
*/
|
|
136
|
+
export async function readdir(uri: URI | string): Promise<string[]> {
|
|
137
|
+
const fs = await getFileSystem();
|
|
138
|
+
const path = toFsPath(uri);
|
|
139
|
+
return fs.readdir(path);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* List files in a Directory (Wrapper for readdir)
|
|
144
|
+
* @param uri Directory URI
|
|
145
|
+
* @returns Promise resolving to array of file names
|
|
146
|
+
*/
|
|
147
|
+
export async function readDirectory(uri: URI | string): Promise<string[]> {
|
|
148
|
+
return readdir(uri);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get stats for a file or directory
|
|
153
|
+
* @param uri URI to check
|
|
154
|
+
* @returns Promise resolving to stats object
|
|
155
|
+
*/
|
|
156
|
+
export async function stat(uri: URI | string): Promise<any> {
|
|
157
|
+
const fs = await getFileSystem();
|
|
158
|
+
const path = toFsPath(uri);
|
|
159
|
+
return fs.stat(path);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Remove a file
|
|
164
|
+
* @param uri URI to the file
|
|
165
|
+
* @returns Promise that resolves when file is removed
|
|
166
|
+
*/
|
|
167
|
+
export async function unlink(uri: URI | string): Promise<void> {
|
|
168
|
+
const fs = await getFileSystem();
|
|
169
|
+
const path = toFsPath(uri);
|
|
170
|
+
return fs.unlink(path);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Remove a directory
|
|
175
|
+
* @param uri URI to the directory
|
|
176
|
+
* @returns Promise that resolves when directory is removed
|
|
177
|
+
*/
|
|
178
|
+
export async function rmdir(uri: URI | string): Promise<void> {
|
|
179
|
+
const fs = await getFileSystem();
|
|
180
|
+
const path = toFsPath(uri);
|
|
181
|
+
return fs.rmdir(path);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Copy a file
|
|
186
|
+
* @param srcUri Source URI
|
|
187
|
+
* @param destUri Destination URI
|
|
188
|
+
* @returns Promise that resolves when copy is complete
|
|
189
|
+
*/
|
|
190
|
+
export async function copyFile(srcUri: URI | string, destUri: URI | string): Promise<void> {
|
|
191
|
+
const fs = await getFileSystem();
|
|
192
|
+
const srcPath = toFsPath(srcUri);
|
|
193
|
+
const destPath = toFsPath(destUri);
|
|
194
|
+
return fs.copyFile(srcPath, destPath);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Move a file
|
|
199
|
+
* @param srcUri Source URI
|
|
200
|
+
* @param destUri Destination URI
|
|
201
|
+
* @returns Promise that resolves when move is complete
|
|
202
|
+
*/
|
|
203
|
+
export async function moveFile(srcUri: URI | string, destUri: URI | string): Promise<void> {
|
|
204
|
+
const fs = await getFileSystem();
|
|
205
|
+
const srcPath = toFsPath(srcUri);
|
|
206
|
+
const destPath = toFsPath(destUri);
|
|
207
|
+
return fs.moveFile(srcPath, destPath);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Ensure a directory exists, creating it and any parent directories if needed
|
|
212
|
+
* @param uri Directory URI
|
|
213
|
+
* @returns Promise that resolves when directory exists
|
|
214
|
+
*/
|
|
215
|
+
export async function ensureDir(uri: URI | string): Promise<void> {
|
|
216
|
+
const fs = await getFileSystem();
|
|
217
|
+
const path = toFsPath(uri);
|
|
218
|
+
return fs.ensureDir(path);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Remove a directory and all its contents recursively
|
|
223
|
+
* @param uri Directory URI
|
|
224
|
+
* @returns Promise that resolves when directory is removed
|
|
225
|
+
*/
|
|
226
|
+
export async function removeDir(uri: URI | string): Promise<void> {
|
|
227
|
+
const fs = await getFileSystem();
|
|
228
|
+
const path = toFsPath(uri);
|
|
229
|
+
return fs.removeDir(path);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Determine if we're running in a browser environment
|
|
234
|
+
* @returns boolean indicating if in browser
|
|
235
|
+
*/
|
|
236
|
+
export function isBrowser(): boolean {
|
|
237
|
+
return typeof window !== 'undefined';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Determine if we're running in Node.js environment
|
|
242
|
+
* @returns boolean indicating if in Node.js
|
|
243
|
+
*/
|
|
244
|
+
export function isNode(): boolean {
|
|
245
|
+
return typeof window === 'undefined';
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Joins a URI with path segments
|
|
250
|
+
* @param base Base URI
|
|
251
|
+
* @param pathSegments Path segments to join
|
|
252
|
+
* @returns New URI with joined path
|
|
253
|
+
*/
|
|
254
|
+
export function joinURI(base: URI | string, ...pathSegments: string[]): URI {
|
|
255
|
+
const baseUri = typeof base === 'string' ? VSCodeURI.parse(base) : base;
|
|
256
|
+
let path = baseUri.path;
|
|
257
|
+
|
|
258
|
+
// Join the path segments
|
|
259
|
+
for (const segment of pathSegments) {
|
|
260
|
+
// Make sure we don't double up on slashes
|
|
261
|
+
if (path.endsWith('/') && segment.startsWith('/')) {
|
|
262
|
+
path += segment.substring(1);
|
|
263
|
+
} else if (!path.endsWith('/') && !segment.startsWith('/')) {
|
|
264
|
+
path += '/' + segment;
|
|
265
|
+
} else {
|
|
266
|
+
path += segment;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Create a new URI with the same scheme and authority but updated path
|
|
271
|
+
return VSCodeURI.from({
|
|
272
|
+
scheme: baseUri.scheme,
|
|
273
|
+
authority: baseUri.authority,
|
|
274
|
+
path,
|
|
275
|
+
query: baseUri.query,
|
|
276
|
+
fragment: baseUri.fragment,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Gets the parent directory URI from a file or directory URI
|
|
282
|
+
* @param uri URI to get parent from
|
|
283
|
+
* @returns Parent directory URI
|
|
284
|
+
*/
|
|
285
|
+
export function getParentURI(uri: URI | string): URI {
|
|
286
|
+
const uriObj = typeof uri === 'string' ? VSCodeURI.parse(uri) : uri;
|
|
287
|
+
|
|
288
|
+
// Split the path into segments
|
|
289
|
+
const segments = uriObj.path.split('/').filter(Boolean);
|
|
290
|
+
|
|
291
|
+
// Remove the last segment (file or directory name)
|
|
292
|
+
segments.pop();
|
|
293
|
+
|
|
294
|
+
// Create a new path with the parent segments
|
|
295
|
+
const parentPath = '/' + segments.join('/');
|
|
296
|
+
|
|
297
|
+
return VSCodeURI.from({
|
|
298
|
+
scheme: uriObj.scheme,
|
|
299
|
+
authority: uriObj.authority,
|
|
300
|
+
path: parentPath,
|
|
301
|
+
query: uriObj.query,
|
|
302
|
+
fragment: uriObj.fragment,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export let chalk: any;
|
|
2
|
+
|
|
3
|
+
// Environment detection
|
|
4
|
+
export const isNodeEnv =
|
|
5
|
+
typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
6
|
+
|
|
7
|
+
if (isNodeEnv) {
|
|
8
|
+
// Only import Node.js modules in Node environment
|
|
9
|
+
// Using dynamic imports to avoid breaking browser bundling
|
|
10
|
+
import('chalk').then(module => {
|
|
11
|
+
chalk = module.default;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Browser-compatible path utilities
|
|
16
|
+
export const browserPath = {
|
|
17
|
+
extname: (path: string): string => {
|
|
18
|
+
const lastDotIndex = path.lastIndexOf('.');
|
|
19
|
+
return lastDotIndex !== -1 ? path.substring(lastDotIndex) : '';
|
|
20
|
+
},
|
|
21
|
+
basename: (path: string, ext?: string): string => {
|
|
22
|
+
let name = path.split('/').pop() || '';
|
|
23
|
+
if (ext && name.endsWith(ext)) {
|
|
24
|
+
name = name.substring(0, name.length - ext.length);
|
|
25
|
+
}
|
|
26
|
+
return name;
|
|
27
|
+
},
|
|
28
|
+
dirname: (path: string): string => {
|
|
29
|
+
const parts = path.split('/');
|
|
30
|
+
parts.pop();
|
|
31
|
+
return parts.join('/') || '.';
|
|
32
|
+
},
|
|
33
|
+
join: (...parts: string[]): string => {
|
|
34
|
+
return parts.filter(Boolean).join('/').replace(/\/+/g, '/');
|
|
35
|
+
},
|
|
36
|
+
resolve: (path: string): string => {
|
|
37
|
+
return path;
|
|
38
|
+
},
|
|
39
|
+
sep: '/',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Use either Node.js path or browser path based on environment
|
|
43
|
+
export const path = isNodeEnv ? await import('node:path').then(module => module) : browserPath;
|