wps-multitool-mcp 1.0.3 → 1.0.5
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 +2 -2
- package/dist/bridge/cancellable.d.ts.map +1 -1
- package/dist/bridge/cancellable.js +2 -0
- package/dist/bridge/cancellable.js.map +1 -1
- package/dist/bridge/index.js +36 -1
- package/dist/bridge/index.js.map +1 -1
- package/dist/client/action-routes.generated.d.ts +2 -2
- package/dist/client/action-routes.generated.d.ts.map +1 -1
- package/dist/client/action-routes.generated.js +8 -2
- package/dist/client/action-routes.generated.js.map +1 -1
- package/dist/server/auto-snapshot.d.ts.map +1 -1
- package/dist/server/auto-snapshot.js +12 -1
- package/dist/server/auto-snapshot.js.map +1 -1
- package/dist/server/collab-guard.d.ts +13 -0
- package/dist/server/collab-guard.d.ts.map +1 -0
- package/dist/server/collab-guard.js +112 -0
- package/dist/server/collab-guard.js.map +1 -0
- package/dist/server/intent-miss-log.d.ts +28 -0
- package/dist/server/intent-miss-log.d.ts.map +1 -0
- package/dist/server/intent-miss-log.js +143 -0
- package/dist/server/intent-miss-log.js.map +1 -0
- package/dist/server/mcp-server.d.ts +9 -0
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +168 -4
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/progress-context.d.ts +6 -0
- package/dist/server/progress-context.d.ts.map +1 -0
- package/dist/server/progress-context.js +35 -0
- package/dist/server/progress-context.js.map +1 -0
- package/dist/server/task-engine.d.ts +112 -0
- package/dist/server/task-engine.d.ts.map +1 -0
- package/dist/server/task-engine.js +305 -0
- package/dist/server/task-engine.js.map +1 -0
- package/dist/server/tool-aliases.generated.d.ts +1 -1
- package/dist/server/tool-aliases.generated.d.ts.map +1 -1
- package/dist/server/tool-aliases.generated.js +15 -2
- package/dist/server/tool-aliases.generated.js.map +1 -1
- package/dist/server/tool-annotations.d.ts.map +1 -1
- package/dist/server/tool-annotations.generated.d.ts.map +1 -1
- package/dist/server/tool-annotations.generated.js +7 -8
- package/dist/server/tool-annotations.generated.js.map +1 -1
- package/dist/server/tool-annotations.js +18 -0
- package/dist/server/tool-annotations.js.map +1 -1
- package/dist/server/tool-metadata.d.ts.map +1 -1
- package/dist/server/tool-metadata.js +21 -9
- package/dist/server/tool-metadata.js.map +1 -1
- package/dist/server/tool-registry.d.ts.map +1 -1
- package/dist/server/tool-registry.js +26 -1
- package/dist/server/tool-registry.js.map +1 -1
- package/dist/server/tool-tiers.d.ts +2 -2
- package/dist/server/tool-tiers.js +2 -2
- package/dist/server/tool-verification.d.ts +5 -5
- package/dist/server/tool-verification.generated.d.ts +4 -4
- package/dist/server/tool-verification.generated.d.ts.map +1 -1
- package/dist/server/tool-verification.generated.js +78 -79
- package/dist/server/tool-verification.generated.js.map +1 -1
- package/dist/server/tool-verification.js +2 -2
- package/dist/tools/common/batch.d.ts.map +1 -1
- package/dist/tools/common/batch.js +5 -0
- package/dist/tools/common/batch.js.map +1 -1
- package/dist/tools/common/convert.js +34 -34
- package/dist/tools/common/general.d.ts.map +1 -1
- package/dist/tools/common/general.js +81 -79
- package/dist/tools/common/general.js.map +1 -1
- package/dist/tools/common/index.d.ts +1 -0
- package/dist/tools/common/index.d.ts.map +1 -1
- package/dist/tools/common/index.js +3 -0
- package/dist/tools/common/index.js.map +1 -1
- package/dist/tools/common/intent.d.ts +42 -0
- package/dist/tools/common/intent.d.ts.map +1 -1
- package/dist/tools/common/intent.js +307 -19
- package/dist/tools/common/intent.js.map +1 -1
- package/dist/tools/common/snapshot.d.ts.map +1 -1
- package/dist/tools/common/snapshot.js +27 -19
- package/dist/tools/common/snapshot.js.map +1 -1
- package/dist/tools/common/taskrunner.d.ts +25 -0
- package/dist/tools/common/taskrunner.d.ts.map +1 -0
- package/dist/tools/common/taskrunner.js +100 -0
- package/dist/tools/common/taskrunner.js.map +1 -0
- package/dist/tools/common/toolgroups.js +36 -36
- package/dist/tools/excel/chart.d.ts.map +1 -1
- package/dist/tools/excel/chart.js +109 -86
- package/dist/tools/excel/chart.js.map +1 -1
- package/dist/tools/excel/comment-protect.js +2 -2
- package/dist/tools/excel/comment-protect.js.map +1 -1
- package/dist/tools/excel/data.d.ts.map +1 -1
- package/dist/tools/excel/data.js +32 -21
- package/dist/tools/excel/data.js.map +1 -1
- package/dist/tools/excel/format.js +9 -9
- package/dist/tools/excel/formula.js +46 -46
- package/dist/tools/excel/pivot.js +34 -34
- package/dist/tools/excel/sheet.d.ts +4 -0
- package/dist/tools/excel/sheet.d.ts.map +1 -1
- package/dist/tools/excel/sheet.js +103 -1
- package/dist/tools/excel/sheet.js.map +1 -1
- package/dist/tools/ppt/animation.d.ts +2 -2
- package/dist/tools/ppt/animation.d.ts.map +1 -1
- package/dist/tools/ppt/animation.js +35 -97
- package/dist/tools/ppt/animation.js.map +1 -1
- package/dist/tools/ppt/beautify-advanced.d.ts +3 -16
- package/dist/tools/ppt/beautify-advanced.d.ts.map +1 -1
- package/dist/tools/ppt/beautify-advanced.js +65 -355
- package/dist/tools/ppt/beautify-advanced.js.map +1 -1
- package/dist/tools/ppt/chart-flow.d.ts.map +1 -1
- package/dist/tools/ppt/chart-flow.js +113 -278
- package/dist/tools/ppt/chart-flow.js.map +1 -1
- package/dist/tools/ppt/data-viz.d.ts.map +1 -1
- package/dist/tools/ppt/data-viz.js +78 -276
- package/dist/tools/ppt/data-viz.js.map +1 -1
- package/dist/tools/ppt/deckkit.d.ts +209 -0
- package/dist/tools/ppt/deckkit.d.ts.map +1 -0
- package/dist/tools/ppt/deckkit.js +635 -0
- package/dist/tools/ppt/deckkit.js.map +1 -0
- package/dist/tools/ppt/helpers.d.ts +38 -0
- package/dist/tools/ppt/helpers.d.ts.map +1 -0
- package/dist/tools/ppt/helpers.js +60 -0
- package/dist/tools/ppt/helpers.js.map +1 -0
- package/dist/tools/ppt/image.d.ts +6 -4
- package/dist/tools/ppt/image.d.ts.map +1 -1
- package/dist/tools/ppt/image.js +148 -244
- package/dist/tools/ppt/image.js.map +1 -1
- package/dist/tools/ppt/index.d.ts +43 -29
- package/dist/tools/ppt/index.d.ts.map +1 -1
- package/dist/tools/ppt/index.js +106 -95
- package/dist/tools/ppt/index.js.map +1 -1
- package/dist/tools/ppt/misc.d.ts +1 -2
- package/dist/tools/ppt/misc.d.ts.map +1 -1
- package/dist/tools/ppt/misc.js +70 -385
- package/dist/tools/ppt/misc.js.map +1 -1
- package/dist/tools/ppt/page-effects.d.ts +28 -0
- package/dist/tools/ppt/page-effects.d.ts.map +1 -0
- package/dist/tools/ppt/page-effects.js +505 -0
- package/dist/tools/ppt/page-effects.js.map +1 -0
- package/dist/tools/ppt/{background.d.ts → page-info.d.ts} +11 -13
- package/dist/tools/ppt/page-info.d.ts.map +1 -0
- package/dist/tools/ppt/page-info.js +258 -0
- package/dist/tools/ppt/page-info.js.map +1 -0
- package/dist/tools/ppt/presentation.d.ts +3 -6
- package/dist/tools/ppt/presentation.d.ts.map +1 -1
- package/dist/tools/ppt/presentation.js +136 -437
- package/dist/tools/ppt/presentation.js.map +1 -1
- package/dist/tools/ppt/shape-basic.d.ts +22 -3
- package/dist/tools/ppt/shape-basic.d.ts.map +1 -1
- package/dist/tools/ppt/shape-basic.js +518 -421
- package/dist/tools/ppt/shape-basic.js.map +1 -1
- package/dist/tools/ppt/slide-ops.d.ts +6 -42
- package/dist/tools/ppt/slide-ops.d.ts.map +1 -1
- package/dist/tools/ppt/slide-ops.js +93 -1485
- package/dist/tools/ppt/slide-ops.js.map +1 -1
- package/dist/tools/ppt/slide.d.ts +1 -7
- package/dist/tools/ppt/slide.d.ts.map +1 -1
- package/dist/tools/ppt/slide.js +196 -328
- package/dist/tools/ppt/slide.js.map +1 -1
- package/dist/tools/ppt/table.d.ts.map +1 -1
- package/dist/tools/ppt/table.js +94 -264
- package/dist/tools/ppt/table.js.map +1 -1
- package/dist/tools/ppt/textbox.d.ts +1 -22
- package/dist/tools/ppt/textbox.d.ts.map +1 -1
- package/dist/tools/ppt/textbox.js +87 -107
- package/dist/tools/ppt/textbox.js.map +1 -1
- package/dist/tools/word/academic.d.ts +2 -0
- package/dist/tools/word/academic.d.ts.map +1 -1
- package/dist/tools/word/academic.js +77 -111
- package/dist/tools/word/academic.js.map +1 -1
- package/dist/tools/word/content.d.ts +7 -12
- package/dist/tools/word/content.d.ts.map +1 -1
- package/dist/tools/word/content.js +134 -452
- package/dist/tools/word/content.js.map +1 -1
- package/dist/tools/word/document.d.ts +1 -3
- package/dist/tools/word/document.d.ts.map +1 -1
- package/dist/tools/word/document.js +71 -328
- package/dist/tools/word/document.js.map +1 -1
- package/dist/tools/word/format.d.ts.map +1 -1
- package/dist/tools/word/format.js +59 -211
- package/dist/tools/word/format.js.map +1 -1
- package/dist/tools/word/helpers.d.ts +33 -0
- package/dist/tools/word/helpers.d.ts.map +1 -0
- package/dist/tools/word/helpers.js +50 -0
- package/dist/tools/word/helpers.js.map +1 -0
- package/dist/tools/word/index.d.ts +1 -1
- package/dist/tools/word/index.d.ts.map +1 -1
- package/dist/tools/word/index.js +2 -6
- package/dist/tools/word/index.js.map +1 -1
- package/dist/tools/word/professional.d.ts +4 -0
- package/dist/tools/word/professional.d.ts.map +1 -1
- package/dist/tools/word/professional.js +80 -4
- package/dist/tools/word/professional.js.map +1 -1
- package/dist/tools/word/proofread.d.ts.map +1 -1
- package/dist/tools/word/proofread.js +44 -184
- package/dist/tools/word/proofread.js.map +1 -1
- package/dist/types/tools.d.ts +6 -0
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/utils/image-inline.d.ts +3 -0
- package/dist/utils/image-inline.d.ts.map +1 -0
- package/dist/utils/image-inline.js +61 -0
- package/dist/utils/image-inline.js.map +1 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/scripts/wps-com.ps1 +509 -28
- package/skills/wps-multitool/SKILL.md +17 -4
- package/skills/wps-multitool/references/dsh.md +1 -1
- package/skills/wps-multitool/references/recipes.md +20 -4
- package/skills/wps-multitool/references/routing.md +13 -0
- package/dist/client/mac-poll-server.d.ts.map +0 -1
- package/dist/client/mac-poll-server.js.map +0 -1
- package/dist/tools/ppt/background.d.ts.map +0 -1
- package/dist/tools/ppt/background.js +0 -389
- package/dist/tools/ppt/background.js.map +0 -1
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* Input: Word 内容操作参数
|
|
4
4
|
* Output: 文档内容变更结果
|
|
5
5
|
* Pos: Word 内容工具实现。一旦我被修改,请更新我的头部注释,以及所属文件夹的md。
|
|
6
|
-
* Word内容操作Tools -
|
|
7
|
-
* 处理文档内容的插入、查找替换、表格、段落格式、页眉页脚等操作
|
|
6
|
+
* Word内容操作Tools - 文档内容编辑模块(2026-10-30 收尾风格统一到 helpers,warnings 一路透传)
|
|
8
7
|
*
|
|
9
8
|
* 包含:
|
|
10
9
|
* - wps_word_insert_text: 插入文本到文档
|
|
@@ -13,19 +12,20 @@
|
|
|
13
12
|
* - wps_word_set_paragraph: 设置段落格式
|
|
14
13
|
* - wps_word_insert_header: 插入页眉
|
|
15
14
|
* - wps_word_insert_footer: 插入页脚
|
|
16
|
-
* - wps_word_get_active_document: 获取当前文档信息
|
|
17
15
|
* - wps_word_insert_page_break: 插入分页符
|
|
18
16
|
* - wps_word_insert_comment: 插入批注
|
|
19
|
-
* - wps_word_set_font_style:
|
|
17
|
+
* - wps_word_set_font_style: (已下线,降为别名指向 wps_word_set_font)
|
|
20
18
|
* - wps_word_set_text_color: 设置文字颜色
|
|
19
|
+
* - wps_word_get_paragraphs: 获取段落结构
|
|
20
|
+
* - wps_word_find_in_document: 查找文本返回位置
|
|
21
|
+
* - wps_word_smart_fill_field: 智能填写模板字段
|
|
22
|
+
* - wps_word_replace_bookmark_content: 替换书签内容
|
|
21
23
|
*/
|
|
22
24
|
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.
|
|
24
|
-
const uuid_1 = require("uuid");
|
|
25
|
+
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.insertPageBreakHandler = exports.insertPageBreakDefinition = exports.insertImageHandler = exports.insertImageDefinition = exports.setParagraphHandler = exports.setParagraphDefinition = exports.insertTableHandler = exports.insertTableDefinition = exports.findReplaceHandler = exports.findReplaceDefinition = exports.insertTextHandler = exports.insertTextDefinition = void 0;
|
|
25
26
|
const tools_1 = require("../../types/tools");
|
|
26
|
-
const wps_client_1 = require("../../client/wps-client");
|
|
27
|
-
const wps_1 = require("../../types/wps");
|
|
28
27
|
const target_1 = require("./target");
|
|
28
|
+
const helpers_1 = require("./helpers");
|
|
29
29
|
/**
|
|
30
30
|
* 插入文本到文档
|
|
31
31
|
* 可以在光标位置、文档开头或结尾插入文本
|
|
@@ -67,53 +67,20 @@ exports.insertTextDefinition = {
|
|
|
67
67
|
const insertTextHandler = async (args) => {
|
|
68
68
|
const { text, position, style, new_paragraph } = args;
|
|
69
69
|
if (!text || text.trim() === '') {
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, wps_1.WpsAppType.WRITER);
|
|
85
|
-
if (response.success && response.data) {
|
|
86
|
-
const positionText = position === 'start' ? '文档开头' :
|
|
87
|
-
position === 'end' ? '文档结尾' : '光标位置';
|
|
88
|
-
return {
|
|
89
|
-
id: (0, uuid_1.v4)(),
|
|
90
|
-
success: true,
|
|
91
|
-
content: [
|
|
92
|
-
{
|
|
93
|
-
type: 'text',
|
|
94
|
-
text: `文本插入成功!\n位置: ${positionText}\n字符数: ${response.data.textLength}${style ? `\n应用样式: ${style}` : ''}`,
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return {
|
|
101
|
-
id: (0, uuid_1.v4)(),
|
|
102
|
-
success: false,
|
|
103
|
-
content: [{ type: 'text', text: `插入文本失败: ${response.error}` }],
|
|
104
|
-
error: response.error,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
110
|
-
return {
|
|
111
|
-
id: (0, uuid_1.v4)(),
|
|
112
|
-
success: false,
|
|
113
|
-
content: [{ type: 'text', text: `插入文本出错: ${errMsg}` }],
|
|
114
|
-
error: errMsg,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
70
|
+
return (0, helpers_1.fail)('要插入的文本不能为空!', '文本内容为空');
|
|
71
|
+
}
|
|
72
|
+
// 处理换行符,如果需要新段落
|
|
73
|
+
const finalText = new_paragraph ? text + '\n' : text;
|
|
74
|
+
const r = await (0, helpers_1.call)('insertText', {
|
|
75
|
+
text: finalText,
|
|
76
|
+
position: position || 'cursor',
|
|
77
|
+
style,
|
|
78
|
+
});
|
|
79
|
+
if (!r.ok)
|
|
80
|
+
return (0, helpers_1.fail)(`插入文本失败: ${r.error}`, r.error);
|
|
81
|
+
const positionText = position === 'start' ? '文档开头' :
|
|
82
|
+
position === 'end' ? '文档结尾' : '光标位置';
|
|
83
|
+
return (0, helpers_1.ok)(`文本插入成功!\n位置: ${positionText}\n字符数: ${r.data?.textLength}${style ? `\n应用样式: ${style}` : ''}`, r.warnings);
|
|
117
84
|
};
|
|
118
85
|
exports.insertTextHandler = insertTextHandler;
|
|
119
86
|
/**
|
|
@@ -165,84 +132,46 @@ exports.findReplaceDefinition = {
|
|
|
165
132
|
const findReplaceHandler = async (args) => {
|
|
166
133
|
const { find_text, replace_text, replace_all, match_case, match_whole_word } = args;
|
|
167
134
|
if (!find_text || find_text.trim() === '') {
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const isReplaceMode = replace_text !== undefined && replace_text !== null;
|
|
178
|
-
const response = await wps_client_1.wpsClient.executeMethod('findReplace', {
|
|
135
|
+
return (0, helpers_1.fail)('查找文本不能为空!', '查找文本为空');
|
|
136
|
+
}
|
|
137
|
+
// 如果没有替换文本,就只是查找
|
|
138
|
+
const isReplaceMode = replace_text !== undefined && replace_text !== null;
|
|
139
|
+
// 全量替换前先计数(2026-10-30 word-audit §三.2):COM 的 Find.Execute 只回布尔,
|
|
140
|
+
// 次数靠替换前的 find_in_document 计数补上——两步换一个"替换了 N 处"。
|
|
141
|
+
let totalCount = 0;
|
|
142
|
+
if (isReplaceMode) {
|
|
143
|
+
const found = await (0, helpers_1.call)('findInDocument', {
|
|
179
144
|
findText: find_text,
|
|
180
|
-
replaceText: isReplaceMode ? replace_text : '',
|
|
181
|
-
replaceAll: replace_all !== false, // 默认true
|
|
182
145
|
matchCase: match_case || false,
|
|
183
146
|
matchWholeWord: match_whole_word || false,
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
id: (0, uuid_1.v4)(),
|
|
206
|
-
success: true,
|
|
207
|
-
content: [
|
|
208
|
-
{
|
|
209
|
-
type: 'text',
|
|
210
|
-
text: `替换完成!\n查找: "${find_text}"\n替换为: "${replace_text}"\n(COM 只返回"是否替换成功",不返回次数)`,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
return {
|
|
217
|
-
id: (0, uuid_1.v4)(),
|
|
218
|
-
success: true,
|
|
219
|
-
content: [
|
|
220
|
-
{
|
|
221
|
-
type: 'text',
|
|
222
|
-
text: `查找完成!\n"${find_text}" ${didReplace ? '存在并已执行替换' : '未找到可替换的内容'}`,
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
return {
|
|
230
|
-
id: (0, uuid_1.v4)(),
|
|
231
|
-
success: false,
|
|
232
|
-
content: [{ type: 'text', text: `查找替换失败: ${response.error}` }],
|
|
233
|
-
error: response.error,
|
|
234
|
-
};
|
|
147
|
+
maxResults: 1,
|
|
148
|
+
});
|
|
149
|
+
if (found.ok)
|
|
150
|
+
totalCount = found.data?.count ?? 0;
|
|
151
|
+
}
|
|
152
|
+
const r = await (0, helpers_1.call)('findReplace', {
|
|
153
|
+
findText: find_text,
|
|
154
|
+
replaceText: isReplaceMode ? replace_text : '',
|
|
155
|
+
replaceAll: replace_all !== false, // 默认true
|
|
156
|
+
matchCase: match_case || false,
|
|
157
|
+
matchWholeWord: match_whole_word || false,
|
|
158
|
+
replaceMode: isReplaceMode,
|
|
159
|
+
});
|
|
160
|
+
if (!r.ok)
|
|
161
|
+
return (0, helpers_1.fail)(`查找替换失败: ${r.error}`, r.error);
|
|
162
|
+
// PS 只回布尔(Find.Execute 的返回值),有没有替换成以它为准;
|
|
163
|
+
// 次数来自替换前的计数(全量替换时两者一致)。
|
|
164
|
+
const didReplace = r.data?.replaced === true;
|
|
165
|
+
if (isReplaceMode) {
|
|
166
|
+
if (!didReplace) {
|
|
167
|
+
return (0, helpers_1.ok)(`未找到 "${find_text}",没有进行替换`, r.warnings);
|
|
235
168
|
}
|
|
169
|
+
const countNote = replace_all !== false && totalCount > 0
|
|
170
|
+
? `共替换 ${totalCount} 处`
|
|
171
|
+
: '已替换(COM 不回逐处计数)';
|
|
172
|
+
return (0, helpers_1.ok)(`替换完成!\n查找: "${find_text}"\n替换为: "${replace_text}"\n${countNote}`, r.warnings);
|
|
236
173
|
}
|
|
237
|
-
|
|
238
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
239
|
-
return {
|
|
240
|
-
id: (0, uuid_1.v4)(),
|
|
241
|
-
success: false,
|
|
242
|
-
content: [{ type: 'text', text: `查找替换出错: ${errMsg}` }],
|
|
243
|
-
error: errMsg,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
174
|
+
return (0, helpers_1.ok)(`查找完成!\n"${find_text}" ${didReplace ? '存在并已执行替换' : '未找到可替换的内容'}`, r.warnings);
|
|
246
175
|
};
|
|
247
176
|
exports.findReplaceHandler = findReplaceHandler;
|
|
248
177
|
/**
|
|
@@ -264,26 +193,10 @@ exports.insertTableDefinition = {
|
|
|
264
193
|
};
|
|
265
194
|
const insertTableHandler = async (args) => {
|
|
266
195
|
const { rows, cols } = args;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
id: (0, uuid_1.v4)(),
|
|
272
|
-
success: true,
|
|
273
|
-
content: [{ type: 'text', text: `已插入 ${rows}×${cols} 表格` }],
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
return {
|
|
277
|
-
id: (0, uuid_1.v4)(),
|
|
278
|
-
success: false,
|
|
279
|
-
content: [{ type: 'text', text: `插入表格失败: ${response.error}` }],
|
|
280
|
-
error: response.error,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
285
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `插入表格出错: ${errMsg}` }], error: errMsg };
|
|
286
|
-
}
|
|
196
|
+
const r = await (0, helpers_1.call)('insertTable', { rows, cols });
|
|
197
|
+
if (!r.ok)
|
|
198
|
+
return (0, helpers_1.fail)(`插入表格失败: ${r.error}`, r.error);
|
|
199
|
+
return (0, helpers_1.ok)(`已插入 ${rows}×${cols} 表格`, r.warnings);
|
|
287
200
|
};
|
|
288
201
|
exports.insertTableHandler = insertTableHandler;
|
|
289
202
|
/**
|
|
@@ -304,64 +217,12 @@ exports.setParagraphDefinition = {
|
|
|
304
217
|
};
|
|
305
218
|
const setParagraphHandler = async (args) => {
|
|
306
219
|
const params = args;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
id: (0, uuid_1.v4)(),
|
|
312
|
-
success: true,
|
|
313
|
-
content: [{ type: 'text', text: '段落格式已设置' }],
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
return {
|
|
317
|
-
id: (0, uuid_1.v4)(),
|
|
318
|
-
success: false,
|
|
319
|
-
content: [{ type: 'text', text: `设置段落失败: ${response.error}` }],
|
|
320
|
-
error: response.error,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
catch (error) {
|
|
324
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
325
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `设置段落出错: ${errMsg}` }], error: errMsg };
|
|
326
|
-
}
|
|
220
|
+
const r = await (0, helpers_1.call)('setParagraph', params);
|
|
221
|
+
if (!r.ok)
|
|
222
|
+
return (0, helpers_1.fail)(`设置段落失败: ${r.error}`, r.error);
|
|
223
|
+
return (0, helpers_1.ok)('段落格式已设置', r.warnings);
|
|
327
224
|
};
|
|
328
225
|
exports.setParagraphHandler = setParagraphHandler;
|
|
329
|
-
/**
|
|
330
|
-
* 获取当前活动文档信息
|
|
331
|
-
*/
|
|
332
|
-
exports.getActiveDocumentDefinition = {
|
|
333
|
-
name: 'wps_word_get_active_document',
|
|
334
|
-
description: '获取当前WPS Writer活动文档的基本信息',
|
|
335
|
-
category: tools_1.ToolCategory.DOCUMENT,
|
|
336
|
-
inputSchema: {
|
|
337
|
-
type: 'object',
|
|
338
|
-
properties: { target: target_1.WORD_TARGET_PROPERTY, },
|
|
339
|
-
},
|
|
340
|
-
};
|
|
341
|
-
const getActiveDocumentHandler = async (_args) => {
|
|
342
|
-
try {
|
|
343
|
-
const response = await wps_client_1.wpsClient.executeMethod('getActiveDocument', {}, wps_1.WpsAppType.WRITER);
|
|
344
|
-
if (response.success && response.data) {
|
|
345
|
-
const d = response.data;
|
|
346
|
-
return {
|
|
347
|
-
id: (0, uuid_1.v4)(),
|
|
348
|
-
success: true,
|
|
349
|
-
content: [{ type: 'text', text: `当前文档: ${d.name}\n路径: ${d.path}\n页数: ${d.pageCount}\n字数: ${d.wordCount}` }],
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
return {
|
|
353
|
-
id: (0, uuid_1.v4)(),
|
|
354
|
-
success: false,
|
|
355
|
-
content: [{ type: 'text', text: `获取文档信息失败: ${response.error}` }],
|
|
356
|
-
error: response.error,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
catch (error) {
|
|
360
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
361
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `获取文档信息出错: ${errMsg}` }], error: errMsg };
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
exports.getActiveDocumentHandler = getActiveDocumentHandler;
|
|
365
226
|
/**
|
|
366
227
|
* 在文档中插入图片
|
|
367
228
|
*/
|
|
@@ -397,48 +258,17 @@ exports.insertImageDefinition = {
|
|
|
397
258
|
const insertImageHandler = async (args) => {
|
|
398
259
|
const { imagePath, width, height } = args;
|
|
399
260
|
if (!imagePath || imagePath.trim() === '') {
|
|
400
|
-
return
|
|
401
|
-
id: (0, uuid_1.v4)(),
|
|
402
|
-
success: false,
|
|
403
|
-
content: [{ type: 'text', text: '图片路径不能为空!' }],
|
|
404
|
-
error: '图片路径为空',
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
try {
|
|
408
|
-
// 参数对齐:底层优先读取 params.path,同时保留 imagePath/filePath
|
|
409
|
-
const response = await wps_client_1.wpsClient.executeMethod('insertImage', { imagePath, path: imagePath, filePath: imagePath, width, height }, wps_1.WpsAppType.WRITER);
|
|
410
|
-
if (response.success) {
|
|
411
|
-
return {
|
|
412
|
-
id: (0, uuid_1.v4)(),
|
|
413
|
-
success: true,
|
|
414
|
-
content: [
|
|
415
|
-
{
|
|
416
|
-
type: 'text',
|
|
417
|
-
text: `图片插入成功!\n路径: ${imagePath}${width ? `\n宽度: ${width}磅` : ''}${height ? `\n高度: ${height}磅` : ''}`,
|
|
418
|
-
},
|
|
419
|
-
],
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
return {
|
|
423
|
-
id: (0, uuid_1.v4)(),
|
|
424
|
-
success: false,
|
|
425
|
-
content: [{ type: 'text', text: `插入图片失败: ${response.error}` }],
|
|
426
|
-
error: response.error,
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
catch (error) {
|
|
430
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
431
|
-
return {
|
|
432
|
-
id: (0, uuid_1.v4)(),
|
|
433
|
-
success: false,
|
|
434
|
-
content: [{ type: 'text', text: `插入图片出错: ${errMsg}` }],
|
|
435
|
-
error: errMsg,
|
|
436
|
-
};
|
|
261
|
+
return (0, helpers_1.fail)('图片路径不能为空!', '图片路径为空');
|
|
437
262
|
}
|
|
263
|
+
// 只发 path:PS 侧读这个键(imagePath/filePath 双键是历史垫片,param-shape 清理)
|
|
264
|
+
const r = await (0, helpers_1.call)('insertImage', { path: imagePath, width, height });
|
|
265
|
+
if (!r.ok)
|
|
266
|
+
return (0, helpers_1.fail)(`插入图片失败: ${r.error}`, r.error);
|
|
267
|
+
return (0, helpers_1.ok)(`图片插入成功!\n路径: ${imagePath}${width ? `\n宽度: ${width}磅` : ''}${height ? `\n高度: ${height}磅` : ''}`, r.warnings);
|
|
438
268
|
};
|
|
439
269
|
exports.insertImageHandler = insertImageHandler;
|
|
440
270
|
/**
|
|
441
|
-
*
|
|
271
|
+
* 在文档光标位置插入分页符
|
|
442
272
|
*/
|
|
443
273
|
exports.insertPageBreakDefinition = {
|
|
444
274
|
name: 'wps_word_insert_page_break',
|
|
@@ -451,51 +281,12 @@ exports.insertPageBreakDefinition = {
|
|
|
451
281
|
},
|
|
452
282
|
};
|
|
453
283
|
const insertPageBreakHandler = async (_args) => {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
return
|
|
457
|
-
|
|
458
|
-
success: response.success,
|
|
459
|
-
content: [{ type: 'text', text: response.success ? '分页符已插入' : response.data?.message || '插入失败' }],
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
catch (e) {
|
|
463
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `插入分页符出错: ${e.message}` }], error: e.message };
|
|
464
|
-
}
|
|
284
|
+
const r = await (0, helpers_1.call)('insertPageBreak', {});
|
|
285
|
+
if (!r.ok)
|
|
286
|
+
return (0, helpers_1.fail)('插入分页符失败', r.error);
|
|
287
|
+
return (0, helpers_1.ok)('分页符已插入', r.warnings);
|
|
465
288
|
};
|
|
466
289
|
exports.insertPageBreakHandler = insertPageBreakHandler;
|
|
467
|
-
exports.setFontStyleDefinition = {
|
|
468
|
-
name: 'wps_word_set_font_style',
|
|
469
|
-
description: '[DEPRECATED·改用 wps_word_set_font] 设置选中文字的字体样式属性\n\n' +
|
|
470
|
-
'什么时候用:已被 wps_word_set_font 取代(同一个 setFont 动作),' +
|
|
471
|
-
'旧参数是 fontName/fontSize,新工具用 font_name/font_size,而且多了 range/color/underline —— 别两个混着用。',
|
|
472
|
-
category: tools_1.ToolCategory.DOCUMENT,
|
|
473
|
-
inputSchema: {
|
|
474
|
-
type: 'object',
|
|
475
|
-
properties: {
|
|
476
|
-
target: target_1.WORD_TARGET_PROPERTY,
|
|
477
|
-
fontName: { type: 'string', description: '字体名称' },
|
|
478
|
-
fontSize: { type: 'number', description: '字号' },
|
|
479
|
-
bold: { type: 'boolean', description: '是否加粗' },
|
|
480
|
-
italic: { type: 'boolean', description: '是否斜体' },
|
|
481
|
-
},
|
|
482
|
-
required: [],
|
|
483
|
-
},
|
|
484
|
-
};
|
|
485
|
-
const setFontStyleHandler = async (args) => {
|
|
486
|
-
try {
|
|
487
|
-
const response = await wps_client_1.wpsClient.executeMethod('setFont', args, wps_1.WpsAppType.WRITER);
|
|
488
|
-
return {
|
|
489
|
-
id: (0, uuid_1.v4)(),
|
|
490
|
-
success: response.success,
|
|
491
|
-
content: [{ type: 'text', text: response.success ? '字体已设置' : response.data?.message || '设置失败' }],
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
catch (e) {
|
|
495
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `设置字体出错: ${e.message}` }], error: e.message };
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
exports.setFontStyleHandler = setFontStyleHandler;
|
|
499
290
|
/**
|
|
500
291
|
* 插入批注到文档选中内容
|
|
501
292
|
*/
|
|
@@ -515,19 +306,12 @@ exports.insertCommentDefinition = {
|
|
|
515
306
|
const insertCommentHandler = async (args) => {
|
|
516
307
|
const { text } = args;
|
|
517
308
|
if (!text || text.trim() === '') {
|
|
518
|
-
return
|
|
519
|
-
}
|
|
520
|
-
try {
|
|
521
|
-
const response = await wps_client_1.wpsClient.executeMethod('addComment', { text }, wps_1.WpsAppType.WRITER);
|
|
522
|
-
return {
|
|
523
|
-
id: (0, uuid_1.v4)(),
|
|
524
|
-
success: response.success,
|
|
525
|
-
content: [{ type: 'text', text: response.success ? '批注已插入' : response.data?.message || '插入失败' }],
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
catch (e) {
|
|
529
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `插入批注出错: ${e.message}` }], error: e.message };
|
|
309
|
+
return (0, helpers_1.fail)('批注内容不能为空!', '批注内容为空');
|
|
530
310
|
}
|
|
311
|
+
const r = await (0, helpers_1.call)('addComment', { text });
|
|
312
|
+
if (!r.ok)
|
|
313
|
+
return (0, helpers_1.fail)((0, helpers_1.errText)('插入批注失败', r), r.error);
|
|
314
|
+
return (0, helpers_1.ok)('批注已插入', r.warnings);
|
|
531
315
|
};
|
|
532
316
|
exports.insertCommentHandler = insertCommentHandler;
|
|
533
317
|
/**
|
|
@@ -558,30 +342,19 @@ exports.setTextColorDefinition = {
|
|
|
558
342
|
const setTextColorHandler = async (args) => {
|
|
559
343
|
const { color, range } = args;
|
|
560
344
|
if (!color || color.trim() === '') {
|
|
561
|
-
return
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `设置文字颜色失败: ${msg}` }], error: msg };
|
|
575
|
-
}
|
|
576
|
-
return {
|
|
577
|
-
id: (0, uuid_1.v4)(),
|
|
578
|
-
success: true,
|
|
579
|
-
content: [{ type: 'text', text: `文字颜色已设置为 ${color}` }],
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
catch (e) {
|
|
583
|
-
return { id: (0, uuid_1.v4)(), success: false, content: [{ type: 'text', text: `设置文字颜色出错: ${e.message}` }], error: e.message };
|
|
584
|
-
}
|
|
345
|
+
return (0, helpers_1.fail)('颜色值不能为空!', '颜色值为空');
|
|
346
|
+
}
|
|
347
|
+
// 第 1 期第 2 章第 1 轮修:原先调 'setTextColor',而 wps-com.ps1 里【没有这个动作】
|
|
348
|
+
// (零命中)→ 每次调用都落到分发器的 default 分支报 Unknown action,工具等于从未生效。
|
|
349
|
+
// 能力本来就在 setFont 上(wps-com.ps1:3839),且参数名 color 两边一致,
|
|
350
|
+
// 所以只改动作名,PS 侧一行都不动。
|
|
351
|
+
const r = await (0, helpers_1.call)('setFont', { color, range: range || 'selection' });
|
|
352
|
+
if (!r.ok) {
|
|
353
|
+
// PS 的失败信息在顶层 error 上,不在 data.message 里 —— 原来读错字段,
|
|
354
|
+
// 失败时只显示"设置失败",把真正的原因(Unknown action 之类)吞掉。
|
|
355
|
+
return (0, helpers_1.fail)(`设置文字颜色失败: ${r.error ?? '设置失败'}`, r.error);
|
|
356
|
+
}
|
|
357
|
+
return (0, helpers_1.ok)(`文字颜色已设置为 ${color}`, r.warnings);
|
|
585
358
|
};
|
|
586
359
|
exports.setTextColorHandler = setTextColorHandler;
|
|
587
360
|
/**
|
|
@@ -613,38 +386,17 @@ exports.getParagraphsDefinition = {
|
|
|
613
386
|
};
|
|
614
387
|
const getParagraphsHandler = async (args) => {
|
|
615
388
|
const { start_paragraph, end_paragraph } = args;
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
id: (0, uuid_1.v4)(),
|
|
628
|
-
success: true,
|
|
629
|
-
content: [{ type: 'text', text: `文档段落结构(共${totalCount}段,返回${returnedCount}段):\n${lines.join('\n')}` }],
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
return {
|
|
633
|
-
id: (0, uuid_1.v4)(),
|
|
634
|
-
success: false,
|
|
635
|
-
content: [{ type: 'text', text: `获取段落结构失败: ${response.error}` }],
|
|
636
|
-
error: response.error,
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
catch (error) {
|
|
640
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
641
|
-
return {
|
|
642
|
-
id: (0, uuid_1.v4)(),
|
|
643
|
-
success: false,
|
|
644
|
-
content: [{ type: 'text', text: `获取段落结构出错: ${errMsg}` }],
|
|
645
|
-
error: errMsg,
|
|
646
|
-
};
|
|
647
|
-
}
|
|
389
|
+
const execParams = {};
|
|
390
|
+
if (start_paragraph != null)
|
|
391
|
+
execParams.startParagraph = start_paragraph;
|
|
392
|
+
if (end_paragraph != null)
|
|
393
|
+
execParams.endParagraph = end_paragraph;
|
|
394
|
+
const r = await (0, helpers_1.call)('getDocumentParagraphs', execParams);
|
|
395
|
+
if (!r.ok)
|
|
396
|
+
return (0, helpers_1.fail)(`获取段落结构失败: ${r.error}`, r.error);
|
|
397
|
+
const { paragraphs, totalCount, returnedCount } = r.data;
|
|
398
|
+
const lines = paragraphs.map((p) => `[${p.index}] (${p.style}) ${p.text}`);
|
|
399
|
+
return (0, helpers_1.ok)(`文档段落结构(共${totalCount}段,返回${returnedCount}段):\n${lines.join('\n')}`, r.warnings);
|
|
648
400
|
};
|
|
649
401
|
exports.getParagraphsHandler = getParagraphsHandler;
|
|
650
402
|
/**
|
|
@@ -678,48 +430,22 @@ exports.findInDocumentDefinition = {
|
|
|
678
430
|
const findInDocumentHandler = async (args) => {
|
|
679
431
|
const { find_text, match_case, match_whole_word, max_results } = args;
|
|
680
432
|
if (!find_text || find_text.trim() === '') {
|
|
681
|
-
return
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (count === 0) {
|
|
698
|
-
return { id: (0, uuid_1.v4)(), success: true, content: [{ type: 'text', text: `未找到 "${findText}"` }] };
|
|
699
|
-
}
|
|
700
|
-
const lines = results.map((r) => ` 段落${r.paragraphIndex} [${r.start}-${r.end}]: ...${r.context}...`);
|
|
701
|
-
return {
|
|
702
|
-
id: (0, uuid_1.v4)(),
|
|
703
|
-
success: true,
|
|
704
|
-
content: [{ type: 'text', text: `找到 "${findText}" 共${count}处:\n${lines.join('\n')}` }],
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
return {
|
|
708
|
-
id: (0, uuid_1.v4)(),
|
|
709
|
-
success: false,
|
|
710
|
-
content: [{ type: 'text', text: `查找失败: ${response.error}` }],
|
|
711
|
-
error: response.error,
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
catch (error) {
|
|
715
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
716
|
-
return {
|
|
717
|
-
id: (0, uuid_1.v4)(),
|
|
718
|
-
success: false,
|
|
719
|
-
content: [{ type: 'text', text: `查找出错: ${errMsg}` }],
|
|
720
|
-
error: errMsg,
|
|
721
|
-
};
|
|
722
|
-
}
|
|
433
|
+
return (0, helpers_1.fail)('查找文本不能为空!', '查找文本为空');
|
|
434
|
+
}
|
|
435
|
+
const r = await (0, helpers_1.call)('findInDocument', {
|
|
436
|
+
findText: find_text,
|
|
437
|
+
matchCase: match_case || false,
|
|
438
|
+
matchWholeWord: match_whole_word || false,
|
|
439
|
+
maxResults: max_results || 20,
|
|
440
|
+
});
|
|
441
|
+
if (!r.ok)
|
|
442
|
+
return (0, helpers_1.fail)(`查找失败: ${r.error}`, r.error);
|
|
443
|
+
const { results, count, findText: ft } = r.data;
|
|
444
|
+
if (count === 0) {
|
|
445
|
+
return (0, helpers_1.ok)(`未找到 "${ft}"`, r.warnings);
|
|
446
|
+
}
|
|
447
|
+
const lines = results.map((x) => ` 段落${x.paragraphIndex} [${x.start}-${x.end}]: ...${x.context}...`);
|
|
448
|
+
return (0, helpers_1.ok)(`找到 "${ft}" 共${count}处:\n${lines.join('\n')}`, r.warnings);
|
|
723
449
|
};
|
|
724
450
|
exports.findInDocumentHandler = findInDocumentHandler;
|
|
725
451
|
/**
|
|
@@ -763,37 +489,16 @@ exports.smartFillFieldDefinition = {
|
|
|
763
489
|
const smartFillFieldHandler = async (args) => {
|
|
764
490
|
const { keyword, value, fill_mode } = args;
|
|
765
491
|
if (!keyword || keyword.trim() === '') {
|
|
766
|
-
return
|
|
492
|
+
return (0, helpers_1.fail)('关键字不能为空!', '关键字为空');
|
|
767
493
|
}
|
|
768
494
|
if (value == null) {
|
|
769
|
-
return
|
|
770
|
-
}
|
|
771
|
-
try {
|
|
772
|
-
const response = await wps_client_1.wpsClient.executeMethod('smartFillField', { keyword, value, fillMode: fill_mode || 'auto' }, wps_1.WpsAppType.WRITER);
|
|
773
|
-
if (response.success && response.data) {
|
|
774
|
-
const { fillMode, result } = response.data;
|
|
775
|
-
return {
|
|
776
|
-
id: (0, uuid_1.v4)(),
|
|
777
|
-
success: true,
|
|
778
|
-
content: [{ type: 'text', text: `填写完成!\n关键字: "${keyword}"\n填写值: "${value}"\n填写模式: ${fillMode}\n结果: ${result}` }],
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
return {
|
|
782
|
-
id: (0, uuid_1.v4)(),
|
|
783
|
-
success: false,
|
|
784
|
-
content: [{ type: 'text', text: `填写失败: ${response.error}` }],
|
|
785
|
-
error: response.error,
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
catch (error) {
|
|
789
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
790
|
-
return {
|
|
791
|
-
id: (0, uuid_1.v4)(),
|
|
792
|
-
success: false,
|
|
793
|
-
content: [{ type: 'text', text: `填写出错: ${errMsg}` }],
|
|
794
|
-
error: errMsg,
|
|
795
|
-
};
|
|
495
|
+
return (0, helpers_1.fail)('填写值不能为空(空字符串将清除该字段内容)', '填写值为空');
|
|
796
496
|
}
|
|
497
|
+
const r = await (0, helpers_1.call)('smartFillField', { keyword, value, fillMode: fill_mode || 'auto' });
|
|
498
|
+
if (!r.ok)
|
|
499
|
+
return (0, helpers_1.fail)(`填写失败: ${r.error}`, r.error);
|
|
500
|
+
const { fillMode, result } = r.data;
|
|
501
|
+
return (0, helpers_1.ok)(`填写完成!\n关键字: "${keyword}"\n填写值: "${value}"\n填写模式: ${fillMode}\n结果: ${result}`, r.warnings);
|
|
797
502
|
};
|
|
798
503
|
exports.smartFillFieldHandler = smartFillFieldHandler;
|
|
799
504
|
/**
|
|
@@ -823,36 +528,15 @@ exports.replaceBookmarkContentDefinition = {
|
|
|
823
528
|
const replaceBookmarkContentHandler = async (args) => {
|
|
824
529
|
const { name, text } = args;
|
|
825
530
|
if (!name || name.trim() === '') {
|
|
826
|
-
return
|
|
531
|
+
return (0, helpers_1.fail)('书签名称不能为空!', '书签名称为空');
|
|
827
532
|
}
|
|
828
533
|
if (text == null) {
|
|
829
|
-
return
|
|
830
|
-
}
|
|
831
|
-
try {
|
|
832
|
-
const response = await wps_client_1.wpsClient.executeMethod('replaceBookmarkContent', { name, text }, wps_1.WpsAppType.WRITER);
|
|
833
|
-
if (response.success && response.data) {
|
|
834
|
-
return {
|
|
835
|
-
id: (0, uuid_1.v4)(),
|
|
836
|
-
success: true,
|
|
837
|
-
content: [{ type: 'text', text: `书签内容替换完成!\n书签: "${name}"\n新内容: "${text}"` }],
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
return {
|
|
841
|
-
id: (0, uuid_1.v4)(),
|
|
842
|
-
success: false,
|
|
843
|
-
content: [{ type: 'text', text: `替换书签内容失败: ${response.error}` }],
|
|
844
|
-
error: response.error,
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
catch (error) {
|
|
848
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
849
|
-
return {
|
|
850
|
-
id: (0, uuid_1.v4)(),
|
|
851
|
-
success: false,
|
|
852
|
-
content: [{ type: 'text', text: `替换书签内容出错: ${errMsg}` }],
|
|
853
|
-
error: errMsg,
|
|
854
|
-
};
|
|
534
|
+
return (0, helpers_1.fail)('替换文本不能为空(空字符串将清空书签)', '替换文本为空');
|
|
855
535
|
}
|
|
536
|
+
const r = await (0, helpers_1.call)('replaceBookmarkContent', { name, text });
|
|
537
|
+
if (!r.ok)
|
|
538
|
+
return (0, helpers_1.fail)(`替换书签内容失败: ${r.error}`, r.error);
|
|
539
|
+
return (0, helpers_1.ok)(`书签内容替换完成!\n书签: "${name}"\n新内容: "${text}"`, r.warnings);
|
|
856
540
|
};
|
|
857
541
|
exports.replaceBookmarkContentHandler = replaceBookmarkContentHandler;
|
|
858
542
|
exports.contentTools = [
|
|
@@ -860,10 +544,8 @@ exports.contentTools = [
|
|
|
860
544
|
{ definition: exports.findReplaceDefinition, handler: exports.findReplaceHandler },
|
|
861
545
|
{ definition: exports.insertTableDefinition, handler: exports.insertTableHandler },
|
|
862
546
|
{ definition: exports.setParagraphDefinition, handler: exports.setParagraphHandler },
|
|
863
|
-
{ definition: exports.getActiveDocumentDefinition, handler: exports.getActiveDocumentHandler },
|
|
864
547
|
{ definition: exports.insertImageDefinition, handler: exports.insertImageHandler },
|
|
865
548
|
{ definition: exports.insertPageBreakDefinition, handler: exports.insertPageBreakHandler },
|
|
866
|
-
{ definition: exports.setFontStyleDefinition, handler: exports.setFontStyleHandler },
|
|
867
549
|
{ definition: exports.insertCommentDefinition, handler: exports.insertCommentHandler },
|
|
868
550
|
{ definition: exports.setTextColorDefinition, handler: exports.setTextColorHandler },
|
|
869
551
|
{ definition: exports.getParagraphsDefinition, handler: exports.getParagraphsHandler },
|