deepfish-ai 1.0.28 → 2.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.
Files changed (62) hide show
  1. package/README.md +126 -368
  2. package/dist/index.js +23320 -0
  3. package/dist/serve/client/assets/index-DUHYC91l.js +1 -0
  4. package/dist/serve/client/assets/index-zcrdNLZs.css +1 -0
  5. package/dist/serve/client/index.html +14 -0
  6. package/dist/serve/pm2-server.js +21015 -0
  7. package/dist/serve/server/entry-server.mjs +224 -0
  8. package/package.json +50 -70
  9. package/LICENSE +0 -21
  10. package/README_CN.md +0 -460
  11. package/src/AgentRobot/AgentRobotFactory/MainAgentRobot.js +0 -88
  12. package/src/AgentRobot/AgentRobotFactory/SubAgentRobot.js +0 -45
  13. package/src/AgentRobot/AgentRobotFactory/SubSkillAgentRobot.js +0 -45
  14. package/src/AgentRobot/AgentRobotFactory/index.js +0 -48
  15. package/src/AgentRobot/BaseAgentRobot/Brain.js +0 -210
  16. package/src/AgentRobot/BaseAgentRobot/BrainEvent.js +0 -17
  17. package/src/AgentRobot/BaseAgentRobot/Hand.js +0 -119
  18. package/src/AgentRobot/BaseAgentRobot/Heart.js +0 -0
  19. package/src/AgentRobot/BaseAgentRobot/Logger.js +0 -114
  20. package/src/AgentRobot/BaseAgentRobot/ScreenPrinter.js +0 -49
  21. package/src/AgentRobot/BaseAgentRobot/index.js +0 -266
  22. package/src/AgentRobot/BaseAgentRobot/lazy-tools/AliBailian.js +0 -997
  23. package/src/AgentRobot/BaseAgentRobot/lazy-tools/doc-transform.js +0 -204
  24. package/src/AgentRobot/BaseAgentRobot/lazy-tools/docx.js +0 -1286
  25. package/src/AgentRobot/BaseAgentRobot/lazy-tools/img.js +0 -765
  26. package/src/AgentRobot/BaseAgentRobot/lazy-tools/pdf.js +0 -736
  27. package/src/AgentRobot/BaseAgentRobot/lazy-tools/pptx.js +0 -567
  28. package/src/AgentRobot/BaseAgentRobot/lazy-tools/video.js +0 -36
  29. package/src/AgentRobot/BaseAgentRobot/lazy-tools/xlsx.js +0 -611
  30. package/src/AgentRobot/BaseAgentRobot/tools/BaseTools.js +0 -13
  31. package/src/AgentRobot/BaseAgentRobot/tools/CreateAgentTools.js +0 -158
  32. package/src/AgentRobot/BaseAgentRobot/tools/FileTools.js +0 -768
  33. package/src/AgentRobot/BaseAgentRobot/tools/GenerateTools.js +0 -441
  34. package/src/AgentRobot/BaseAgentRobot/tools/InquirerTools.js +0 -244
  35. package/src/AgentRobot/BaseAgentRobot/tools/SystemTools.js +0 -263
  36. package/src/AgentRobot/BaseAgentRobot/tools/TaskTools.js +0 -211
  37. package/src/AgentRobot/BaseAgentRobot/tools/TestTools.js +0 -100
  38. package/src/AgentRobot/BaseAgentRobot/tools/UserTool.js +0 -87
  39. package/src/AgentRobot/BaseAgentRobot/tools/WebTools.js +0 -257
  40. package/src/AgentRobot/BaseAgentRobot/utils/AIRequest.js +0 -297
  41. package/src/AgentRobot/BaseAgentRobot/utils/AIToolManager.js +0 -131
  42. package/src/AgentRobot/BaseAgentRobot/utils/AgentTree.js +0 -66
  43. package/src/AgentRobot/BaseAgentRobot/utils/AttachmentToolScanner.js +0 -235
  44. package/src/AgentRobot/BaseAgentRobot/utils/MessageCompresser.js +0 -236
  45. package/src/AgentRobot/BaseAgentRobot/utils/aiConsole.js +0 -74
  46. package/src/AgentRobot/BaseAgentRobot/utils/aiInquirer.js +0 -78
  47. package/src/AgentRobot/BaseAgentRobot/utils/analyzeReturn.test.js +0 -104
  48. package/src/AgentRobot/BaseAgentRobot/utils/copilot.js +0 -117
  49. package/src/AgentRobot/BaseAgentRobot/utils/node-root.js +0 -138
  50. package/src/AgentRobot/BaseAgentRobot/utils/normal.js +0 -399
  51. package/src/cli/ConfigManager.js +0 -283
  52. package/src/cli/DefaultConfig.js +0 -98
  53. package/src/cli/GlobalVariable.js +0 -8
  54. package/src/cli/MemoryManager.js +0 -53
  55. package/src/cli/SkillConfigManager.js +0 -343
  56. package/src/cli/SkillParser.js +0 -58
  57. package/src/cli/ai-auth.js +0 -231
  58. package/src/cli/ai-config.js +0 -225
  59. package/src/cli/ai-memory.js +0 -22
  60. package/src/cli/ai-skill.js +0 -65
  61. package/src/cli/index.js +0 -77
  62. package/src/index.js +0 -54
@@ -1,611 +0,0 @@
1
- /**
2
- * @Author: Roman 306863030@qq.com
3
- * @Description: Excel/XLSX 文档处理工具集(xlsx / SheetJS)
4
- */
5
- const path = require('path')
6
- const fs = require('fs-extra')
7
- const XLSX = require('xlsx')
8
-
9
- // ─── 统一返回结构 ─────────────────────────────────────────────────────────────
10
-
11
- function ok(data = null) {
12
- return { success: true, data }
13
- }
14
-
15
- function fail(error, data = null) {
16
- return { success: false, error: error?.message || String(error), data }
17
- }
18
-
19
- function resolvePath(filePath) {
20
- return path.resolve(process.cwd(), filePath)
21
- }
22
-
23
- // ─── 工具函数 ─────────────────────────────────────────────────────────────────
24
-
25
- function xlsxReadme() {
26
- return `【XLSX 工具使用说明】
27
- 1. 优先使用本工具内置函数完成任务(读取、写入、搜索、合并、CSV 互转等)。
28
- 2. 如果内置函数无法满足需求(如复杂格式保真、特殊公式处理、跨格式高级转换),再尝试使用 LibreOffice 命令行。
29
- 3. 在调用 LibreOffice 前,先检测系统是否已安装 LibreOffice:
30
- - 已安装:直接使用 LibreOffice 命令行继续处理。
31
- - 未安装:询问用户是否允许安装。
32
- 4. 若用户同意安装:引导完成安装后继续执行原任务。
33
- 5. 若用户拒绝安装:明确告知当前能力限制,并终止该操作。
34
-
35
- 建议:
36
- - 简单与结构化数据处理优先使用内置函数,速度更快且依赖更少。
37
- - 仅在确实需要高保真格式转换时才启用 LibreOffice 路径。`
38
- }
39
-
40
- /**
41
- * 获取 XLSX 文件基本信息(工作表名称、行列数等)
42
- */
43
- async function getXlsxInfo(filePath) {
44
- try {
45
- const fullPath = resolvePath(filePath)
46
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
47
- const workbook = XLSX.readFile(fullPath)
48
- const stat = fs.statSync(fullPath)
49
- const sheets = workbook.SheetNames.map((name) => {
50
- const ws = workbook.Sheets[name]
51
- const range = XLSX.utils.decode_range(ws['!ref'] || 'A1:A1')
52
- return {
53
- name,
54
- rows: range.e.r - range.s.r + 1,
55
- cols: range.e.c - range.s.c + 1,
56
- }
57
- })
58
- return ok({
59
- filePath: fullPath,
60
- size: stat.size,
61
- mtime: stat.mtime,
62
- sheetCount: workbook.SheetNames.length,
63
- sheets,
64
- })
65
- } catch (error) {
66
- return fail(error, { filePath })
67
- }
68
- }
69
-
70
- /**
71
- * 获取所有工作表名称列表
72
- */
73
- async function getSheetNames(filePath) {
74
- try {
75
- const fullPath = resolvePath(filePath)
76
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
77
- const workbook = XLSX.readFile(fullPath)
78
- return ok({ filePath: fullPath, sheetNames: workbook.SheetNames })
79
- } catch (error) {
80
- return fail(error, { filePath })
81
- }
82
- }
83
-
84
- /**
85
- * 读取指定工作表为 JSON 数组(第一行作为 header)
86
- */
87
- async function readSheet(filePath, sheetName) {
88
- try {
89
- const fullPath = resolvePath(filePath)
90
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
91
- const workbook = XLSX.readFile(fullPath)
92
- const name = sheetName || workbook.SheetNames[0]
93
- if (!workbook.Sheets[name]) return fail(`Sheet "${name}" not found`, { filePath: fullPath, sheetName: name })
94
- const ws = workbook.Sheets[name]
95
- const data = XLSX.utils.sheet_to_json(ws, { defval: '' })
96
- const range = XLSX.utils.decode_range(ws['!ref'] || 'A1:A1')
97
- return ok({
98
- filePath: fullPath,
99
- sheetName: name,
100
- rowCount: data.length,
101
- colCount: range.e.c - range.s.c + 1,
102
- data,
103
- })
104
- } catch (error) {
105
- return fail(error, { filePath, sheetName })
106
- }
107
- }
108
-
109
- /**
110
- * 读取指定工作表为二维数组(不解析 header)
111
- */
112
- async function readSheetRaw(filePath, sheetName) {
113
- try {
114
- const fullPath = resolvePath(filePath)
115
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
116
- const workbook = XLSX.readFile(fullPath)
117
- const name = sheetName || workbook.SheetNames[0]
118
- if (!workbook.Sheets[name]) return fail(`Sheet "${name}" not found`, { filePath: fullPath, sheetName: name })
119
- const ws = workbook.Sheets[name]
120
- const data = XLSX.utils.sheet_to_json(ws, { header: 1, defval: '' })
121
- return ok({ filePath: fullPath, sheetName: name, rowCount: data.length, data })
122
- } catch (error) {
123
- return fail(error, { filePath, sheetName })
124
- }
125
- }
126
-
127
- /**
128
- * 读取全部工作表,返回 { sheetName: jsonArray } 对象
129
- */
130
- async function readAllSheets(filePath) {
131
- try {
132
- const fullPath = resolvePath(filePath)
133
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
134
- const workbook = XLSX.readFile(fullPath)
135
- const result = {}
136
- for (const name of workbook.SheetNames) {
137
- result[name] = XLSX.utils.sheet_to_json(workbook.Sheets[name], { defval: '' })
138
- }
139
- return ok({ filePath: fullPath, sheetCount: workbook.SheetNames.length, sheets: result })
140
- } catch (error) {
141
- return fail(error, { filePath })
142
- }
143
- }
144
-
145
- /**
146
- * 将 JSON 数据写入新 XLSX 文件(可指定多个 sheet)
147
- * sheetsData 格式:[ { name, data: [{},...] } ] 或 [ { name, data: [[...]], isRaw: true } ]
148
- */
149
- async function writeXlsx(outputPath, sheetsData = [], options = {}) {
150
- try {
151
- const fullOutput = resolvePath(outputPath)
152
- fs.ensureDirSync(path.dirname(fullOutput))
153
- const workbook = XLSX.utils.book_new()
154
- for (const sheetDef of sheetsData) {
155
- const name = sheetDef.name || 'Sheet1'
156
- const ws = sheetDef.isRaw
157
- ? XLSX.utils.aoa_to_sheet(sheetDef.data || [[]])
158
- : XLSX.utils.json_to_sheet(sheetDef.data || [], { skipHeader: sheetDef.skipHeader })
159
- XLSX.utils.book_append_sheet(workbook, ws, name)
160
- }
161
- XLSX.writeFile(workbook, fullOutput, { bookType: options.bookType || 'xlsx' })
162
- return ok({ outputPath: fullOutput, sheetCount: sheetsData.length })
163
- } catch (error) {
164
- return fail(error, { outputPath })
165
- }
166
- }
167
-
168
- /**
169
- * 向已有 XLSX 的指定 sheet 末尾追加行数据
170
- */
171
- async function appendRows(filePath, rows = [], sheetName) {
172
- try {
173
- const fullPath = resolvePath(filePath)
174
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
175
- const workbook = XLSX.readFile(fullPath)
176
- const name = sheetName || workbook.SheetNames[0]
177
- if (!workbook.Sheets[name]) return fail(`Sheet "${name}" not found`, { filePath: fullPath, sheetName: name })
178
- const ws = workbook.Sheets[name]
179
- XLSX.utils.sheet_add_json(ws, rows, { skipHeader: true, origin: -1 })
180
- XLSX.writeFile(workbook, fullPath)
181
- return ok({ filePath: fullPath, sheetName: name, appendedRows: rows.length })
182
- } catch (error) {
183
- return fail(error, { filePath, sheetName })
184
- }
185
- }
186
-
187
- /**
188
- * 在 XLSX 的指定 sheet 中搜索关键词,返回匹配的单元格位置
189
- */
190
- async function searchXlsx(filePath, keyword, sheetName) {
191
- try {
192
- const fullPath = resolvePath(filePath)
193
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
194
- const workbook = XLSX.readFile(fullPath)
195
- const targetSheets = sheetName ? [sheetName] : workbook.SheetNames
196
- const matches = []
197
- for (const name of targetSheets) {
198
- const ws = workbook.Sheets[name]
199
- if (!ws) continue
200
- for (const cellAddr of Object.keys(ws)) {
201
- if (cellAddr.startsWith('!')) continue
202
- const cell = ws[cellAddr]
203
- const val = String(cell.v ?? '')
204
- if (val.includes(keyword)) {
205
- matches.push({ sheet: name, cell: cellAddr, value: val })
206
- }
207
- }
208
- }
209
- return ok({ filePath: fullPath, keyword, matchCount: matches.length, matches })
210
- } catch (error) {
211
- return fail(error, { filePath, keyword, sheetName })
212
- }
213
- }
214
-
215
- /**
216
- * 删除 XLSX 中的指定工作表
217
- */
218
- async function deleteSheet(filePath, sheetName) {
219
- try {
220
- const fullPath = resolvePath(filePath)
221
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
222
- const workbook = XLSX.readFile(fullPath)
223
- if (!workbook.Sheets[sheetName]) return fail(`Sheet "${sheetName}" not found`, { filePath: fullPath, sheetName })
224
- const idx = workbook.SheetNames.indexOf(sheetName)
225
- workbook.SheetNames.splice(idx, 1)
226
- delete workbook.Sheets[sheetName]
227
- XLSX.writeFile(workbook, fullPath)
228
- return ok({ filePath: fullPath, deletedSheet: sheetName, remainingSheets: workbook.SheetNames })
229
- } catch (error) {
230
- return fail(error, { filePath, sheetName })
231
- }
232
- }
233
-
234
- /**
235
- * 重命名工作表
236
- */
237
- async function renameSheet(filePath, oldName, newName) {
238
- try {
239
- const fullPath = resolvePath(filePath)
240
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
241
- const workbook = XLSX.readFile(fullPath)
242
- if (!workbook.Sheets[oldName]) return fail(`Sheet "${oldName}" not found`, { filePath: fullPath, oldName })
243
- const idx = workbook.SheetNames.indexOf(oldName)
244
- workbook.SheetNames[idx] = newName
245
- workbook.Sheets[newName] = workbook.Sheets[oldName]
246
- delete workbook.Sheets[oldName]
247
- XLSX.writeFile(workbook, fullPath)
248
- return ok({ filePath: fullPath, oldName, newName })
249
- } catch (error) {
250
- return fail(error, { filePath, oldName, newName })
251
- }
252
- }
253
-
254
- /**
255
- * 合并多个 XLSX 文件为一个(各文件的 sheet 合并到新文件中)
256
- */
257
- async function mergeXlsx(inputPaths, outputPath) {
258
- try {
259
- const fullOutput = resolvePath(outputPath)
260
- fs.ensureDirSync(path.dirname(fullOutput))
261
- const newWorkbook = XLSX.utils.book_new()
262
- const usedNames = new Set()
263
- for (const inputPath of inputPaths) {
264
- const fullInput = resolvePath(inputPath)
265
- if (!fs.existsSync(fullInput)) return fail(`File does not exist: ${fullInput}`, { filePath: fullInput })
266
- const wb = XLSX.readFile(fullInput)
267
- for (let name of wb.SheetNames) {
268
- let uniqueName = name
269
- let count = 1
270
- while (usedNames.has(uniqueName)) uniqueName = `${name}_${count++}`
271
- usedNames.add(uniqueName)
272
- XLSX.utils.book_append_sheet(newWorkbook, wb.Sheets[name], uniqueName)
273
- }
274
- }
275
- XLSX.writeFile(newWorkbook, fullOutput)
276
- return ok({ outputPath: fullOutput, sheetCount: newWorkbook.SheetNames.length, sheets: newWorkbook.SheetNames })
277
- } catch (error) {
278
- return fail(error, { outputPath })
279
- }
280
- }
281
-
282
- /**
283
- * 将 XLSX 导出为 CSV 文件(指定 sheet)
284
- */
285
- async function xlsxToCsv(filePath, outputPath, sheetName) {
286
- try {
287
- const fullPath = resolvePath(filePath)
288
- const fullOutput = resolvePath(outputPath)
289
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
290
- fs.ensureDirSync(path.dirname(fullOutput))
291
- const workbook = XLSX.readFile(fullPath)
292
- const name = sheetName || workbook.SheetNames[0]
293
- if (!workbook.Sheets[name]) return fail(`Sheet "${name}" not found`, { filePath: fullPath, sheetName: name })
294
- const csv = XLSX.utils.sheet_to_csv(workbook.Sheets[name])
295
- fs.writeFileSync(fullOutput, csv, 'utf8')
296
- return ok({ filePath: fullPath, outputPath: fullOutput, sheetName: name })
297
- } catch (error) {
298
- return fail(error, { filePath, outputPath, sheetName })
299
- }
300
- }
301
-
302
- /**
303
- * 将 CSV 文件导入为 XLSX
304
- */
305
- async function csvToXlsx(inputPath, outputPath, sheetName) {
306
- try {
307
- const fullInput = resolvePath(inputPath)
308
- const fullOutput = resolvePath(outputPath)
309
- if (!fs.existsSync(fullInput)) return fail(`File does not exist: ${fullInput}`, { filePath: fullInput })
310
- fs.ensureDirSync(path.dirname(fullOutput))
311
- const csv = fs.readFileSync(fullInput, 'utf8')
312
- const workbook = XLSX.read(csv, { type: 'string' })
313
- const ws = workbook.Sheets[workbook.SheetNames[0]]
314
- const newWb = XLSX.utils.book_new()
315
- XLSX.utils.book_append_sheet(newWb, ws, sheetName || 'Sheet1')
316
- XLSX.writeFile(newWb, fullOutput)
317
- return ok({ inputPath: fullInput, outputPath: fullOutput })
318
- } catch (error) {
319
- return fail(error, { inputPath, outputPath })
320
- }
321
- }
322
-
323
- /**
324
- * 统计 XLSX 指定 sheet 的行列数及数据摘要
325
- */
326
- async function getSheetStats(filePath, sheetName) {
327
- try {
328
- const fullPath = resolvePath(filePath)
329
- if (!fs.existsSync(fullPath)) return fail(`File does not exist: ${fullPath}`, { filePath: fullPath })
330
- const workbook = XLSX.readFile(fullPath)
331
- const name = sheetName || workbook.SheetNames[0]
332
- if (!workbook.Sheets[name]) return fail(`Sheet "${name}" not found`, { filePath: fullPath, sheetName: name })
333
- const ws = workbook.Sheets[name]
334
- const data = XLSX.utils.sheet_to_json(ws, { header: 1, defval: '' })
335
- const range = XLSX.utils.decode_range(ws['!ref'] || 'A1:A1')
336
- const headers = data[0] || []
337
- const dataRows = data.slice(1)
338
- const nonEmpty = dataRows.filter((row) => row.some((c) => c !== '' && c !== null && c !== undefined))
339
- return ok({
340
- filePath: fullPath,
341
- sheetName: name,
342
- totalRows: range.e.r - range.s.r + 1,
343
- totalCols: range.e.c - range.s.c + 1,
344
- dataRows: nonEmpty.length,
345
- headers,
346
- })
347
- } catch (error) {
348
- return fail(error, { filePath, sheetName })
349
- }
350
- }
351
-
352
- // ─── 工具描述 ─────────────────────────────────────────────────────────────────
353
-
354
- const descriptions = [
355
- {
356
- type: 'function',
357
- function: {
358
- name: 'xlsxReadme',
359
- description: '获取 XLSX 工具集的使用说明, 调用函数前必须先查看本说明。',
360
- parameters: {},
361
- }
362
- },
363
- {
364
- type: 'function',
365
- function: {
366
- name: 'getXlsxInfo',
367
- description: '获取 XLSX 文件基本信息(工作表名列表、各 sheet 行列数、文件大小等)。参数:filePath 为 .xlsx 文件路径。返回值:对象,包含 success、data(含 sheetCount、sheets 数组、size、mtime)、error。',
368
- parameters: {
369
- type: 'object',
370
- properties: {
371
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
372
- },
373
- required: ['filePath'],
374
- },
375
- },
376
- },
377
- {
378
- type: 'function',
379
- function: {
380
- name: 'getSheetNames',
381
- description: '获取 XLSX 文件中所有工作表的名称列表。参数:filePath 为 .xlsx 文件路径。返回值:对象,包含 success、data(含 sheetNames 数组)、error。',
382
- parameters: {
383
- type: 'object',
384
- properties: {
385
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
386
- },
387
- required: ['filePath'],
388
- },
389
- },
390
- },
391
- {
392
- type: 'function',
393
- function: {
394
- name: 'readSheet',
395
- description: '读取 XLSX 指定工作表数据,以第一行为 header,返回 JSON 对象数组。参数:filePath 为路径;sheetName 为工作表名(省略则读第一个)。返回值:对象,包含 success、data(含 sheetName、rowCount、colCount、data 数组)、error。',
396
- parameters: {
397
- type: 'object',
398
- properties: {
399
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
400
- sheetName: { type: 'string', description: '工作表名,省略则读取第一个 sheet。' },
401
- },
402
- required: ['filePath'],
403
- },
404
- },
405
- },
406
- {
407
- type: 'function',
408
- function: {
409
- name: 'readSheetRaw',
410
- description: '读取 XLSX 指定工作表为二维数组(不解析 header)。参数:filePath 为路径;sheetName 为工作表名。返回值:对象,包含 success、data(含 sheetName、rowCount、data 二维数组)、error。',
411
- parameters: {
412
- type: 'object',
413
- properties: {
414
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
415
- sheetName: { type: 'string', description: '工作表名,省略则读取第一个。' },
416
- },
417
- required: ['filePath'],
418
- },
419
- },
420
- },
421
- {
422
- type: 'function',
423
- function: {
424
- name: 'readAllSheets',
425
- description: '读取 XLSX 文件的所有工作表,返回 { sheetName: jsonArray } 对象。参数:filePath 为路径。返回值:对象,包含 success、data(含 sheetCount、sheets 对象)、error。',
426
- parameters: {
427
- type: 'object',
428
- properties: {
429
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
430
- },
431
- required: ['filePath'],
432
- },
433
- },
434
- },
435
- {
436
- type: 'function',
437
- function: {
438
- name: 'writeXlsx',
439
- description: '将数据写入新的 XLSX 文件,支持多 sheet。参数:outputPath 为输出路径;sheetsData 为数组,每项含 name(sheet名)、data(JSON数组 或二维数组)、isRaw(是否为二维数组,默认 false);options 可选({ bookType: xlsx/csv/ods })。返回值:对象,包含 success、data(含 outputPath、sheetCount)、error。',
440
- parameters: {
441
- type: 'object',
442
- properties: {
443
- outputPath: { type: 'string', description: '输出 .xlsx 文件路径。' },
444
- sheetsData: {
445
- type: 'array',
446
- description: 'sheet 数据数组,每项:{ name, data, isRaw }。',
447
- items: { type: 'object' },
448
- },
449
- options: { type: 'object', description: '可选:{ bookType }。' },
450
- },
451
- required: ['outputPath', 'sheetsData'],
452
- },
453
- },
454
- },
455
- {
456
- type: 'function',
457
- function: {
458
- name: 'appendRows',
459
- description: '向 XLSX 指定工作表末尾追加行数据。参数:filePath 为路径;rows 为 JSON 对象数组;sheetName 为工作表名(省略则用第一个)。返回值:对象,包含 success、data(含 sheetName、appendedRows)、error。',
460
- parameters: {
461
- type: 'object',
462
- properties: {
463
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
464
- rows: { type: 'array', description: '要追加的行数据(JSON 对象数组)。', items: { type: 'object' } },
465
- sheetName: { type: 'string', description: '目标工作表名。' },
466
- },
467
- required: ['filePath', 'rows'],
468
- },
469
- },
470
- },
471
- {
472
- type: 'function',
473
- function: {
474
- name: 'searchXlsx',
475
- description: '在 XLSX 指定(或全部)sheet 中搜索关键词,返回匹配单元格位置。参数:filePath 为路径;keyword 为关键词;sheetName 为工作表名(省略则搜索全部)。返回值:对象,包含 success、data(含 keyword、matchCount、matches 数组)、error。',
476
- parameters: {
477
- type: 'object',
478
- properties: {
479
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
480
- keyword: { type: 'string', description: '搜索关键词。' },
481
- sheetName: { type: 'string', description: '要搜索的工作表名,省略则搜索全部。' },
482
- },
483
- required: ['filePath', 'keyword'],
484
- },
485
- },
486
- },
487
- {
488
- type: 'function',
489
- function: {
490
- name: 'deleteSheet',
491
- description: '删除 XLSX 中的指定工作表。参数:filePath 为路径;sheetName 为要删除的工作表名。返回值:对象,包含 success、data(含 deletedSheet、remainingSheets)、error。',
492
- parameters: {
493
- type: 'object',
494
- properties: {
495
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
496
- sheetName: { type: 'string', description: '要删除的工作表名。' },
497
- },
498
- required: ['filePath', 'sheetName'],
499
- },
500
- },
501
- },
502
- {
503
- type: 'function',
504
- function: {
505
- name: 'renameSheet',
506
- description: '重命名 XLSX 中的工作表。参数:filePath 为路径;oldName 为原工作表名;newName 为新工作表名。返回值:对象,包含 success、data(含 oldName、newName)、error。',
507
- parameters: {
508
- type: 'object',
509
- properties: {
510
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
511
- oldName: { type: 'string', description: '原工作表名。' },
512
- newName: { type: 'string', description: '新工作表名。' },
513
- },
514
- required: ['filePath', 'oldName', 'newName'],
515
- },
516
- },
517
- },
518
- {
519
- type: 'function',
520
- function: {
521
- name: 'mergeXlsx',
522
- description: '将多个 XLSX 文件合并为一个(各文件的所有 sheet 合并到新文件)。参数:inputPaths 为源文件路径数组;outputPath 为输出路径。返回值:对象,包含 success、data(含 outputPath、sheetCount、sheets)、error。',
523
- parameters: {
524
- type: 'object',
525
- properties: {
526
- inputPaths: { type: 'array', items: { type: 'string' }, description: '要合并的 XLSX 文件路径数组。' },
527
- outputPath: { type: 'string', description: '合并后输出的 XLSX 文件路径。' },
528
- },
529
- required: ['inputPaths', 'outputPath'],
530
- },
531
- },
532
- },
533
- {
534
- type: 'function',
535
- function: {
536
- name: 'xlsxToCsv',
537
- description: '将 XLSX 工作表导出为 CSV 文件。参数:filePath 为 .xlsx 路径;outputPath 为 .csv 输出路径;sheetName 为工作表名(省略则用第一个)。返回值:对象,包含 success、data(含 outputPath、sheetName)、error。',
538
- parameters: {
539
- type: 'object',
540
- properties: {
541
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
542
- outputPath: { type: 'string', description: '输出 CSV 文件路径。' },
543
- sheetName: { type: 'string', description: '要导出的工作表名。' },
544
- },
545
- required: ['filePath', 'outputPath'],
546
- },
547
- },
548
- },
549
- {
550
- type: 'function',
551
- function: {
552
- name: 'csvToXlsx',
553
- description: '将 CSV 文件转换为 XLSX 文件。参数:inputPath 为 .csv 路径;outputPath 为 .xlsx 输出路径;sheetName 为工作表名(默认 Sheet1)。返回值:对象,包含 success、data(含 inputPath、outputPath)、error。',
554
- parameters: {
555
- type: 'object',
556
- properties: {
557
- inputPath: { type: 'string', description: 'CSV 文件路径。' },
558
- outputPath: { type: 'string', description: '输出 XLSX 文件路径。' },
559
- sheetName: { type: 'string', description: '工作表名,默认 Sheet1。' },
560
- },
561
- required: ['inputPath', 'outputPath'],
562
- },
563
- },
564
- },
565
- {
566
- type: 'function',
567
- function: {
568
- name: 'getSheetStats',
569
- description: '统计 XLSX 指定工作表的行列数量及 header 信息。参数:filePath 为路径;sheetName 为工作表名(省略则用第一个)。返回值:对象,包含 success、data(含 totalRows、totalCols、dataRows、headers)、error。',
570
- parameters: {
571
- type: 'object',
572
- properties: {
573
- filePath: { type: 'string', description: 'XLSX 文件路径。' },
574
- sheetName: { type: 'string', description: '工作表名。' },
575
- },
576
- required: ['filePath'],
577
- },
578
- },
579
- },
580
- ]
581
-
582
- // ─── 导出 ──────────────────────────────────────────────────────────────────────
583
-
584
- const functions = {
585
- xlsxReadme,
586
- getXlsxInfo,
587
- getSheetNames,
588
- readSheet,
589
- readSheetRaw,
590
- readAllSheets,
591
- writeXlsx,
592
- appendRows,
593
- searchXlsx,
594
- deleteSheet,
595
- renameSheet,
596
- mergeXlsx,
597
- xlsxToCsv,
598
- csvToXlsx,
599
- getSheetStats,
600
- }
601
-
602
- const XlsxTool = {
603
- name: 'XlsxTool',
604
- description: '提供 Excel/XLSX 文件的信息读取、单Sheet/全Sheet读取、数据写入、追加行、搜索、删除/重命名Sheet、合并文件、CSV互转等全面处理能力',
605
- platform: 'all',
606
- descriptions,
607
- functions,
608
- isSystem: true
609
- }
610
-
611
- module.exports = XlsxTool
@@ -1,13 +0,0 @@
1
- const descriptions = [] // openai能识别的描述
2
- const functions = {} // key为函数名称,value为方法体
3
-
4
- const BaseTool = {
5
- name: 'BaseTool',
6
- description: '基础扩展模板,提供扩展的基本结构定义',
7
- platform: 'all', // 扩展支持的平台(process.platform),all或空表示所有平台, win32表示仅支持Windows, darwin表示仅支持MacOS, linux表示仅支持Linux
8
- descriptions,
9
- functions,
10
- isSystem: true
11
- }
12
-
13
- module.exports = BaseTool