@keyou007/agent-bot 0.1.15-alpha.1 → 0.1.15-alpha.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/CHANGELOG.md +4 -0
- package/dist/feishu/CardRenderer.js +63 -8
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuConnector.js +4 -1
- package/dist/feishu/FeishuConnector.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +79 -5
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/feishu/CardRenderer.ts +75 -8
- package/src/feishu/FeishuConnector.ts +4 -1
- package/src/proxy/ProxySessionController.ts +85 -5
|
@@ -526,6 +526,25 @@ export class ProxySessionController {
|
|
|
526
526
|
await this.assertSendableFile(filePath);
|
|
527
527
|
await this.outbound.sendFile(contextKey, filePath);
|
|
528
528
|
}
|
|
529
|
+
else if (kind === "directory_new_folder_prompt") {
|
|
530
|
+
const directory = directoryActionPath(scopedAction.value.directory);
|
|
531
|
+
await this.assertBrowsableDirectory(directory);
|
|
532
|
+
await this.outbound.updateInteractiveCard(contextKey, requiredCardMessageId(scopedAction.messageId), this.cardRenderer.renderDirectoryNewFolderCard({
|
|
533
|
+
directory,
|
|
534
|
+
displayDirectory: abbreviateHomeDirectory(directory),
|
|
535
|
+
contextKey,
|
|
536
|
+
page: directoryPageValue(scopedAction.value.page),
|
|
537
|
+
}));
|
|
538
|
+
}
|
|
539
|
+
else if (kind === "directory_new_folder_submit") {
|
|
540
|
+
await this.createDirectoryFromCard(contextKey, scopedAction);
|
|
541
|
+
}
|
|
542
|
+
else if (kind === "directory_new_folder_cancel") {
|
|
543
|
+
await this.openDirectoryBrowser(contextKey, directoryActionPath(scopedAction.value.directory), {
|
|
544
|
+
updateMessageId: requiredCardMessageId(scopedAction.messageId),
|
|
545
|
+
page: directoryPageValue(scopedAction.value.page),
|
|
546
|
+
});
|
|
547
|
+
}
|
|
529
548
|
else if (kind === "directory_new" || kind === "directory_new_group") {
|
|
530
549
|
const directory = directoryActionPath(scopedAction.value.directory);
|
|
531
550
|
await this.assertBrowsableDirectory(directory);
|
|
@@ -3828,12 +3847,12 @@ export class ProxySessionController {
|
|
|
3828
3847
|
const card = this.cardRenderer.renderDirectoryBrowserCard({
|
|
3829
3848
|
directory: abbreviateHomeDirectory(directory),
|
|
3830
3849
|
entries: visibleEntries,
|
|
3831
|
-
currentActions: directoryCreationActions(directory, contextKey),
|
|
3850
|
+
currentActions: directoryCreationActions(directory, contextKey, page),
|
|
3832
3851
|
navigationActions,
|
|
3833
3852
|
footerLines: [
|
|
3834
3853
|
`第 ${page + 1}/${totalPages} 页 · ${directoryCount} 个目录 · ${entries.length - directoryCount} 个文件`,
|
|
3835
3854
|
"",
|
|
3836
|
-
">
|
|
3855
|
+
"> 点击目录名称进入,点击文件名称发送到当前会话;卡片顶部可新建目录、任务或群聊。",
|
|
3837
3856
|
],
|
|
3838
3857
|
});
|
|
3839
3858
|
if (options.updateMessageId) {
|
|
@@ -3892,6 +3911,28 @@ export class ProxySessionController {
|
|
|
3892
3911
|
if (!stats.isDirectory())
|
|
3893
3912
|
throw new Error(`这不是目录:${directory}`);
|
|
3894
3913
|
}
|
|
3914
|
+
async createDirectoryFromCard(contextKey, action) {
|
|
3915
|
+
const directory = directoryActionPath(action.value.directory);
|
|
3916
|
+
await this.assertBrowsableDirectory(directory);
|
|
3917
|
+
const folderName = directoryFolderName(cardFormValue(action.value, "folderName"));
|
|
3918
|
+
const newDirectory = path.join(directory, folderName);
|
|
3919
|
+
try {
|
|
3920
|
+
await fs.mkdir(newDirectory);
|
|
3921
|
+
}
|
|
3922
|
+
catch (error) {
|
|
3923
|
+
const code = typeof error === "object" && error !== null && "code" in error
|
|
3924
|
+
? String(error.code)
|
|
3925
|
+
: undefined;
|
|
3926
|
+
if (code === "EEXIST")
|
|
3927
|
+
throw new Error(`目录已存在:${newDirectory}`);
|
|
3928
|
+
throw new Error(`无法创建目录 ${newDirectory}:${runtimeErrorMessage(error)}`);
|
|
3929
|
+
}
|
|
3930
|
+
await this.openDirectoryBrowser(contextKey, directory, {
|
|
3931
|
+
updateMessageId: requiredCardMessageId(action.messageId),
|
|
3932
|
+
page: directoryPageValue(action.value.page),
|
|
3933
|
+
});
|
|
3934
|
+
await this.outbound.sendText(contextKey, `已创建目录:${newDirectory}`);
|
|
3935
|
+
}
|
|
3895
3936
|
async assertSendableFile(filePath) {
|
|
3896
3937
|
let stats;
|
|
3897
3938
|
try {
|
|
@@ -5242,10 +5283,43 @@ function directoryFileActionPath(value) {
|
|
|
5242
5283
|
}
|
|
5243
5284
|
return path.resolve(value);
|
|
5244
5285
|
}
|
|
5245
|
-
function
|
|
5286
|
+
function cardFormValue(value, name) {
|
|
5287
|
+
const formValue = value.formValue;
|
|
5288
|
+
return typeof formValue === "object" && formValue !== null
|
|
5289
|
+
? formValue[name]
|
|
5290
|
+
: undefined;
|
|
5291
|
+
}
|
|
5292
|
+
function directoryFolderName(value) {
|
|
5293
|
+
if (typeof value !== "string" || !value.trim())
|
|
5294
|
+
throw new Error("请输入目录名。");
|
|
5295
|
+
const name = value.trim();
|
|
5296
|
+
if (name === "." || name === "..")
|
|
5297
|
+
throw new Error("目录名不能是 . 或 ..。");
|
|
5298
|
+
if (name.length > 255)
|
|
5299
|
+
throw new Error("目录名不能超过 255 个字符。");
|
|
5300
|
+
if (/[<>:"/\\|?*\u0000-\u001F]/u.test(name)) {
|
|
5301
|
+
throw new Error("目录名不能包含路径分隔符或以下字符:< > : \" / \\ | ? *");
|
|
5302
|
+
}
|
|
5303
|
+
if (/[. ]$/u.test(name))
|
|
5304
|
+
throw new Error("目录名不能以空格或句点结尾。");
|
|
5305
|
+
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/iu.test(name)) {
|
|
5306
|
+
throw new Error("该名称是系统保留名称,请使用其他目录名。");
|
|
5307
|
+
}
|
|
5308
|
+
return name;
|
|
5309
|
+
}
|
|
5310
|
+
function directoryCreationActions(directory, contextKey, page) {
|
|
5246
5311
|
return [
|
|
5247
5312
|
{
|
|
5248
|
-
text: "
|
|
5313
|
+
text: "NewFolder",
|
|
5314
|
+
value: {
|
|
5315
|
+
action: "directory_new_folder_prompt",
|
|
5316
|
+
directory,
|
|
5317
|
+
contextKey,
|
|
5318
|
+
page: String(page),
|
|
5319
|
+
},
|
|
5320
|
+
},
|
|
5321
|
+
{
|
|
5322
|
+
text: "NewTask",
|
|
5249
5323
|
value: {
|
|
5250
5324
|
action: "directory_new",
|
|
5251
5325
|
directory,
|
|
@@ -5253,7 +5327,7 @@ function directoryCreationActions(directory, contextKey) {
|
|
|
5253
5327
|
},
|
|
5254
5328
|
},
|
|
5255
5329
|
{
|
|
5256
|
-
text: "
|
|
5330
|
+
text: "NewGroupTask",
|
|
5257
5331
|
value: {
|
|
5258
5332
|
action: "directory_new_group",
|
|
5259
5333
|
directory,
|