wps-multitool-mcp 0.0.0-stage → 1.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/README.md +3 -3
- package/dist/bridge/cancellable.d.ts +36 -0
- package/dist/bridge/cancellable.d.ts.map +1 -0
- package/dist/bridge/cancellable.js +155 -0
- package/dist/bridge/cancellable.js.map +1 -0
- package/dist/bridge/index.d.ts +37 -0
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/index.js +383 -0
- package/dist/bridge/index.js.map +1 -0
- package/dist/bridge/ps-child.d.ts +155 -0
- package/dist/bridge/ps-child.d.ts.map +1 -0
- package/dist/bridge/ps-child.js +578 -0
- package/dist/bridge/ps-child.js.map +1 -0
- package/dist/cli/install.d.ts +58 -0
- package/dist/cli/install.d.ts.map +1 -0
- package/dist/cli/install.js +301 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/client/action-routes.d.ts +32 -0
- package/dist/client/action-routes.d.ts.map +1 -0
- package/dist/client/action-routes.generated.d.ts +10 -0
- package/dist/client/action-routes.generated.d.ts.map +1 -0
- package/dist/client/action-routes.generated.js +327 -0
- package/dist/client/action-routes.generated.js.map +1 -0
- package/dist/client/action-routes.js +57 -0
- package/dist/client/action-routes.js.map +1 -0
- package/dist/client/ps-daemon.d.ts +95 -0
- package/dist/client/ps-daemon.d.ts.map +1 -0
- package/dist/client/ps-daemon.js +424 -0
- package/dist/client/ps-daemon.js.map +1 -0
- package/dist/client/wps-client.d.ts +69 -0
- package/dist/client/wps-client.d.ts.map +1 -0
- package/dist/client/wps-client.js +442 -0
- package/dist/client/wps-client.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +173 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-identity.d.ts +23 -0
- package/dist/runtime-identity.d.ts.map +1 -0
- package/dist/runtime-identity.js +26 -0
- package/dist/runtime-identity.js.map +1 -0
- package/dist/server/auto-snapshot.d.ts +58 -0
- package/dist/server/auto-snapshot.d.ts.map +1 -0
- package/dist/server/auto-snapshot.js +150 -0
- package/dist/server/auto-snapshot.js.map +1 -0
- package/dist/server/cancel-context.d.ts +30 -0
- package/dist/server/cancel-context.d.ts.map +1 -0
- package/dist/server/cancel-context.js +38 -0
- package/dist/server/cancel-context.js.map +1 -0
- package/dist/server/mcp-server.d.ts +74 -0
- package/dist/server/mcp-server.d.ts.map +1 -0
- package/dist/server/mcp-server.js +592 -0
- package/dist/server/mcp-server.js.map +1 -0
- package/dist/server/server-info.d.ts +21 -0
- package/dist/server/server-info.d.ts.map +1 -0
- package/dist/server/server-info.js +56 -0
- package/dist/server/server-info.js.map +1 -0
- package/dist/server/tool-aliases.generated.d.ts +41 -0
- package/dist/server/tool-aliases.generated.d.ts.map +1 -0
- package/dist/server/tool-aliases.generated.js +88 -0
- package/dist/server/tool-aliases.generated.js.map +1 -0
- package/dist/server/tool-annotations.d.ts +55 -0
- package/dist/server/tool-annotations.d.ts.map +1 -0
- package/dist/server/tool-annotations.generated.d.ts +14 -0
- package/dist/server/tool-annotations.generated.d.ts.map +1 -0
- package/dist/server/tool-annotations.generated.js +302 -0
- package/dist/server/tool-annotations.generated.js.map +1 -0
- package/dist/server/tool-annotations.js +192 -0
- package/dist/server/tool-annotations.js.map +1 -0
- package/dist/server/tool-group-events.d.ts +23 -0
- package/dist/server/tool-group-events.d.ts.map +1 -0
- package/dist/server/tool-group-events.js +44 -0
- package/dist/server/tool-group-events.js.map +1 -0
- package/dist/server/tool-metadata.d.ts +68 -0
- package/dist/server/tool-metadata.d.ts.map +1 -0
- package/dist/server/tool-metadata.js +834 -0
- package/dist/server/tool-metadata.js.map +1 -0
- package/dist/server/tool-registry.d.ts +186 -0
- package/dist/server/tool-registry.d.ts.map +1 -0
- package/dist/server/tool-registry.js +615 -0
- package/dist/server/tool-registry.js.map +1 -0
- package/dist/server/tool-tiers.d.ts +58 -0
- package/dist/server/tool-tiers.d.ts.map +1 -0
- package/dist/server/tool-tiers.js +128 -0
- package/dist/server/tool-tiers.js.map +1 -0
- package/dist/server/tool-verification.d.ts +35 -0
- package/dist/server/tool-verification.d.ts.map +1 -0
- package/dist/server/tool-verification.generated.d.ts +17 -0
- package/dist/server/tool-verification.generated.d.ts.map +1 -0
- package/dist/server/tool-verification.generated.js +293 -0
- package/dist/server/tool-verification.generated.js.map +1 -0
- package/dist/server/tool-verification.js +43 -0
- package/dist/server/tool-verification.js.map +1 -0
- package/dist/tools/common/batch.d.ts +33 -0
- package/dist/tools/common/batch.d.ts.map +1 -0
- package/dist/tools/common/batch.js +273 -0
- package/dist/tools/common/batch.js.map +1 -0
- package/dist/tools/common/convert.d.ts +41 -0
- package/dist/tools/common/convert.d.ts.map +1 -0
- package/dist/tools/common/convert.js +299 -0
- package/dist/tools/common/convert.js.map +1 -0
- package/dist/tools/common/general.d.ts +36 -0
- package/dist/tools/common/general.d.ts.map +1 -0
- package/dist/tools/common/general.js +582 -0
- package/dist/tools/common/general.js.map +1 -0
- package/dist/tools/common/index.d.ts +38 -0
- package/dist/tools/common/index.d.ts.map +1 -0
- package/dist/tools/common/index.js +116 -0
- package/dist/tools/common/index.js.map +1 -0
- package/dist/tools/common/intent.d.ts +48 -0
- package/dist/tools/common/intent.d.ts.map +1 -0
- package/dist/tools/common/intent.js +221 -0
- package/dist/tools/common/intent.js.map +1 -0
- package/dist/tools/common/repair.d.ts +29 -0
- package/dist/tools/common/repair.d.ts.map +1 -0
- package/dist/tools/common/repair.js +140 -0
- package/dist/tools/common/repair.js.map +1 -0
- package/dist/tools/common/snapshot.d.ts +77 -0
- package/dist/tools/common/snapshot.d.ts.map +1 -0
- package/dist/tools/common/snapshot.js +497 -0
- package/dist/tools/common/snapshot.js.map +1 -0
- package/dist/tools/common/status.d.ts +27 -0
- package/dist/tools/common/status.d.ts.map +1 -0
- package/dist/tools/common/status.js +139 -0
- package/dist/tools/common/status.js.map +1 -0
- package/dist/tools/common/toolgroups.d.ts +38 -0
- package/dist/tools/common/toolgroups.d.ts.map +1 -0
- package/dist/tools/common/toolgroups.js +254 -0
- package/dist/tools/common/toolgroups.js.map +1 -0
- package/dist/tools/excel/chart.d.ts +86 -0
- package/dist/tools/excel/chart.d.ts.map +1 -0
- package/dist/tools/excel/chart.js +659 -0
- package/dist/tools/excel/chart.js.map +1 -0
- package/dist/tools/excel/comment-protect.d.ts +58 -0
- package/dist/tools/excel/comment-protect.d.ts.map +1 -0
- package/dist/tools/excel/comment-protect.js +274 -0
- package/dist/tools/excel/comment-protect.js.map +1 -0
- package/dist/tools/excel/data-advanced.d.ts +47 -0
- package/dist/tools/excel/data-advanced.d.ts.map +1 -0
- package/dist/tools/excel/data-advanced.js +263 -0
- package/dist/tools/excel/data-advanced.js.map +1 -0
- package/dist/tools/excel/data.d.ts +86 -0
- package/dist/tools/excel/data.d.ts.map +1 -0
- package/dist/tools/excel/data.js +606 -0
- package/dist/tools/excel/data.js.map +1 -0
- package/dist/tools/excel/format.d.ts +42 -0
- package/dist/tools/excel/format.d.ts.map +1 -0
- package/dist/tools/excel/format.js +717 -0
- package/dist/tools/excel/format.js.map +1 -0
- package/dist/tools/excel/formula.d.ts +55 -0
- package/dist/tools/excel/formula.d.ts.map +1 -0
- package/dist/tools/excel/formula.js +316 -0
- package/dist/tools/excel/formula.js.map +1 -0
- package/dist/tools/excel/index.d.ts +44 -0
- package/dist/tools/excel/index.d.ts.map +1 -0
- package/dist/tools/excel/index.js +241 -0
- package/dist/tools/excel/index.js.map +1 -0
- package/dist/tools/excel/pivot.d.ts +39 -0
- package/dist/tools/excel/pivot.d.ts.map +1 -0
- package/dist/tools/excel/pivot.js +455 -0
- package/dist/tools/excel/pivot.js.map +1 -0
- package/dist/tools/excel/row-column.d.ts +64 -0
- package/dist/tools/excel/row-column.d.ts.map +1 -0
- package/dist/tools/excel/row-column.js +299 -0
- package/dist/tools/excel/row-column.js.map +1 -0
- package/dist/tools/excel/sheet-gaps.d.ts +50 -0
- package/dist/tools/excel/sheet-gaps.d.ts.map +1 -0
- package/dist/tools/excel/sheet-gaps.js +373 -0
- package/dist/tools/excel/sheet-gaps.js.map +1 -0
- package/dist/tools/excel/sheet.d.ts +102 -0
- package/dist/tools/excel/sheet.d.ts.map +1 -0
- package/dist/tools/excel/sheet.js +827 -0
- package/dist/tools/excel/sheet.js.map +1 -0
- package/dist/tools/excel/workbook.d.ts +62 -0
- package/dist/tools/excel/workbook.d.ts.map +1 -0
- package/dist/tools/excel/workbook.js +371 -0
- package/dist/tools/excel/workbook.js.map +1 -0
- package/dist/tools/index.d.ts +48 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +113 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/ppt/animation.d.ts +36 -0
- package/dist/tools/ppt/animation.d.ts.map +1 -0
- package/dist/tools/ppt/animation.js +190 -0
- package/dist/tools/ppt/animation.js.map +1 -0
- package/dist/tools/ppt/background.d.ts +54 -0
- package/dist/tools/ppt/background.d.ts.map +1 -0
- package/dist/tools/ppt/background.js +389 -0
- package/dist/tools/ppt/background.js.map +1 -0
- package/dist/tools/ppt/beautify-advanced.d.ts +66 -0
- package/dist/tools/ppt/beautify-advanced.d.ts.map +1 -0
- package/dist/tools/ppt/beautify-advanced.js +600 -0
- package/dist/tools/ppt/beautify-advanced.js.map +1 -0
- package/dist/tools/ppt/chart-flow.d.ts +58 -0
- package/dist/tools/ppt/chart-flow.d.ts.map +1 -0
- package/dist/tools/ppt/chart-flow.js +523 -0
- package/dist/tools/ppt/chart-flow.js.map +1 -0
- package/dist/tools/ppt/data-viz.d.ts +64 -0
- package/dist/tools/ppt/data-viz.d.ts.map +1 -0
- package/dist/tools/ppt/data-viz.js +514 -0
- package/dist/tools/ppt/data-viz.js.map +1 -0
- package/dist/tools/ppt/image.d.ts +30 -0
- package/dist/tools/ppt/image.d.ts.map +1 -0
- package/dist/tools/ppt/image.js +447 -0
- package/dist/tools/ppt/image.js.map +1 -0
- package/dist/tools/ppt/index.d.ts +72 -0
- package/dist/tools/ppt/index.d.ts.map +1 -0
- package/dist/tools/ppt/index.js +320 -0
- package/dist/tools/ppt/index.js.map +1 -0
- package/dist/tools/ppt/misc.d.ts +93 -0
- package/dist/tools/ppt/misc.d.ts.map +1 -0
- package/dist/tools/ppt/misc.js +817 -0
- package/dist/tools/ppt/misc.js.map +1 -0
- package/dist/tools/ppt/presentation.d.ts +72 -0
- package/dist/tools/ppt/presentation.d.ts.map +1 -0
- package/dist/tools/ppt/presentation.js +694 -0
- package/dist/tools/ppt/presentation.js.map +1 -0
- package/dist/tools/ppt/shape-basic.d.ts +46 -0
- package/dist/tools/ppt/shape-basic.d.ts.map +1 -0
- package/dist/tools/ppt/shape-basic.js +756 -0
- package/dist/tools/ppt/shape-basic.js.map +1 -0
- package/dist/tools/ppt/slide-ops.d.ts +73 -0
- package/dist/tools/ppt/slide-ops.d.ts.map +1 -0
- package/dist/tools/ppt/slide-ops.js +1740 -0
- package/dist/tools/ppt/slide-ops.js.map +1 -0
- package/dist/tools/ppt/slide.d.ts +51 -0
- package/dist/tools/ppt/slide.d.ts.map +1 -0
- package/dist/tools/ppt/slide.js +484 -0
- package/dist/tools/ppt/slide.js.map +1 -0
- package/dist/tools/ppt/table.d.ts +58 -0
- package/dist/tools/ppt/table.d.ts.map +1 -0
- package/dist/tools/ppt/table.js +514 -0
- package/dist/tools/ppt/table.js.map +1 -0
- package/dist/tools/ppt/textbox.d.ts +47 -0
- package/dist/tools/ppt/textbox.d.ts.map +1 -0
- package/dist/tools/ppt/textbox.js +249 -0
- package/dist/tools/ppt/textbox.js.map +1 -0
- package/dist/tools/word/academic.d.ts +50 -0
- package/dist/tools/word/academic.d.ts.map +1 -0
- package/dist/tools/word/academic.js +500 -0
- package/dist/tools/word/academic.js.map +1 -0
- package/dist/tools/word/content.d.ts +97 -0
- package/dist/tools/word/content.d.ts.map +1 -0
- package/dist/tools/word/content.js +843 -0
- package/dist/tools/word/content.js.map +1 -0
- package/dist/tools/word/document.d.ts +65 -0
- package/dist/tools/word/document.d.ts.map +1 -0
- package/dist/tools/word/document.js +576 -0
- package/dist/tools/word/document.js.map +1 -0
- package/dist/tools/word/format.d.ts +50 -0
- package/dist/tools/word/format.d.ts.map +1 -0
- package/dist/tools/word/format.js +462 -0
- package/dist/tools/word/format.js.map +1 -0
- package/dist/tools/word/gaps.d.ts +58 -0
- package/dist/tools/word/gaps.d.ts.map +1 -0
- package/dist/tools/word/gaps.js +431 -0
- package/dist/tools/word/gaps.js.map +1 -0
- package/dist/tools/word/index.d.ts +34 -0
- package/dist/tools/word/index.d.ts.map +1 -0
- package/dist/tools/word/index.js +122 -0
- package/dist/tools/word/index.js.map +1 -0
- package/dist/tools/word/professional.d.ts +48 -0
- package/dist/tools/word/professional.d.ts.map +1 -0
- package/dist/tools/word/professional.js +657 -0
- package/dist/tools/word/professional.js.map +1 -0
- package/dist/tools/word/proofread.d.ts +25 -0
- package/dist/tools/word/proofread.d.ts.map +1 -0
- package/dist/tools/word/proofread.js +718 -0
- package/dist/tools/word/proofread.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +25 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/tools.d.ts +174 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +45 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/wps.d.ts +190 -0
- package/dist/types/wps.d.ts.map +1 -0
- package/dist/types/wps.js +23 -0
- package/dist/types/wps.js.map +1 -0
- package/dist/utils/error.d.ts +147 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +417 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/logger.d.ts +56 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +155 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/version.d.ts +22 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +101 -0
- package/dist/version.js.map +1 -0
- package/package.json +66 -6
- package/scripts/wps-com.ps1 +8255 -0
- package/scripts/wps-comd.ps1 +123 -0
- package/skills/wps-multitool/SKILL.md +129 -0
- package/skills/wps-multitool/references/errors.md +62 -0
- package/skills/wps-multitool/references/recipes.md +83 -0
- package/skills/wps-multitool/references/routing.md +88 -0
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Input: Word 内容操作参数
|
|
4
|
+
* Output: 文档内容变更结果
|
|
5
|
+
* Pos: Word 内容工具实现。一旦我被修改,请更新我的头部注释,以及所属文件夹的md。
|
|
6
|
+
* Word内容操作Tools - 文档内容编辑模块
|
|
7
|
+
* 处理文档内容的插入、查找替换、表格、段落格式、页眉页脚等操作
|
|
8
|
+
*
|
|
9
|
+
* 包含:
|
|
10
|
+
* - wps_word_insert_text: 插入文本到文档
|
|
11
|
+
* - wps_word_find_replace: 查找替换功能
|
|
12
|
+
* - wps_word_insert_table: 插入表格
|
|
13
|
+
* - wps_word_set_paragraph: 设置段落格式
|
|
14
|
+
* - wps_word_insert_header: 插入页眉
|
|
15
|
+
* - wps_word_insert_footer: 插入页脚
|
|
16
|
+
* - wps_word_get_active_document: 获取当前文档信息
|
|
17
|
+
* - wps_word_insert_page_break: 插入分页符
|
|
18
|
+
* - wps_word_insert_comment: 插入批注
|
|
19
|
+
* - wps_word_set_font_style: 设置选中文字的字体样式属性
|
|
20
|
+
* - wps_word_set_text_color: 设置文字颜色
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.contentTools = exports.replaceBookmarkContentHandler = exports.replaceBookmarkContentDefinition = exports.smartFillFieldHandler = exports.smartFillFieldDefinition = exports.findInDocumentHandler = exports.findInDocumentDefinition = exports.getParagraphsHandler = exports.getParagraphsDefinition = exports.setTextColorHandler = exports.setTextColorDefinition = exports.insertCommentHandler = exports.insertCommentDefinition = exports.setFontStyleHandler = exports.setFontStyleDefinition = exports.insertPageBreakHandler = exports.insertPageBreakDefinition = exports.insertImageHandler = exports.insertImageDefinition = exports.getActiveDocumentHandler = exports.getActiveDocumentDefinition = exports.setParagraphHandler = exports.setParagraphDefinition = exports.insertTableHandler = exports.insertTableDefinition = exports.findReplaceHandler = exports.findReplaceDefinition = exports.insertTextHandler = exports.insertTextDefinition = void 0;
|
|
24
|
+
const uuid_1 = require("uuid");
|
|
25
|
+
const tools_1 = require("../../types/tools");
|
|
26
|
+
const wps_client_1 = require("../../client/wps-client");
|
|
27
|
+
const wps_1 = require("../../types/wps");
|
|
28
|
+
/**
|
|
29
|
+
* 插入文本到文档
|
|
30
|
+
* 可以在光标位置、文档开头或结尾插入文本
|
|
31
|
+
*/
|
|
32
|
+
exports.insertTextDefinition = {
|
|
33
|
+
name: 'wps_word_insert_text',
|
|
34
|
+
description: `在Word文档中插入文本。
|
|
35
|
+
|
|
36
|
+
使用场景:
|
|
37
|
+
- "在文档开头加个标题"
|
|
38
|
+
- "在光标位置插入这段话"
|
|
39
|
+
- "在文档末尾添加备注"`,
|
|
40
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
41
|
+
inputSchema: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
text: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
description: '要插入的文本内容',
|
|
47
|
+
},
|
|
48
|
+
position: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: '插入位置,可选值: "cursor"(光标位置), "start"(文档开头), "end"(文档结尾)。默认cursor',
|
|
51
|
+
enum: ['cursor', 'start', 'end'],
|
|
52
|
+
},
|
|
53
|
+
style: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: '插入后应用的样式,如 "标题 1"、"正文"',
|
|
56
|
+
},
|
|
57
|
+
new_paragraph: {
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
description: '插入后是否新起一段,默认false',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
required: ['text'],
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
const insertTextHandler = async (args) => {
|
|
66
|
+
const { text, position, style, new_paragraph } = args;
|
|
67
|
+
if (!text || text.trim() === '') {
|
|
68
|
+
return {
|
|
69
|
+
id: (0, uuid_1.v4)(),
|
|
70
|
+
success: false,
|
|
71
|
+
content: [{ type: 'text', text: '要插入的文本不能为空!' }],
|
|
72
|
+
error: '文本内容为空',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
// 处理换行符,如果需要新段落
|
|
77
|
+
const finalText = new_paragraph ? text + '\n' : text;
|
|
78
|
+
const response = await wps_client_1.wpsClient.executeMethod('insertText', {
|
|
79
|
+
text: finalText,
|
|
80
|
+
position: position || 'cursor',
|
|
81
|
+
style,
|
|
82
|
+
}, wps_1.WpsAppType.WRITER);
|
|
83
|
+
if (response.success && response.data) {
|
|
84
|
+
const positionText = position === 'start' ? '文档开头' :
|
|
85
|
+
position === 'end' ? '文档结尾' : '光标位置';
|
|
86
|
+
return {
|
|
87
|
+
id: (0, uuid_1.v4)(),
|
|
88
|
+
success: true,
|
|
89
|
+
content: [
|
|
90
|
+
{
|
|
91
|
+
type: 'text',
|
|
92
|
+
text: `文本插入成功!\n位置: ${positionText}\n字符数: ${response.data.textLength}${style ? `\n应用样式: ${style}` : ''}`,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return {
|
|
99
|
+
id: (0, uuid_1.v4)(),
|
|
100
|
+
success: false,
|
|
101
|
+
content: [{ type: 'text', text: `插入文本失败: ${response.error}` }],
|
|
102
|
+
error: response.error,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
108
|
+
return {
|
|
109
|
+
id: (0, uuid_1.v4)(),
|
|
110
|
+
success: false,
|
|
111
|
+
content: [{ type: 'text', text: `插入文本出错: ${errMsg}` }],
|
|
112
|
+
error: errMsg,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
exports.insertTextHandler = insertTextHandler;
|
|
117
|
+
/**
|
|
118
|
+
* 查找替换功能
|
|
119
|
+
* 支持全文批量查找替换文本
|
|
120
|
+
*/
|
|
121
|
+
exports.findReplaceDefinition = {
|
|
122
|
+
name: 'wps_word_find_replace',
|
|
123
|
+
description: `在Word文档中查找并替换文本。
|
|
124
|
+
|
|
125
|
+
使用场景:
|
|
126
|
+
- "把所有的'公司'替换成'集团'"
|
|
127
|
+
- "把文档里的错别字改过来"
|
|
128
|
+
- "批量替换某个词"
|
|
129
|
+
|
|
130
|
+
支持选项:
|
|
131
|
+
- 区分大小写
|
|
132
|
+
- 全字匹配
|
|
133
|
+
- 全部替换或仅替换一处`,
|
|
134
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
135
|
+
inputSchema: {
|
|
136
|
+
type: 'object',
|
|
137
|
+
properties: {
|
|
138
|
+
find_text: {
|
|
139
|
+
type: 'string',
|
|
140
|
+
description: '要查找的文本',
|
|
141
|
+
},
|
|
142
|
+
replace_text: {
|
|
143
|
+
type: 'string',
|
|
144
|
+
description: '替换为的文本,如果只是查找不替换,可以不填',
|
|
145
|
+
},
|
|
146
|
+
replace_all: {
|
|
147
|
+
type: 'boolean',
|
|
148
|
+
description: '是否全部替换,默认true',
|
|
149
|
+
},
|
|
150
|
+
match_case: {
|
|
151
|
+
type: 'boolean',
|
|
152
|
+
description: '是否区分大小写,默认false',
|
|
153
|
+
},
|
|
154
|
+
match_whole_word: {
|
|
155
|
+
type: 'boolean',
|
|
156
|
+
description: '是否全字匹配,默认false',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
required: ['find_text'],
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
const findReplaceHandler = async (args) => {
|
|
163
|
+
const { find_text, replace_text, replace_all, match_case, match_whole_word } = args;
|
|
164
|
+
if (!find_text || find_text.trim() === '') {
|
|
165
|
+
return {
|
|
166
|
+
id: (0, uuid_1.v4)(),
|
|
167
|
+
success: false,
|
|
168
|
+
content: [{ type: 'text', text: '查找文本不能为空!' }],
|
|
169
|
+
error: '查找文本为空',
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
// 如果没有替换文本,就只是查找
|
|
174
|
+
const isReplaceMode = replace_text !== undefined && replace_text !== null;
|
|
175
|
+
const response = await wps_client_1.wpsClient.executeMethod('findReplace', {
|
|
176
|
+
findText: find_text,
|
|
177
|
+
replaceText: isReplaceMode ? replace_text : '',
|
|
178
|
+
replaceAll: replace_all !== false, // 默认true
|
|
179
|
+
matchCase: match_case || false,
|
|
180
|
+
matchWholeWord: match_whole_word || false,
|
|
181
|
+
replaceMode: isReplaceMode,
|
|
182
|
+
}, wps_1.WpsAppType.WRITER);
|
|
183
|
+
if (response.success && response.data) {
|
|
184
|
+
const result = response.data;
|
|
185
|
+
// PS 只回布尔(Find.Execute 的返回值),没有次数。
|
|
186
|
+
// 所以"替换了几处"改成如实说"是否替换成功"—— 宁可少说,不能编一个数字。
|
|
187
|
+
const didReplace = result.replaced === true;
|
|
188
|
+
if (isReplaceMode) {
|
|
189
|
+
if (!didReplace) {
|
|
190
|
+
return {
|
|
191
|
+
id: (0, uuid_1.v4)(),
|
|
192
|
+
success: true,
|
|
193
|
+
content: [
|
|
194
|
+
{
|
|
195
|
+
type: 'text',
|
|
196
|
+
text: `未找到 "${find_text}",没有进行替换`,
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
id: (0, uuid_1.v4)(),
|
|
203
|
+
success: true,
|
|
204
|
+
content: [
|
|
205
|
+
{
|
|
206
|
+
type: 'text',
|
|
207
|
+
text: `替换完成!\n查找: "${find_text}"\n替换为: "${replace_text}"\n(COM 只返回"是否替换成功",不返回次数)`,
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
return {
|
|
214
|
+
id: (0, uuid_1.v4)(),
|
|
215
|
+
success: true,
|
|
216
|
+
content: [
|
|
217
|
+
{
|
|
218
|
+
type: 'text',
|
|
219
|
+
text: `查找完成!\n"${find_text}" ${didReplace ? '存在并已执行替换' : '未找到可替换的内容'}`,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
return {
|
|
227
|
+
id: (0, uuid_1.v4)(),
|
|
228
|
+
success: false,
|
|
229
|
+
content: [{ type: 'text', text: `查找替换失败: ${response.error}` }],
|
|
230
|
+
error: response.error,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
236
|
+
return {
|
|
237
|
+
id: (0, uuid_1.v4)(),
|
|
238
|
+
success: false,
|
|
239
|
+
content: [{ type: 'text', text: `查找替换出错: ${errMsg}` }],
|
|
240
|
+
error: errMsg,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
exports.findReplaceHandler = findReplaceHandler;
|
|
245
|
+
/**
|
|
246
|
+
* 插入表格到文档光标位置
|
|
247
|
+
*/
|
|
248
|
+
exports.insertTableDefinition = {
|
|
249
|
+
name: 'wps_word_insert_table',
|
|
250
|
+
description: '在Word文档光标位置插入表格',
|
|
251
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
252
|
+
inputSchema: {
|
|
253
|
+
type: 'object',
|
|
254
|
+
properties: {
|
|
255
|
+
rows: { type: 'number', description: '表格行数' },
|
|
256
|
+
cols: { type: 'number', description: '表格列数' },
|
|
257
|
+
},
|
|
258
|
+
required: ['rows', 'cols'],
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
const insertTableHandler = async (args) => {
|
|
262
|
+
const { rows, cols } = args;
|
|
263
|
+
try {
|
|
264
|
+
const response = await wps_client_1.wpsClient.executeMethod('insertTable', { rows, cols }, wps_1.WpsAppType.WRITER);
|
|
265
|
+
if (response.success) {
|
|
266
|
+
return {
|
|
267
|
+
id: (0, uuid_1.v4)(),
|
|
268
|
+
success: true,
|
|
269
|
+
content: [{ type: 'text', text: `已插入 ${rows}×${cols} 表格` }],
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
id: (0, uuid_1.v4)(),
|
|
274
|
+
success: false,
|
|
275
|
+
content: [{ type: 'text', text: `插入表格失败: ${response.error}` }],
|
|
276
|
+
error: response.error,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
281
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `插入表格出错: ${errMsg}` }], error: errMsg };
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
exports.insertTableHandler = insertTableHandler;
|
|
285
|
+
/**
|
|
286
|
+
* 设置当前段落格式
|
|
287
|
+
*/
|
|
288
|
+
exports.setParagraphDefinition = {
|
|
289
|
+
name: 'wps_word_set_paragraph',
|
|
290
|
+
description: '设置当前段落格式(对齐方式、行间距等)',
|
|
291
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
292
|
+
inputSchema: {
|
|
293
|
+
type: 'object',
|
|
294
|
+
properties: {
|
|
295
|
+
alignment: { type: 'string', description: '对齐方式: left/center/right/justify' },
|
|
296
|
+
lineSpacing: { type: 'number', description: '行间距倍数,如1.5、2' },
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
const setParagraphHandler = async (args) => {
|
|
301
|
+
const params = args;
|
|
302
|
+
try {
|
|
303
|
+
const response = await wps_client_1.wpsClient.executeMethod('setParagraph', params, wps_1.WpsAppType.WRITER);
|
|
304
|
+
if (response.success) {
|
|
305
|
+
return {
|
|
306
|
+
id: (0, uuid_1.v4)(),
|
|
307
|
+
success: true,
|
|
308
|
+
content: [{ type: 'text', text: '段落格式已设置' }],
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
id: (0, uuid_1.v4)(),
|
|
313
|
+
success: false,
|
|
314
|
+
content: [{ type: 'text', text: `设置段落失败: ${response.error}` }],
|
|
315
|
+
error: response.error,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
320
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `设置段落出错: ${errMsg}` }], error: errMsg };
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
exports.setParagraphHandler = setParagraphHandler;
|
|
324
|
+
/**
|
|
325
|
+
* 获取当前活动文档信息
|
|
326
|
+
*/
|
|
327
|
+
exports.getActiveDocumentDefinition = {
|
|
328
|
+
name: 'wps_word_get_active_document',
|
|
329
|
+
description: '获取当前WPS Writer活动文档的基本信息',
|
|
330
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
331
|
+
inputSchema: {
|
|
332
|
+
type: 'object',
|
|
333
|
+
properties: {},
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
const getActiveDocumentHandler = async (_args) => {
|
|
337
|
+
try {
|
|
338
|
+
const response = await wps_client_1.wpsClient.executeMethod('getActiveDocument', {}, wps_1.WpsAppType.WRITER);
|
|
339
|
+
if (response.success && response.data) {
|
|
340
|
+
const d = response.data;
|
|
341
|
+
return {
|
|
342
|
+
id: (0, uuid_1.v4)(),
|
|
343
|
+
success: true,
|
|
344
|
+
content: [{ type: 'text', text: `当前文档: ${d.name}\n路径: ${d.path}\n页数: ${d.pageCount}\n字数: ${d.wordCount}` }],
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
id: (0, uuid_1.v4)(),
|
|
349
|
+
success: false,
|
|
350
|
+
content: [{ type: 'text', text: `获取文档信息失败: ${response.error}` }],
|
|
351
|
+
error: response.error,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
356
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `获取文档信息出错: ${errMsg}` }], error: errMsg };
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
exports.getActiveDocumentHandler = getActiveDocumentHandler;
|
|
360
|
+
/**
|
|
361
|
+
* 在文档中插入图片
|
|
362
|
+
*/
|
|
363
|
+
exports.insertImageDefinition = {
|
|
364
|
+
name: 'wps_word_insert_image',
|
|
365
|
+
description: `在Word文档中插入图片。
|
|
366
|
+
|
|
367
|
+
使用场景:
|
|
368
|
+
- "在文档中插入一张图片"
|
|
369
|
+
- "把这个截图放到文档里"
|
|
370
|
+
- "在光标位置插入logo"`,
|
|
371
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
372
|
+
inputSchema: {
|
|
373
|
+
type: 'object',
|
|
374
|
+
properties: {
|
|
375
|
+
imagePath: {
|
|
376
|
+
type: 'string',
|
|
377
|
+
description: '图片文件路径',
|
|
378
|
+
},
|
|
379
|
+
width: {
|
|
380
|
+
type: 'number',
|
|
381
|
+
description: '图片宽度(磅),可选',
|
|
382
|
+
},
|
|
383
|
+
height: {
|
|
384
|
+
type: 'number',
|
|
385
|
+
description: '图片高度(磅),可选',
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
required: ['imagePath'],
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
const insertImageHandler = async (args) => {
|
|
392
|
+
const { imagePath, width, height } = args;
|
|
393
|
+
if (!imagePath || imagePath.trim() === '') {
|
|
394
|
+
return {
|
|
395
|
+
id: (0, uuid_1.v4)(),
|
|
396
|
+
success: false,
|
|
397
|
+
content: [{ type: 'text', text: '图片路径不能为空!' }],
|
|
398
|
+
error: '图片路径为空',
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
// 参数对齐:底层优先读取 params.path,同时保留 imagePath/filePath
|
|
403
|
+
const response = await wps_client_1.wpsClient.executeMethod('insertImage', { imagePath, path: imagePath, filePath: imagePath, width, height }, wps_1.WpsAppType.WRITER);
|
|
404
|
+
if (response.success) {
|
|
405
|
+
return {
|
|
406
|
+
id: (0, uuid_1.v4)(),
|
|
407
|
+
success: true,
|
|
408
|
+
content: [
|
|
409
|
+
{
|
|
410
|
+
type: 'text',
|
|
411
|
+
text: `图片插入成功!\n路径: ${imagePath}${width ? `\n宽度: ${width}磅` : ''}${height ? `\n高度: ${height}磅` : ''}`,
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
id: (0, uuid_1.v4)(),
|
|
418
|
+
success: false,
|
|
419
|
+
content: [{ type: 'text', text: `插入图片失败: ${response.error}` }],
|
|
420
|
+
error: response.error,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
425
|
+
return {
|
|
426
|
+
id: (0, uuid_1.v4)(),
|
|
427
|
+
success: false,
|
|
428
|
+
content: [{ type: 'text', text: `插入图片出错: ${errMsg}` }],
|
|
429
|
+
error: errMsg,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
exports.insertImageHandler = insertImageHandler;
|
|
434
|
+
/**
|
|
435
|
+
* 导出所有内容操作相关的Tools
|
|
436
|
+
*/
|
|
437
|
+
exports.insertPageBreakDefinition = {
|
|
438
|
+
name: 'wps_word_insert_page_break',
|
|
439
|
+
description: '在文档光标位置插入分页符',
|
|
440
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
441
|
+
inputSchema: {
|
|
442
|
+
type: 'object',
|
|
443
|
+
properties: {},
|
|
444
|
+
required: [],
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
const insertPageBreakHandler = async (_args) => {
|
|
448
|
+
try {
|
|
449
|
+
const response = await wps_client_1.wpsClient.executeMethod('insertPageBreak', {}, wps_1.WpsAppType.WRITER);
|
|
450
|
+
return {
|
|
451
|
+
id: (0, uuid_1.v4)(),
|
|
452
|
+
success: response.success,
|
|
453
|
+
content: [{ type: 'text', text: response.success ? '分页符已插入' : response.data?.message || '插入失败' }],
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
catch (e) {
|
|
457
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `插入分页符出错: ${e.message}` }], error: e.message };
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
exports.insertPageBreakHandler = insertPageBreakHandler;
|
|
461
|
+
exports.setFontStyleDefinition = {
|
|
462
|
+
name: 'wps_word_set_font_style',
|
|
463
|
+
description: '[DEPRECATED·改用 wps_word_set_font] 设置选中文字的字体样式属性\n\n' +
|
|
464
|
+
'什么时候用:已被 wps_word_set_font 取代(同一个 setFont 动作),' +
|
|
465
|
+
'旧参数是 fontName/fontSize,新工具用 font_name/font_size,而且多了 range/color/underline —— 别两个混着用。',
|
|
466
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
467
|
+
inputSchema: {
|
|
468
|
+
type: 'object',
|
|
469
|
+
properties: {
|
|
470
|
+
fontName: { type: 'string', description: '字体名称' },
|
|
471
|
+
fontSize: { type: 'number', description: '字号' },
|
|
472
|
+
bold: { type: 'boolean', description: '是否加粗' },
|
|
473
|
+
italic: { type: 'boolean', description: '是否斜体' },
|
|
474
|
+
},
|
|
475
|
+
required: [],
|
|
476
|
+
},
|
|
477
|
+
};
|
|
478
|
+
const setFontStyleHandler = async (args) => {
|
|
479
|
+
try {
|
|
480
|
+
const response = await wps_client_1.wpsClient.executeMethod('setFont', args, wps_1.WpsAppType.WRITER);
|
|
481
|
+
return {
|
|
482
|
+
id: (0, uuid_1.v4)(),
|
|
483
|
+
success: response.success,
|
|
484
|
+
content: [{ type: 'text', text: response.success ? '字体已设置' : response.data?.message || '设置失败' }],
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
catch (e) {
|
|
488
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `设置字体出错: ${e.message}` }], error: e.message };
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
exports.setFontStyleHandler = setFontStyleHandler;
|
|
492
|
+
/**
|
|
493
|
+
* 插入批注到文档选中内容
|
|
494
|
+
*/
|
|
495
|
+
exports.insertCommentDefinition = {
|
|
496
|
+
name: 'wps_word_insert_comment',
|
|
497
|
+
description: '在Word文档选中内容处插入批注',
|
|
498
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
499
|
+
inputSchema: {
|
|
500
|
+
type: 'object',
|
|
501
|
+
properties: {
|
|
502
|
+
text: { type: 'string', description: '批注内容' },
|
|
503
|
+
},
|
|
504
|
+
required: ['text'],
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
const insertCommentHandler = async (args) => {
|
|
508
|
+
const { text } = args;
|
|
509
|
+
if (!text || text.trim() === '') {
|
|
510
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: '批注内容不能为空!' }], error: '批注内容为空' };
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
const response = await wps_client_1.wpsClient.executeMethod('addComment', { text }, wps_1.WpsAppType.WRITER);
|
|
514
|
+
return {
|
|
515
|
+
id: (0, uuid_1.v4)(),
|
|
516
|
+
success: response.success,
|
|
517
|
+
content: [{ type: 'text', text: response.success ? '批注已插入' : response.data?.message || '插入失败' }],
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
catch (e) {
|
|
521
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `插入批注出错: ${e.message}` }], error: e.message };
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
exports.insertCommentHandler = insertCommentHandler;
|
|
525
|
+
/**
|
|
526
|
+
* 设置选中文字的颜色
|
|
527
|
+
*/
|
|
528
|
+
exports.setTextColorDefinition = {
|
|
529
|
+
name: 'wps_word_set_text_color',
|
|
530
|
+
description: '设置Word文档中选中文字的颜色',
|
|
531
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
532
|
+
inputSchema: {
|
|
533
|
+
type: 'object',
|
|
534
|
+
properties: {
|
|
535
|
+
color: { type: 'string', description: '颜色值,如 "#FF0000"、"red"' },
|
|
536
|
+
},
|
|
537
|
+
required: ['color'],
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
const setTextColorHandler = async (args) => {
|
|
541
|
+
const { color } = args;
|
|
542
|
+
if (!color || color.trim() === '') {
|
|
543
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: '颜色值不能为空!' }], error: '颜色值为空' };
|
|
544
|
+
}
|
|
545
|
+
try {
|
|
546
|
+
const response = await wps_client_1.wpsClient.executeMethod('setTextColor', // NOTE: 仅Windows支持
|
|
547
|
+
{ color }, wps_1.WpsAppType.WRITER);
|
|
548
|
+
return {
|
|
549
|
+
id: (0, uuid_1.v4)(),
|
|
550
|
+
success: response.success,
|
|
551
|
+
content: [{ type: 'text', text: response.success ? `文字颜色已设置为 ${color}` : response.data?.message || '设置失败' }],
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
catch (e) {
|
|
555
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `设置文字颜色出错: ${e.message}` }], error: e.message };
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
exports.setTextColorHandler = setTextColorHandler;
|
|
559
|
+
/**
|
|
560
|
+
* 获取文档段落结构
|
|
561
|
+
* 返回段落的文本、样式、位置信息,用于了解文档结构和识别填写位置
|
|
562
|
+
*/
|
|
563
|
+
exports.getParagraphsDefinition = {
|
|
564
|
+
name: 'wps_word_get_paragraphs',
|
|
565
|
+
description: `获取Word文档的段落结构信息,返回每段的文本、样式和字符位置。
|
|
566
|
+
|
|
567
|
+
使用场景:
|
|
568
|
+
- "了解文档的结构"
|
|
569
|
+
- "查看文档有哪些段落"
|
|
570
|
+
- "帮我看看模板里有哪些需要填写的位置"
|
|
571
|
+
- 在填写模板前,先读取文档结构以识别填写位置
|
|
572
|
+
|
|
573
|
+
返回信息包括:段落索引、文本内容、样式名称、字符起止位置。
|
|
574
|
+
支持分页获取(startParagraph/endParagraph),默认返回前50段。`,
|
|
575
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
576
|
+
inputSchema: {
|
|
577
|
+
type: 'object',
|
|
578
|
+
properties: {
|
|
579
|
+
start_paragraph: { type: 'number', description: '起始段落索引(从1开始),默认1' },
|
|
580
|
+
end_paragraph: { type: 'number', description: '结束段落索引,默认为起始+49' },
|
|
581
|
+
},
|
|
582
|
+
required: [],
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
const getParagraphsHandler = async (args) => {
|
|
586
|
+
const { start_paragraph, end_paragraph } = args;
|
|
587
|
+
try {
|
|
588
|
+
const execParams = {};
|
|
589
|
+
if (start_paragraph != null)
|
|
590
|
+
execParams.startParagraph = start_paragraph;
|
|
591
|
+
if (end_paragraph != null)
|
|
592
|
+
execParams.endParagraph = end_paragraph;
|
|
593
|
+
const response = await wps_client_1.wpsClient.executeMethod('getDocumentParagraphs', execParams, wps_1.WpsAppType.WRITER);
|
|
594
|
+
if (response.success && response.data) {
|
|
595
|
+
const { paragraphs, totalCount, returnedCount } = response.data;
|
|
596
|
+
const lines = paragraphs.map((p) => `[${p.index}] (${p.style}) ${p.text}`);
|
|
597
|
+
return {
|
|
598
|
+
id: (0, uuid_1.v4)(),
|
|
599
|
+
success: true,
|
|
600
|
+
content: [{ type: 'text', text: `文档段落结构(共${totalCount}段,返回${returnedCount}段):\n${lines.join('\n')}` }],
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
id: (0, uuid_1.v4)(),
|
|
605
|
+
success: false,
|
|
606
|
+
content: [{ type: 'text', text: `获取段落结构失败: ${response.error}` }],
|
|
607
|
+
error: response.error,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
612
|
+
return {
|
|
613
|
+
id: (0, uuid_1.v4)(),
|
|
614
|
+
success: false,
|
|
615
|
+
content: [{ type: 'text', text: `获取段落结构出错: ${errMsg}` }],
|
|
616
|
+
error: errMsg,
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
exports.getParagraphsHandler = getParagraphsHandler;
|
|
621
|
+
/**
|
|
622
|
+
* 查找文本返回位置(不替换)
|
|
623
|
+
* 返回匹配文本的位置信息和上下文,供后续精确操作使用
|
|
624
|
+
*/
|
|
625
|
+
exports.findInDocumentDefinition = {
|
|
626
|
+
name: 'wps_word_find_in_document',
|
|
627
|
+
description: `在Word文档中查找文本并返回位置信息,不执行替换操作。
|
|
628
|
+
|
|
629
|
+
使用场景:
|
|
630
|
+
- "找一下'项目名称'在文档的哪个位置"
|
|
631
|
+
- "看看文档里有哪些地方需要填写"
|
|
632
|
+
- 在使用smart_fill_field之前,先用此工具定位关键字
|
|
633
|
+
|
|
634
|
+
返回信息包括:匹配文本、字符起止位置、所在段落索引、上下文(前后50字符)。
|
|
635
|
+
与find_replace不同,此工具仅查找不替换,返回位置信息供后续操作使用。`,
|
|
636
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
637
|
+
inputSchema: {
|
|
638
|
+
type: 'object',
|
|
639
|
+
properties: {
|
|
640
|
+
find_text: { type: 'string', description: '要查找的文本' },
|
|
641
|
+
match_case: { type: 'boolean', description: '是否区分大小写,默认false' },
|
|
642
|
+
match_whole_word: { type: 'boolean', description: '是否全字匹配,默认false' },
|
|
643
|
+
max_results: { type: 'number', description: '最大返回结果数,默认20' },
|
|
644
|
+
},
|
|
645
|
+
required: ['find_text'],
|
|
646
|
+
},
|
|
647
|
+
};
|
|
648
|
+
const findInDocumentHandler = async (args) => {
|
|
649
|
+
const { find_text, match_case, match_whole_word, max_results } = args;
|
|
650
|
+
if (!find_text || find_text.trim() === '') {
|
|
651
|
+
return {
|
|
652
|
+
id: (0, uuid_1.v4)(),
|
|
653
|
+
success: false,
|
|
654
|
+
content: [{ type: 'text', text: '查找文本不能为空!' }],
|
|
655
|
+
error: '查找文本为空',
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
try {
|
|
659
|
+
const response = await wps_client_1.wpsClient.executeMethod('findInDocument', {
|
|
660
|
+
findText: find_text,
|
|
661
|
+
matchCase: match_case || false,
|
|
662
|
+
matchWholeWord: match_whole_word || false,
|
|
663
|
+
maxResults: max_results || 20,
|
|
664
|
+
}, wps_1.WpsAppType.WRITER);
|
|
665
|
+
if (response.success && response.data) {
|
|
666
|
+
const { results, count, findText } = response.data;
|
|
667
|
+
if (count === 0) {
|
|
668
|
+
return { id: (0, uuid_1.v4)(), success: true, content: [{ type: 'text', text: `未找到 "${findText}"` }] };
|
|
669
|
+
}
|
|
670
|
+
const lines = results.map((r) => ` 段落${r.paragraphIndex} [${r.start}-${r.end}]: ...${r.context}...`);
|
|
671
|
+
return {
|
|
672
|
+
id: (0, uuid_1.v4)(),
|
|
673
|
+
success: true,
|
|
674
|
+
content: [{ type: 'text', text: `找到 "${findText}" 共${count}处:\n${lines.join('\n')}` }],
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
return {
|
|
678
|
+
id: (0, uuid_1.v4)(),
|
|
679
|
+
success: false,
|
|
680
|
+
content: [{ type: 'text', text: `查找失败: ${response.error}` }],
|
|
681
|
+
error: response.error,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
catch (error) {
|
|
685
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
686
|
+
return {
|
|
687
|
+
id: (0, uuid_1.v4)(),
|
|
688
|
+
success: false,
|
|
689
|
+
content: [{ type: 'text', text: `查找出错: ${errMsg}` }],
|
|
690
|
+
error: errMsg,
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
exports.findInDocumentHandler = findInDocumentHandler;
|
|
695
|
+
/**
|
|
696
|
+
* 智能填写模板字段
|
|
697
|
+
* 自动判断关键字附近的填写模式(下划线/冒号后/标签后/占位符),在正确位置插入内容并保持格式
|
|
698
|
+
*/
|
|
699
|
+
exports.smartFillFieldDefinition = {
|
|
700
|
+
name: 'wps_word_smart_fill_field',
|
|
701
|
+
description: `智能填写Word模板中的字段。自动识别关键字附近的填写模式,在正确位置插入内容并保持原有格式。
|
|
702
|
+
|
|
703
|
+
使用场景:
|
|
704
|
+
- "把项目名称填写为'XX信息化项目'"
|
|
705
|
+
- "填写建设单位为'XX公司'"
|
|
706
|
+
- "模板里的项目编号填上'2026-001'"
|
|
707
|
+
- 任何需要在模板文档中"填写"而非"替换"的场景
|
|
708
|
+
|
|
709
|
+
支持的填写模式(fill_mode,默认auto自动判断):
|
|
710
|
+
- auto: 自动判断(推荐)
|
|
711
|
+
- underline: 关键字后有下划线___,替换下划线为填写内容
|
|
712
|
+
- afterColon: 关键字后有冒号(:或:),在冒号后插入
|
|
713
|
+
- afterLabel: 关键字是标签,直接在关键字后插入
|
|
714
|
+
- placeholder: 关键字被{}或【】包裹,替换整个占位符
|
|
715
|
+
|
|
716
|
+
重要:模板填写场景应优先使用此工具,而非find_replace。find_replace会删除关键字本身并可能破坏格式。`,
|
|
717
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
718
|
+
inputSchema: {
|
|
719
|
+
type: 'object',
|
|
720
|
+
properties: {
|
|
721
|
+
keyword: { type: 'string', description: '要填写的关键字(如"项目名称"、"建设单位")' },
|
|
722
|
+
value: { type: 'string', description: '要填写的值(如"XX信息化项目")' },
|
|
723
|
+
fill_mode: {
|
|
724
|
+
type: 'string',
|
|
725
|
+
description: '填写模式: auto(自动判断), underline(下划线), afterColon(冒号后), afterLabel(标签后), placeholder(占位符)。默认auto',
|
|
726
|
+
enum: ['auto', 'underline', 'afterColon', 'afterLabel', 'placeholder'],
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
required: ['keyword', 'value'],
|
|
730
|
+
},
|
|
731
|
+
};
|
|
732
|
+
const smartFillFieldHandler = async (args) => {
|
|
733
|
+
const { keyword, value, fill_mode } = args;
|
|
734
|
+
if (!keyword || keyword.trim() === '') {
|
|
735
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: '关键字不能为空!' }], error: '关键字为空' };
|
|
736
|
+
}
|
|
737
|
+
if (value == null) {
|
|
738
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: '填写值不能为空(空字符串将清除该字段内容)' }], error: '填写值为空' };
|
|
739
|
+
}
|
|
740
|
+
try {
|
|
741
|
+
const response = await wps_client_1.wpsClient.executeMethod('smartFillField', { keyword, value, fillMode: fill_mode || 'auto' }, wps_1.WpsAppType.WRITER);
|
|
742
|
+
if (response.success && response.data) {
|
|
743
|
+
const { fillMode, result } = response.data;
|
|
744
|
+
return {
|
|
745
|
+
id: (0, uuid_1.v4)(),
|
|
746
|
+
success: true,
|
|
747
|
+
content: [{ type: 'text', text: `填写完成!\n关键字: "${keyword}"\n填写值: "${value}"\n填写模式: ${fillMode}\n结果: ${result}` }],
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
id: (0, uuid_1.v4)(),
|
|
752
|
+
success: false,
|
|
753
|
+
content: [{ type: 'text', text: `填写失败: ${response.error}` }],
|
|
754
|
+
error: response.error,
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
catch (error) {
|
|
758
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
759
|
+
return {
|
|
760
|
+
id: (0, uuid_1.v4)(),
|
|
761
|
+
success: false,
|
|
762
|
+
content: [{ type: 'text', text: `填写出错: ${errMsg}` }],
|
|
763
|
+
error: errMsg,
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
exports.smartFillFieldHandler = smartFillFieldHandler;
|
|
768
|
+
/**
|
|
769
|
+
* 替换书签内容
|
|
770
|
+
* 通过书签名定位并替换内容,保持书签位置格式
|
|
771
|
+
*/
|
|
772
|
+
exports.replaceBookmarkContentDefinition = {
|
|
773
|
+
name: 'wps_word_replace_bookmark_content',
|
|
774
|
+
description: `替换Word文档中书签的内容。通过书签名定位,替换书签范围内的文本,保持原有格式。
|
|
775
|
+
|
|
776
|
+
使用场景:
|
|
777
|
+
- "把书签'project_name'的内容改为'XX项目'"
|
|
778
|
+
- 模板文档使用书签标记填写位置时使用
|
|
779
|
+
|
|
780
|
+
注意:替换后书签会自动重建,不会丢失。`,
|
|
781
|
+
category: tools_1.ToolCategory.DOCUMENT,
|
|
782
|
+
inputSchema: {
|
|
783
|
+
type: 'object',
|
|
784
|
+
properties: {
|
|
785
|
+
name: { type: 'string', description: '书签名称' },
|
|
786
|
+
text: { type: 'string', description: '要替换为的文本内容' },
|
|
787
|
+
},
|
|
788
|
+
required: ['name', 'text'],
|
|
789
|
+
},
|
|
790
|
+
};
|
|
791
|
+
const replaceBookmarkContentHandler = async (args) => {
|
|
792
|
+
const { name, text } = args;
|
|
793
|
+
if (!name || name.trim() === '') {
|
|
794
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: '书签名称不能为空!' }], error: '书签名称为空' };
|
|
795
|
+
}
|
|
796
|
+
if (text == null) {
|
|
797
|
+
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: '替换文本不能为空(空字符串将清空书签)' }], error: '替换文本为空' };
|
|
798
|
+
}
|
|
799
|
+
try {
|
|
800
|
+
const response = await wps_client_1.wpsClient.executeMethod('replaceBookmarkContent', { name, text }, wps_1.WpsAppType.WRITER);
|
|
801
|
+
if (response.success && response.data) {
|
|
802
|
+
return {
|
|
803
|
+
id: (0, uuid_1.v4)(),
|
|
804
|
+
success: true,
|
|
805
|
+
content: [{ type: 'text', text: `书签内容替换完成!\n书签: "${name}"\n新内容: "${text}"` }],
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
return {
|
|
809
|
+
id: (0, uuid_1.v4)(),
|
|
810
|
+
success: false,
|
|
811
|
+
content: [{ type: 'text', text: `替换书签内容失败: ${response.error}` }],
|
|
812
|
+
error: response.error,
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
catch (error) {
|
|
816
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
817
|
+
return {
|
|
818
|
+
id: (0, uuid_1.v4)(),
|
|
819
|
+
success: false,
|
|
820
|
+
content: [{ type: 'text', text: `替换书签内容出错: ${errMsg}` }],
|
|
821
|
+
error: errMsg,
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
exports.replaceBookmarkContentHandler = replaceBookmarkContentHandler;
|
|
826
|
+
exports.contentTools = [
|
|
827
|
+
{ definition: exports.insertTextDefinition, handler: exports.insertTextHandler },
|
|
828
|
+
{ definition: exports.findReplaceDefinition, handler: exports.findReplaceHandler },
|
|
829
|
+
{ definition: exports.insertTableDefinition, handler: exports.insertTableHandler },
|
|
830
|
+
{ definition: exports.setParagraphDefinition, handler: exports.setParagraphHandler },
|
|
831
|
+
{ definition: exports.getActiveDocumentDefinition, handler: exports.getActiveDocumentHandler },
|
|
832
|
+
{ definition: exports.insertImageDefinition, handler: exports.insertImageHandler },
|
|
833
|
+
{ definition: exports.insertPageBreakDefinition, handler: exports.insertPageBreakHandler },
|
|
834
|
+
{ definition: exports.setFontStyleDefinition, handler: exports.setFontStyleHandler },
|
|
835
|
+
{ definition: exports.insertCommentDefinition, handler: exports.insertCommentHandler },
|
|
836
|
+
{ definition: exports.setTextColorDefinition, handler: exports.setTextColorHandler },
|
|
837
|
+
{ definition: exports.getParagraphsDefinition, handler: exports.getParagraphsHandler },
|
|
838
|
+
{ definition: exports.findInDocumentDefinition, handler: exports.findInDocumentHandler },
|
|
839
|
+
{ definition: exports.smartFillFieldDefinition, handler: exports.smartFillFieldHandler },
|
|
840
|
+
{ definition: exports.replaceBookmarkContentDefinition, handler: exports.replaceBookmarkContentHandler },
|
|
841
|
+
];
|
|
842
|
+
exports.default = exports.contentTools;
|
|
843
|
+
//# sourceMappingURL=content.js.map
|