dsh-plugin-pscad-expert-vyma 1.0.10 → 1.0.11
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 +1 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/plugin.yaml +1 -1
- package/tools/main.py +44 -8
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -29,7 +29,8 @@ export const Config = Schema.object({
|
|
|
29
29
|
.description('Python 解释器路径;默认自动探测(PATH→py 启动器→常见安装位置),无需手动配置'),
|
|
30
30
|
toolsCli: Schema.string().default('./tools/cli.py'),
|
|
31
31
|
defaultFolder: Schema.string().default(''),
|
|
32
|
-
timeoutMs: Schema.number().default(
|
|
32
|
+
timeoutMs: Schema.number().default(300000)
|
|
33
|
+
.description('单次工具调用总超时(毫秒);PSCAD 冷启动等待上限 180s,需留余量'),
|
|
33
34
|
})
|
|
34
35
|
|
|
35
36
|
// ---------------- Python 解释器自动探测(免 profile YAML 配置) ----------------
|
package/package.json
CHANGED
package/plugin.yaml
CHANGED
package/tools/main.py
CHANGED
|
@@ -68,7 +68,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
|
|
68
68
|
CONFIG_FILE_NAME: str = '.pscad_config.json' # 工作区本地配置文件
|
|
69
69
|
PSCAD_PORT: int = int(os.environ.get("PSCAD_PORT", "54329"))
|
|
70
70
|
DEFAULT_FOLDER: str = os.environ.get("PSCAD_WORK_DIR", "") # 无硬编码;空则回退当前工作目录
|
|
71
|
-
LAUNCH_WAIT_S: int =
|
|
71
|
+
LAUNCH_WAIT_S: int = 180 # PSCAD 冷启动(拉起→自动化端口就绪)实测可能 >60s,放宽到 180s
|
|
72
72
|
CONNECT_TIMEOUT_S: int = 20
|
|
73
73
|
|
|
74
74
|
# 配置缺失时的标准 Agent 返回(裸字典,供大模型识别并触发对话式引导)
|
|
@@ -228,15 +228,31 @@ def init_pscad_environment(exe_path: str, pylib_path: str = '') -> Dict[str, Any
|
|
|
228
228
|
"""
|
|
229
229
|
try:
|
|
230
230
|
if not pylib_path:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
# ① site-packages 已有 pip 版 mhi-pscad(Python 3.12+ 机器常见):
|
|
232
|
+
# 直接使用(空 pylib 表示不记录路径,运行时优先直导),无需发现
|
|
233
|
+
ok_sp, _ = _trial_import_mhi('')
|
|
234
|
+
if ok_sp:
|
|
235
|
+
pylib_path = ''
|
|
234
236
|
else:
|
|
237
|
+
discovered = _discover_pylib(exe_path)
|
|
238
|
+
if discovered:
|
|
239
|
+
pylib_path = discovered
|
|
240
|
+
else:
|
|
241
|
+
return {'error': 'ConfigMissing',
|
|
242
|
+
'instruction': ('未能在 PSCAD 安装目录自动发现 mhi.pscad,'
|
|
243
|
+
'site-packages 也无可用版本。请确认 PSCAD 5.x '
|
|
244
|
+
'安装完整(应有 bin/win64/mhi.zip),或 '
|
|
245
|
+
'pip install mhi-pscad 后重试,或手动提供 '
|
|
246
|
+
'mhi.pscad 库路径后再调用 init_pscad_environment。')}
|
|
247
|
+
# 保存前试导入验证:防止自动发现/指定路径在当前 Python 下不可导入
|
|
248
|
+
# (如 mhi.zip 2.2.1 依赖 Python 3.12 已移除的 distutils)时,把原本
|
|
249
|
+
# 可用的配置覆盖成坏配置。导入失败一律不保存,返回引导。
|
|
250
|
+
if pylib_path:
|
|
251
|
+
ok_imp, imp_msg = _trial_import_mhi(pylib_path)
|
|
252
|
+
if not ok_imp:
|
|
235
253
|
return {'error': 'ConfigMissing',
|
|
236
|
-
'instruction': ('
|
|
237
|
-
|
|
238
|
-
'bin/win64/mhi.zip),或手动提供 mhi.pscad '
|
|
239
|
-
'库路径后再调用 init_pscad_environment。')}
|
|
254
|
+
'instruction': ('mhi.pscad 无法在当前 Python 下导入,配置未保存:%s'
|
|
255
|
+
% imp_msg)}
|
|
240
256
|
r = save_config(exe_path, pylib_path)
|
|
241
257
|
if r['status'] == 'success':
|
|
242
258
|
r['data']['message'] = ('PSCAD 环境配置已保存。后续连接将自动使用该配置,'
|
|
@@ -246,6 +262,20 @@ def init_pscad_environment(exe_path: str, pylib_path: str = '') -> Dict[str, Any
|
|
|
246
262
|
return _err(exc)
|
|
247
263
|
|
|
248
264
|
|
|
265
|
+
def _trial_import_mhi(pylib: str) -> Tuple[bool, str]:
|
|
266
|
+
"""试导入验证:确认 pylib(目录或 zip;空串=仅 site-packages 直导)可导入 mhi.pscad。
|
|
267
|
+
|
|
268
|
+
不抛异常;失败返回带指引的消息(Python ≥3.12 的 distutils 问题等)。
|
|
269
|
+
"""
|
|
270
|
+
try:
|
|
271
|
+
if pylib and pylib not in sys.path:
|
|
272
|
+
sys.path.insert(0, pylib)
|
|
273
|
+
import mhi.pscad # noqa: F401
|
|
274
|
+
return True, ''
|
|
275
|
+
except Exception as exc:
|
|
276
|
+
return False, _mhi_import_error(exc, pylib or '<site-packages>')
|
|
277
|
+
|
|
278
|
+
|
|
249
279
|
def _cfg_exe() -> Optional[str]:
|
|
250
280
|
"""解析 PSCAD 可执行文件路径:本地配置优先,环境变量降级回退。"""
|
|
251
281
|
cfg = load_config()
|
|
@@ -548,6 +578,12 @@ def connect_and_load_project(project_name: str,
|
|
|
548
578
|
try:
|
|
549
579
|
_pscad.create_case(project_name, folder=folder)
|
|
550
580
|
prj = _pscad.project(project_name)
|
|
581
|
+
# mhi 2.9.7 的 create_case 可能只在 PSCAD 会话内存建工程、不落盘
|
|
582
|
+
# (与 2.2.1 语义差异);显式 save() 保证 folder 下生成 .pscx
|
|
583
|
+
try:
|
|
584
|
+
prj.save()
|
|
585
|
+
except Exception:
|
|
586
|
+
pass
|
|
551
587
|
except Exception as exc:
|
|
552
588
|
return _err('create_case 失败: %s' % exc)
|
|
553
589
|
|