@huyooo/ai-chat-core 0.2.10 → 0.2.12
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/dist/index.d.ts +7 -11
- package/dist/index.js +79 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1353,32 +1353,28 @@ declare function analyzeVideoTool(): ToolPlugin;
|
|
|
1353
1353
|
|
|
1354
1354
|
declare function getWeatherTool(): ToolPlugin;
|
|
1355
1355
|
|
|
1356
|
-
/**
|
|
1357
|
-
* UI 动作工具(Vite 插件风格)
|
|
1358
|
-
*
|
|
1359
|
-
* 将前端 UI 事件封装成 AI 可调用的工具
|
|
1360
|
-
* 前端通过监听 onToolComplete 的 sideEffects 来执行相应的 UI 操作
|
|
1361
|
-
*/
|
|
1362
|
-
|
|
1363
1356
|
/**
|
|
1364
1357
|
* 显示 Toast 通知
|
|
1365
1358
|
*/
|
|
1366
1359
|
declare function showToastTool(): ToolPlugin;
|
|
1360
|
+
|
|
1367
1361
|
/**
|
|
1368
1362
|
* 打开确认对话框
|
|
1369
1363
|
*/
|
|
1370
1364
|
declare function openConfirmDialogTool(): ToolPlugin;
|
|
1365
|
+
|
|
1371
1366
|
/**
|
|
1372
|
-
*
|
|
1367
|
+
* 打开文件预览(由宿主 UI 消费 ui:file_preview 副作用实现)
|
|
1373
1368
|
*/
|
|
1374
1369
|
declare function openFilePreviewTool(): ToolPlugin;
|
|
1370
|
+
|
|
1375
1371
|
/**
|
|
1376
|
-
*
|
|
1372
|
+
* 跳转到指定目录(由宿主 UI 消费 ui:navigate 副作用实现)
|
|
1377
1373
|
*/
|
|
1378
1374
|
declare function navigateToDirectoryTool(): ToolPlugin;
|
|
1375
|
+
|
|
1379
1376
|
/**
|
|
1380
|
-
*
|
|
1381
|
-
* @deprecated 使用 showToastTool() 等函数形式
|
|
1377
|
+
* UI 动作工具集合(用于快速注入)
|
|
1382
1378
|
*/
|
|
1383
1379
|
declare const uiActionTools: ToolPlugin[];
|
|
1384
1380
|
|
package/dist/index.js
CHANGED
|
@@ -2620,7 +2620,11 @@ function getWeatherTool() {
|
|
|
2620
2620
|
});
|
|
2621
2621
|
}
|
|
2622
2622
|
|
|
2623
|
-
// src/builtin-tools/ui-actions.ts
|
|
2623
|
+
// src/builtin-tools/ui-actions/show-toast.ts
|
|
2624
|
+
function getStringArg(args, key) {
|
|
2625
|
+
const value = args[key];
|
|
2626
|
+
return typeof value === "string" ? value : null;
|
|
2627
|
+
}
|
|
2624
2628
|
function showToastTool() {
|
|
2625
2629
|
return tool({
|
|
2626
2630
|
name: "show_toast",
|
|
@@ -2633,7 +2637,8 @@ function showToastTool() {
|
|
|
2633
2637
|
required: ["message"]
|
|
2634
2638
|
},
|
|
2635
2639
|
execute: async (args) => {
|
|
2636
|
-
const message = args
|
|
2640
|
+
const message = getStringArg(args, "message");
|
|
2641
|
+
if (!message) throw new Error("\u53C2\u6570\u9519\u8BEF\uFF1Amessage \u5FC5\u987B\u662F string");
|
|
2637
2642
|
return {
|
|
2638
2643
|
result: JSON.stringify({ success: true }),
|
|
2639
2644
|
sideEffects: [{ type: "notification", success: true, message }]
|
|
@@ -2641,6 +2646,12 @@ function showToastTool() {
|
|
|
2641
2646
|
}
|
|
2642
2647
|
});
|
|
2643
2648
|
}
|
|
2649
|
+
|
|
2650
|
+
// src/builtin-tools/ui-actions/open-confirm-dialog.ts
|
|
2651
|
+
function getStringArg2(args, key) {
|
|
2652
|
+
const value = args[key];
|
|
2653
|
+
return typeof value === "string" ? value : null;
|
|
2654
|
+
}
|
|
2644
2655
|
function openConfirmDialogTool() {
|
|
2645
2656
|
return tool({
|
|
2646
2657
|
name: "open_confirm_dialog",
|
|
@@ -2656,45 +2667,81 @@ function openConfirmDialogTool() {
|
|
|
2656
2667
|
required: ["title", "message"]
|
|
2657
2668
|
},
|
|
2658
2669
|
execute: async (args) => {
|
|
2670
|
+
const title = getStringArg2(args, "title");
|
|
2671
|
+
const message = getStringArg2(args, "message");
|
|
2672
|
+
if (!title) throw new Error("\u53C2\u6570\u9519\u8BEF\uFF1Atitle \u5FC5\u987B\u662F string");
|
|
2673
|
+
if (!message) throw new Error("\u53C2\u6570\u9519\u8BEF\uFF1Amessage \u5FC5\u987B\u662F string");
|
|
2674
|
+
const confirmText = getStringArg2(args, "confirmText") ?? "\u786E\u8BA4";
|
|
2675
|
+
const cancelText = getStringArg2(args, "cancelText") ?? "\u53D6\u6D88";
|
|
2659
2676
|
return {
|
|
2660
2677
|
result: JSON.stringify({ success: true }),
|
|
2661
|
-
sideEffects: [
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2678
|
+
sideEffects: [
|
|
2679
|
+
{
|
|
2680
|
+
type: "ui:confirm_dialog",
|
|
2681
|
+
success: true,
|
|
2682
|
+
data: {
|
|
2683
|
+
title,
|
|
2684
|
+
message,
|
|
2685
|
+
confirmText,
|
|
2686
|
+
cancelText
|
|
2687
|
+
}
|
|
2669
2688
|
}
|
|
2670
|
-
|
|
2689
|
+
]
|
|
2671
2690
|
};
|
|
2672
2691
|
}
|
|
2673
2692
|
});
|
|
2674
2693
|
}
|
|
2694
|
+
|
|
2695
|
+
// src/builtin-tools/ui-actions/open-file-preview.ts
|
|
2696
|
+
function getStringArg3(args, key) {
|
|
2697
|
+
const value = args[key];
|
|
2698
|
+
return typeof value === "string" ? value : null;
|
|
2699
|
+
}
|
|
2700
|
+
function getMediaTypeArg(args, key) {
|
|
2701
|
+
const value = args[key];
|
|
2702
|
+
if (value === "image" || value === "video" || value === "audio") return value;
|
|
2703
|
+
return null;
|
|
2704
|
+
}
|
|
2675
2705
|
function openFilePreviewTool() {
|
|
2676
2706
|
return tool({
|
|
2677
2707
|
name: "open_file_preview",
|
|
2678
|
-
description: "\u5728\u7528\u6237\u754C\u9762\u4E0A\u6253\u5F00\u6587\u4EF6\u9884\u89C8\u7A97\u53E3\uFF0C\u8BA9\u7528\u6237\u67E5\u770B\u6307\u5B9A\u6587\u4EF6\u7684\u5185\u5BB9\
|
|
2708
|
+
description: "\u5728\u7528\u6237\u754C\u9762\u4E0A\u6253\u5F00\u6587\u4EF6\u9884\u89C8\u7A97\u53E3\uFF0C\u8BA9\u7528\u6237\u67E5\u770B\u6307\u5B9A\u6587\u4EF6\u7684\u5185\u5BB9\uFF08\u5BBF\u4E3B\u9700\u5904\u7406 ui:file_preview sideEffect\uFF09\u3002",
|
|
2679
2709
|
parameters: {
|
|
2680
2710
|
type: "object",
|
|
2681
2711
|
properties: {
|
|
2682
|
-
path: { type: "string", description: "\u8981\u9884\u89C8\u7684\u6587\u4EF6\u7684\u5B8C\u6574\u8DEF\u5F84" }
|
|
2712
|
+
path: { type: "string", description: "\u8981\u9884\u89C8\u7684\u6587\u4EF6\u7684\u5B8C\u6574\u8DEF\u5F84" },
|
|
2713
|
+
mediaType: {
|
|
2714
|
+
type: "string",
|
|
2715
|
+
description: "\u9884\u89C8\u7C7B\u578B\uFF08\u5FC5\u586B\uFF09\uFF1Aimage/video/audio\u3002\u5BBF\u4E3B\u4E0D\u4F1A\u518D\u6839\u636E\u540E\u7F00\u63A8\u65AD\u3002",
|
|
2716
|
+
enum: ["image", "video", "audio"]
|
|
2717
|
+
}
|
|
2683
2718
|
},
|
|
2684
|
-
required: ["path"]
|
|
2719
|
+
required: ["path", "mediaType"]
|
|
2685
2720
|
},
|
|
2686
2721
|
execute: async (args) => {
|
|
2722
|
+
const path = getStringArg3(args, "path");
|
|
2723
|
+
if (!path) throw new Error("\u53C2\u6570\u9519\u8BEF\uFF1Apath \u5FC5\u987B\u662F string");
|
|
2724
|
+
const mediaTypeValue = getMediaTypeArg(args, "mediaType");
|
|
2725
|
+
if (!mediaTypeValue) throw new Error('\u53C2\u6570\u9519\u8BEF\uFF1AmediaType \u5FC5\u987B\u662F "image" | "video" | "audio"');
|
|
2687
2726
|
return {
|
|
2688
|
-
result: JSON.stringify({ success: true, path:
|
|
2689
|
-
sideEffects: [
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2727
|
+
result: JSON.stringify({ success: true, path, mediaType: mediaTypeValue }),
|
|
2728
|
+
sideEffects: [
|
|
2729
|
+
{
|
|
2730
|
+
type: "ui:file_preview",
|
|
2731
|
+
success: true,
|
|
2732
|
+
data: { path, mediaType: mediaTypeValue }
|
|
2733
|
+
}
|
|
2734
|
+
]
|
|
2694
2735
|
};
|
|
2695
2736
|
}
|
|
2696
2737
|
});
|
|
2697
2738
|
}
|
|
2739
|
+
|
|
2740
|
+
// src/builtin-tools/ui-actions/navigate-to-directory.ts
|
|
2741
|
+
function getStringArg4(args, key) {
|
|
2742
|
+
const value = args[key];
|
|
2743
|
+
return typeof value === "string" ? value : null;
|
|
2744
|
+
}
|
|
2698
2745
|
function navigateToDirectoryTool() {
|
|
2699
2746
|
return tool({
|
|
2700
2747
|
name: "navigate_to_directory",
|
|
@@ -2707,17 +2754,23 @@ function navigateToDirectoryTool() {
|
|
|
2707
2754
|
required: ["path"]
|
|
2708
2755
|
},
|
|
2709
2756
|
execute: async (args) => {
|
|
2757
|
+
const path = getStringArg4(args, "path");
|
|
2758
|
+
if (!path) throw new Error("\u53C2\u6570\u9519\u8BEF\uFF1Apath \u5FC5\u987B\u662F string");
|
|
2710
2759
|
return {
|
|
2711
|
-
result: JSON.stringify({ success: true, path
|
|
2712
|
-
sideEffects: [
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2760
|
+
result: JSON.stringify({ success: true, path }),
|
|
2761
|
+
sideEffects: [
|
|
2762
|
+
{
|
|
2763
|
+
type: "ui:navigate",
|
|
2764
|
+
success: true,
|
|
2765
|
+
data: { path }
|
|
2766
|
+
}
|
|
2767
|
+
]
|
|
2717
2768
|
};
|
|
2718
2769
|
}
|
|
2719
2770
|
});
|
|
2720
2771
|
}
|
|
2772
|
+
|
|
2773
|
+
// src/builtin-tools/ui-actions/index.ts
|
|
2721
2774
|
var uiActionTools = [
|
|
2722
2775
|
showToastTool(),
|
|
2723
2776
|
openConfirmDialogTool(),
|