@tanskong/office-assistant 1.0.1 → 1.0.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.py +35 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanskong/office-assistant",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Office Assistant - AI-powered Office automation via MCP protocol with license protection",
5
5
  "main": "bin/office-assistant.js",
6
6
  "bin": {
package/src/server.py CHANGED
@@ -96,20 +96,38 @@ def open_file(file_path: str) -> dict:
96
96
  - PowerPoint: .pptx, .ppt
97
97
 
98
98
  Tip: Place files in "Desktop/智能办公区/数据" for safe processing.
99
+ Note: For Chinese file paths, use run_python tool instead.
99
100
  """
101
+ import os
102
+
103
+ # 处理中文路径编码
104
+ # 方法1: 使用绝对路径
105
+ file_path = os.path.abspath(file_path)
106
+
107
+ # 方法2: 确保路径存在
108
+ if not os.path.exists(file_path):
109
+ return {"success": False, "error": f"File not found: {file_path}"}
110
+
100
111
  ext = file_path.split('.')[-1].lower()
101
112
  app_name = APP_MAP.get(ext, 'Excel')
102
113
  app = Officer.Application(app_name)
114
+
115
+ if app is None:
116
+ return {"success": False, "error": f"Failed to start {app_name}"}
103
117
 
104
- if app_name == 'Excel':
105
- doc = app.Workbooks.Open(file_path)
106
- elif app_name == 'Word':
107
- doc = app.Documents.Open(file_path)
108
- elif app_name == 'PowerPoint':
109
- doc = app.Presentations.Open(file_path)
110
-
111
- app.Visible = True
112
- return {"success": True, "app": app_name, "file": file_path}
118
+ try:
119
+ if app_name == 'Excel':
120
+ # 使用 Unicode 字符串传递路径
121
+ doc = app.Workbooks.Open(file_path)
122
+ elif app_name == 'Word':
123
+ doc = app.Documents.Open(file_path)
124
+ elif app_name == 'PowerPoint':
125
+ doc = app.Presentations.Open(file_path)
126
+
127
+ app.Visible = True
128
+ return {"success": True, "app": app_name, "file": file_path}
129
+ except Exception as e:
130
+ return {"success": False, "error": str(e), "note": "For Chinese paths, use run_python tool"}
113
131
 
114
132
 
115
133
  @mcp.tool()
@@ -176,10 +194,15 @@ def run_python(code: str, app_name: str = "Excel") -> dict:
176
194
  # ========== System Tools ==========
177
195
 
178
196
  @mcp.tool()
179
- def screenshot(save_name: str = None) -> str:
197
+ def screenshot(save_name: str = None) -> dict:
180
198
  """Capture a screenshot and save to the export folder."""
181
- path = Officer.ScreenShot(save_name)
182
- return path
199
+ try:
200
+ path = Officer.ScreenShot(save_name)
201
+ return {"success": True, "path": path}
202
+ except ImportError as e:
203
+ return {"success": False, "error": "缺少 Pillow 模块,请运行: pip install Pillow", "detail": str(e)}
204
+ except Exception as e:
205
+ return {"success": False, "error": str(e)}
183
206
 
184
207
 
185
208
  @mcp.tool()