dsh-plugin-pscad-expert-vyma 1.0.6 → 1.0.7
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 +3 -1
- package/package.json +5 -2
- package/plugin.yaml +1 -1
- package/tools/cli.py +33 -0
- package/tools/__pycache__/main.cpython-37.pyc +0 -0
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -79,7 +79,9 @@ function runPy(tool, args, config, signal) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// ---------------- 工具渲染(纯函数:不做 I/O) ----------------
|
|
82
|
-
|
|
82
|
+
// 注意:DSH 框架以 render(args, value) 双参调用渲染器;若只声明单参 value,
|
|
83
|
+
// 实际收到的是 args,导致"成功结果恒显示参数/{}"。必须双参并取第二个参数。
|
|
84
|
+
function renderJson(_args, value) {
|
|
83
85
|
if (value && typeof value === 'object' && value.error === 'ConfigMissing') {
|
|
84
86
|
// 配置缺失:引导 Agent 立即停止当前任务并询问用户路径
|
|
85
87
|
return [{ type: 'text', text: `【配置缺失】${value.instruction}` }]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-pscad-expert-vyma",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "PSCAD 自动化建模与仿真控制专家插件(DSH Agent 工具库 + 基准模板 + 领域知识)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"plugin.yaml",
|
|
31
31
|
"README.md",
|
|
32
32
|
"index.js",
|
|
33
|
-
"cordis.patch.yml"
|
|
33
|
+
"cordis.patch.yml",
|
|
34
|
+
"!tools/__pycache__/",
|
|
35
|
+
"!**/*.pyc",
|
|
36
|
+
"!**/*.pyo"
|
|
34
37
|
],
|
|
35
38
|
"engines": {
|
|
36
39
|
"python": ">=3.7"
|
package/plugin.yaml
CHANGED
package/tools/cli.py
CHANGED
|
@@ -27,9 +27,33 @@ from typing import Any, Dict, List
|
|
|
27
27
|
# 将本文件所在目录加入 sys.path,以便 import main(tools/main.py)
|
|
28
28
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
29
29
|
|
|
30
|
+
# 统一 stdout 为 UTF-8:Node 桥接按 UTF-8 解码,避免 GBK 中文乱码(Python 3.7+)
|
|
31
|
+
try:
|
|
32
|
+
sys.stdout.reconfigure(encoding='utf-8')
|
|
33
|
+
sys.stderr.reconfigure(encoding='utf-8')
|
|
34
|
+
except Exception:
|
|
35
|
+
pass
|
|
36
|
+
|
|
30
37
|
import main as pat # noqa: E402
|
|
31
38
|
|
|
39
|
+
def _run_simulation_configure(time_duration: float = 0.5,
|
|
40
|
+
time_step: float = 10.0,
|
|
41
|
+
sample_step: float = 50.0,
|
|
42
|
+
timeout_loops: int = 60) -> Dict[str, Any]:
|
|
43
|
+
"""组合工具:先配置仿真参数(configure_simulation),再编译运行并监控。
|
|
44
|
+
|
|
45
|
+
对应桥接层 pscad_run_simulation 的复合语义(配置 + 运行一步到位)。
|
|
46
|
+
"""
|
|
47
|
+
cfg = pat.configure_simulation(time_duration=time_duration,
|
|
48
|
+
time_step=time_step,
|
|
49
|
+
sample_step=sample_step)
|
|
50
|
+
if cfg.get('status') != 'success':
|
|
51
|
+
return cfg
|
|
52
|
+
return pat.run_simulation_and_monitor(timeout_loops=timeout_loops)
|
|
53
|
+
|
|
54
|
+
|
|
32
55
|
# 白名单:仅暴露经过审核的工具函数(防止任意 Python 代码执行)
|
|
56
|
+
# 同时收录桥接层 index.js 注册的 pscad_* 工具名(别名),消除名字脱节。
|
|
33
57
|
TOOL_WHITELIST: Dict[str, Any] = {
|
|
34
58
|
'init_pscad_environment': pat.init_pscad_environment,
|
|
35
59
|
'connect_and_load_project': pat.connect_and_load_project,
|
|
@@ -50,6 +74,15 @@ TOOL_WHITELIST: Dict[str, Any] = {
|
|
|
50
74
|
'close_connection': pat.close_connection,
|
|
51
75
|
'build_droop_chain': pat.build_droop_chain,
|
|
52
76
|
'self_check': pat.self_check,
|
|
77
|
+
# ---- 桥接层别名(index.js 注册的 pscad_* 工具名)----
|
|
78
|
+
'pscad_init_environment': pat.init_pscad_environment,
|
|
79
|
+
'pscad_connect_load_project': pat.connect_and_load_project,
|
|
80
|
+
'pscad_add_component': pat.add_and_configure_component,
|
|
81
|
+
'pscad_connect_ports': pat.connect_ports_safely,
|
|
82
|
+
'pscad_connect_signal': pat.connect_signal_by_name,
|
|
83
|
+
'pscad_run_simulation': _run_simulation_configure,
|
|
84
|
+
'pscad_read_output': pat.read_output,
|
|
85
|
+
'pscad_self_check': pat.self_check,
|
|
53
86
|
}
|
|
54
87
|
|
|
55
88
|
|
|
Binary file
|