aws-runtime-bridge 1.7.20 → 1.7.21

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.
@@ -141,6 +141,48 @@ async function listHostDirectories(requestPath = '') {
141
141
  items
142
142
  };
143
143
  }
144
+ async function resolveHostDirectoryPath(targetPath) {
145
+ const normalizedPath = path.normalize(String(targetPath || ''));
146
+ const stat = await fs.stat(normalizedPath);
147
+ if (!stat.isDirectory()) {
148
+ throw new Error('Path is not a directory: ' + normalizedPath);
149
+ }
150
+ return normalizedPath;
151
+ }
152
+ function assertSafeDirectoryEntryName(entryName) {
153
+ const trimmedName = String(entryName || '').trim();
154
+ if (!trimmedName) {
155
+ throw new Error('Folder name is required');
156
+ }
157
+ if (trimmedName.includes('/') || trimmedName.includes('\\') || trimmedName === '.' || trimmedName === '..') {
158
+ throw new Error('Folder name must not contain path separators');
159
+ }
160
+ return trimmedName;
161
+ }
162
+ async function createHostDirectory(parentPath, entryName) {
163
+ const parentDirectory = await resolveHostDirectoryPath(parentPath);
164
+ const safeEntryName = assertSafeDirectoryEntryName(entryName);
165
+ const targetPath = path.join(parentDirectory, safeEntryName);
166
+ await fs.mkdir(targetPath);
167
+ return {
168
+ ok: true,
169
+ parentPath,
170
+ targetPath: targetPath.replace(/\\/g, '/'),
171
+ entryName: safeEntryName
172
+ };
173
+ }
174
+ async function renameHostDirectory(targetPath, newName) {
175
+ const sourcePath = await resolveHostDirectoryPath(targetPath);
176
+ const safeNewName = assertSafeDirectoryEntryName(newName);
177
+ const destinationPath = path.join(path.dirname(sourcePath), safeNewName);
178
+ await fs.rename(sourcePath, destinationPath);
179
+ return {
180
+ ok: true,
181
+ sourcePath: sourcePath.replace(/\\/g, '/'),
182
+ targetPath: destinationPath.replace(/\\/g, '/'),
183
+ newName: safeNewName
184
+ };
185
+ }
144
186
  /**
145
187
  * 列出目录内容
146
188
  * POST /api/file-browser/list
@@ -219,6 +261,36 @@ fileBrowserRouter.post('/workspace/read', validateToken, async (req, res) => {
219
261
  res.status(400).json({ error: err.message });
220
262
  }
221
263
  });
264
+ /**
265
+ * 在目录选择器当前位置创建文件夹。
266
+ * POST /api/file-browser/directory-picker/create
267
+ */
268
+ fileBrowserRouter.post('/directory-picker/create', validateToken, async (req, res) => {
269
+ try {
270
+ const { path: requestPath = '', entryName } = req.body || {};
271
+ res.json(await createHostDirectory(String(requestPath || ''), String(entryName || '')));
272
+ }
273
+ catch (error) {
274
+ const err = error;
275
+ log.error('failed to create directory from directory picker:', err);
276
+ res.status(400).json({ error: err.message });
277
+ }
278
+ });
279
+ /**
280
+ * 重命名目录选择器中的文件夹。
281
+ * POST /api/file-browser/directory-picker/rename
282
+ */
283
+ fileBrowserRouter.post('/directory-picker/rename', validateToken, async (req, res) => {
284
+ try {
285
+ const { targetPath, newName } = req.body || {};
286
+ res.json(await renameHostDirectory(String(targetPath || ''), String(newName || '')));
287
+ }
288
+ catch (error) {
289
+ const err = error;
290
+ log.error('failed to rename directory from directory picker:', err);
291
+ res.status(400).json({ error: err.message });
292
+ }
293
+ });
222
294
  /**
223
295
  * 预览工作区文档内容。
224
296
  * POST /api/file-browser/workspace/preview
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-runtime-bridge",
3
- "version": "1.7.20",
3
+ "version": "1.7.21",
4
4
  "description": "AgentsWorkStudio runtime bridge service for machine-level agent runtime integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",