dsh-plugin-pscad-expert-vyma 1.0.0 → 1.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.
- package/cordis.patch.yml +2 -0
- package/index.js +24 -0
- package/package.json +10 -3
- package/plugin.yaml +10 -1
- package/tools/__pycache__/main.cpython-37.pyc +0 -0
- package/tools/main.py +34 -3
package/cordis.patch.yml
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
exports.name = 'pscad-expert-bridge';
|
|
5
|
+
|
|
6
|
+
exports.apply = function (ctx) {
|
|
7
|
+
ctx.on('ready', () => {
|
|
8
|
+
try {
|
|
9
|
+
const baseDir = ctx.baseDir || process.cwd();
|
|
10
|
+
const targetDir = path.join(baseDir, 'plugins', 'dsh-plugin-pscad-expert-vyma');
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(targetDir)) {
|
|
13
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
14
|
+
fs.cpSync(__dirname, targetDir, {
|
|
15
|
+
recursive: true,
|
|
16
|
+
filter: (src) => !src.includes('node_modules') && !src.includes('.git')
|
|
17
|
+
});
|
|
18
|
+
ctx.logger('pscad-bridge').info('PSCAD Agent 资产已成功跨层释放!');
|
|
19
|
+
}
|
|
20
|
+
} catch (err) {
|
|
21
|
+
ctx.logger('pscad-bridge').error('释放资产失败:', err);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-pscad-expert-vyma",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "PSCAD 自动化建模与仿真控制专家插件(DSH Agent 工具库 + 基准模板 + 领域知识)",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dsh": {
|
|
7
|
+
"bundle": {
|
|
8
|
+
"patch": "./cordis.patch.yml"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
6
11
|
"keywords": [
|
|
7
12
|
"dsh",
|
|
8
13
|
"pscad",
|
|
@@ -17,7 +22,9 @@
|
|
|
17
22
|
"tools/",
|
|
18
23
|
"templates/",
|
|
19
24
|
"plugin.yaml",
|
|
20
|
-
"README.md"
|
|
25
|
+
"README.md",
|
|
26
|
+
"index.js",
|
|
27
|
+
"cordis.patch.yml"
|
|
21
28
|
],
|
|
22
29
|
"engines": {
|
|
23
30
|
"python": ">=3.7"
|
package/plugin.yaml
CHANGED
|
@@ -3,9 +3,18 @@
|
|
|
3
3
|
# 由知识资产固化项目自动生成(2026-08-25)· 部署至 Git 仓库
|
|
4
4
|
# ============================================================
|
|
5
5
|
name: pscad-automation-expert
|
|
6
|
-
version: 1.0.
|
|
6
|
+
version: 1.0.2
|
|
7
7
|
description: PSCAD 自动化建模与仿真控制专家插件
|
|
8
8
|
|
|
9
|
+
# ---- 系统提示词(加载到 Agent 上下文最前置位置)----
|
|
10
|
+
system_prompt: |
|
|
11
|
+
【环境配置最高优先级规则】当调用工具返回 ConfigMissing 错误时,你必须立刻停止当前任务,
|
|
12
|
+
主动且礼貌地在聊天界面询问用户的 PSCAD 安装路径,并引导他们完成配置。
|
|
13
|
+
|
|
14
|
+
你是 PSCAD 自动化建模与仿真控制专家。当调用任何工具返回 `ConfigMissing` 错误时,
|
|
15
|
+
你必须立刻停止调用其他工具,主动在聊天界面中询问用户 PSCAD 的安装路径,
|
|
16
|
+
并引导他们完成配置(调用 init_pscad_environment 工具保存路径)。
|
|
17
|
+
|
|
9
18
|
# ---- 工具入口注册(tools/main.py 中的核心函数)----
|
|
10
19
|
entry_points:
|
|
11
20
|
tools:
|
|
Binary file
|
package/tools/main.py
CHANGED
|
@@ -71,9 +71,12 @@ DEFAULT_FOLDER: str = os.environ.get("PSCAD_WORK_DIR", "") # 无硬编码;空
|
|
|
71
71
|
LAUNCH_WAIT_S: int = 60
|
|
72
72
|
CONNECT_TIMEOUT_S: int = 20
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
# 配置缺失时的标准 Agent 返回(裸字典,供大模型识别并触发对话式引导)
|
|
75
|
+
CONFIG_MISSING_RESPONSE: Dict[str, str] = {
|
|
76
|
+
"error": "ConfigMissing",
|
|
77
|
+
"instruction": "本地未找到配置。请中止操作,用自然语言向用户询问其 PSCAD 的安装路径,获取后调用 init_pscad_environment 工具保存。",
|
|
78
|
+
}
|
|
79
|
+
MISSING_CONFIG_MSG = CONFIG_MISSING_RESPONSE['instruction']
|
|
77
80
|
|
|
78
81
|
# 元件默认参数(实测合法值;调用方 params 覆盖默认值)
|
|
79
82
|
COMPONENT_DEFAULTS: Dict[str, Dict[str, Any]] = {
|
|
@@ -242,6 +245,26 @@ def _err(exc: Union[Exception, str]) -> Dict[str, Any]:
|
|
|
242
245
|
return {"status": "error", "message": str(exc)}
|
|
243
246
|
|
|
244
247
|
|
|
248
|
+
def _require_config() -> Optional[Dict[str, Any]]:
|
|
249
|
+
"""统一配置存在性检查(所有会连接 PSCAD 的工具函数入口调用)。
|
|
250
|
+
|
|
251
|
+
若工作区本地无 ``.pscad_config.json``(且无环境变量回退),**不抛异常、
|
|
252
|
+
不崩溃**,直接返回标准引导字典::
|
|
253
|
+
|
|
254
|
+
{"error": "ConfigMissing",
|
|
255
|
+
"instruction": "本地未找到 PSCAD 配置。请立即中止当前操作,使用自然语言
|
|
256
|
+
向用户询问其 PSCAD 的安装路径,获取后调用 init_pscad_environment 工具进行保存。"}
|
|
257
|
+
|
|
258
|
+
大模型收到该返回后应停止调用其他工具、在聊天界面询问用户路径。
|
|
259
|
+
|
|
260
|
+
Returns:
|
|
261
|
+
配置缺失时返回 ``CONFIG_MISSING_RESPONSE``(裸字典);配置可用返回 ``None``。
|
|
262
|
+
"""
|
|
263
|
+
if _cfg_exe() and _cfg_pylib():
|
|
264
|
+
return None
|
|
265
|
+
return CONFIG_MISSING_RESPONSE
|
|
266
|
+
|
|
267
|
+
|
|
245
268
|
def _import_mhi() -> Tuple[bool, str]:
|
|
246
269
|
"""懒加载 mhi.pscad(仅在实际需要连接 PSCAD 时调用)。
|
|
247
270
|
|
|
@@ -378,6 +401,10 @@ def connect_and_load_project(project_name: str,
|
|
|
378
401
|
"""
|
|
379
402
|
global _pscad, _prj, _prj_name, _prj_folder, _main
|
|
380
403
|
try:
|
|
404
|
+
# 对话式引导:配置缺失时立即返回 ConfigMissing 引导字典(不崩溃)
|
|
405
|
+
missing = _require_config()
|
|
406
|
+
if missing is not None:
|
|
407
|
+
return missing
|
|
381
408
|
ok, msg = _ensure_connected()
|
|
382
409
|
if not ok and auto_launch:
|
|
383
410
|
launched, msg2 = _launch_pscad()
|
|
@@ -476,6 +503,10 @@ def restart_pscad() -> Dict[str, Any]:
|
|
|
476
503
|
"""
|
|
477
504
|
global _pscad, _prj, _main
|
|
478
505
|
try:
|
|
506
|
+
# 对话式引导:配置缺失时返回 ConfigMissing 引导字典(不崩溃)
|
|
507
|
+
missing = _require_config()
|
|
508
|
+
if missing is not None:
|
|
509
|
+
return missing
|
|
479
510
|
if _pscad is not None:
|
|
480
511
|
try:
|
|
481
512
|
_pscad.close_connection()
|