opc-agent 4.2.10 → 4.2.12
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/AUDIT-TASK.md +96 -0
- package/cc-err.txt +0 -0
- package/cc-err2.txt +0 -0
- package/dist/cli.js +5 -4
- package/dist/cli.js.map +1 -1
- package/dist/core/runtime.d.ts.map +1 -1
- package/dist/core/runtime.js +4 -2
- package/dist/core/runtime.js.map +1 -1
- package/dist/memory/deepbrain.d.ts.map +1 -1
- package/dist/memory/deepbrain.js +14 -40
- package/dist/memory/deepbrain.js.map +1 -1
- package/dist/providers/index.js +6 -6
- package/dist/providers/index.js.map +1 -1
- package/dist/studio/server.d.ts.map +1 -1
- package/dist/studio/server.js +7 -1
- package/dist/studio/server.js.map +1 -1
- package/package.json +1 -1
package/AUDIT-TASK.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# OPC Studio 全面代码审查 + 穿行测试
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
OPC Studio 有 4 个核心模块:
|
|
5
|
+
1. **OPC Agent** — 主控 Studio(server.ts + index.html)
|
|
6
|
+
2. **DeepBrain** — 知识库(npm: deepbrain,ESM-only)
|
|
7
|
+
3. **AgentKits** — 模型配置(npm: agentkits,ESM-only)
|
|
8
|
+
4. **Workstation** — 岗位模板(npm: agent-workstation,CJS)
|
|
9
|
+
|
|
10
|
+
当前问题:代码里有大量引用这些模块的地方,部分是假实现、部分包名错误、部分 ESM/CJS 不兼容。
|
|
11
|
+
|
|
12
|
+
## 任务
|
|
13
|
+
|
|
14
|
+
### 阶段 1: 全面代码扫描
|
|
15
|
+
1. 扫描 `src/` 所有 `.ts` 文件,列出每个对 `deepbrain`、`agentkits`、`agent-workstation` 的引用
|
|
16
|
+
2. 检查每个引用点:
|
|
17
|
+
- 包名是否正确?(agentkits 不是 agent-kits)
|
|
18
|
+
- 加载方式是否正确?(ESM 包必须用 `dynamicImport`,不能用 `require`)
|
|
19
|
+
- 被调用的 API(类名/方法名)是否真实存在?
|
|
20
|
+
- 错误处理是否合理?
|
|
21
|
+
|
|
22
|
+
### 阶段 2: 验证模块 API
|
|
23
|
+
对每个模块,实际检查导出了哪些类/函数:
|
|
24
|
+
```bash
|
|
25
|
+
node -e "import('deepbrain').then(m=>console.log(Object.keys(m)))"
|
|
26
|
+
node -e "import('agentkits').then(m=>console.log(Object.keys(m)))"
|
|
27
|
+
node -e "const m=require('agent-workstation');console.log(Object.keys(m))"
|
|
28
|
+
```
|
|
29
|
+
然后对比代码里调用的 API,标记哪些是假的。
|
|
30
|
+
|
|
31
|
+
### 阶段 3: 修复
|
|
32
|
+
- 所有 `require('deepbrain')` 和 `require('agentkits')` 改为 `const { dynamicImport } = require('../utils/dynamic-import')` + `await dynamicImport('xxx')`
|
|
33
|
+
- 包名错误全部纠正
|
|
34
|
+
- 调用不存在的 API → 要么实现,要么移除假代码
|
|
35
|
+
- 已有的 `dynamicImport` helper 在 `src/utils/dynamic-import.js`(纯 JS,用 `new Function('specifier', 'return import(specifier)')` 绕过 TS 编译)
|
|
36
|
+
|
|
37
|
+
### 阶段 4: 穿行测试
|
|
38
|
+
修复后,逐个测试每条 API 路径:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# 0. Build
|
|
42
|
+
npm run build
|
|
43
|
+
|
|
44
|
+
# 1. 启动 Studio(在 opc-agent 目录,不是 test 目录)
|
|
45
|
+
node -e "const{StudioServer}=require('./dist/studio/server');new StudioServer({port:4000,agentDir:process.cwd(),workDir:process.cwd()}).start()"
|
|
46
|
+
|
|
47
|
+
# 2. 测 Memory/DeepBrain APIs
|
|
48
|
+
curl http://localhost:4000/api/memory/stats
|
|
49
|
+
curl http://localhost:4000/api/memory/list
|
|
50
|
+
curl -X POST http://localhost:4000/api/memory/upload -F "file=@README.md"
|
|
51
|
+
|
|
52
|
+
# 3. 测 Agent CRUD
|
|
53
|
+
curl http://localhost:4000/api/agents
|
|
54
|
+
curl -X POST http://localhost:4000/api/agents -H "Content-Type: application/json" -d '{"name":"test","model":"auto"}'
|
|
55
|
+
curl http://localhost:4000/api/agents/test
|
|
56
|
+
curl -X DELETE http://localhost:4000/api/agents/test
|
|
57
|
+
|
|
58
|
+
# 4. 测 Agent Chat(OPC 助手)
|
|
59
|
+
curl -X POST http://localhost:4000/api/agents/opc-assistant/chat -H "Content-Type: application/json" -d '{"message":"你好"}'
|
|
60
|
+
|
|
61
|
+
# 5. 测模板
|
|
62
|
+
curl http://localhost:4000/api/templates
|
|
63
|
+
|
|
64
|
+
# 6. 测模型配置
|
|
65
|
+
curl http://localhost:4000/api/models
|
|
66
|
+
curl http://localhost:4000/api/models/ollama
|
|
67
|
+
|
|
68
|
+
# 7. 前端加载
|
|
69
|
+
curl -s http://localhost:4000/ | head -20
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
每个测试记录:HTTP status + 返回数据前 200 字符 + 是否有中文乱码。
|
|
73
|
+
|
|
74
|
+
### 阶段 5: 清理
|
|
75
|
+
- 移除所有死代码
|
|
76
|
+
- 确保 `npm run build` 零 error
|
|
77
|
+
- `postbuild.js` 已经处理 studio-ui + dynamic-import.js 复制
|
|
78
|
+
|
|
79
|
+
## 关键约束
|
|
80
|
+
- deepbrain 和 agentkits 是 ESM-only(`"type": "module"`)
|
|
81
|
+
- agent-workstation 是 CJS(无 `type` 字段)
|
|
82
|
+
- opc-agent 本身是 CJS(tsconfig `module: commonjs`)
|
|
83
|
+
- `dynamicImport()` helper 用 `new Function` 绕过 TS 编译
|
|
84
|
+
- 所有中文字符串必须正确 UTF-8 编码
|
|
85
|
+
- 不要改 tsconfig,不要把项目改成 ESM
|
|
86
|
+
|
|
87
|
+
## 文件位置
|
|
88
|
+
- 项目根目录: `C:\Users\mingjwan\opc-agent`
|
|
89
|
+
- Studio server: `src/studio/server.ts`
|
|
90
|
+
- CLI: `src/cli.ts`
|
|
91
|
+
- Doctor: `src/doctor.ts`
|
|
92
|
+
- Brain seed: `src/hub/brain-seed.ts`
|
|
93
|
+
- Dynamic import helper: `src/utils/dynamic-import.js`
|
|
94
|
+
- Postbuild: `scripts/postbuild.js`
|
|
95
|
+
|
|
96
|
+
完成后 commit message 格式: `v4.2.12: full code audit - fix module refs, remove dead code, pass all API tests`
|
package/cc-err.txt
ADDED
|
File without changes
|
package/cc-err2.txt
ADDED
|
File without changes
|
package/dist/cli.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const { dynamicImport } = require('./utils/dynamic-import');
|
|
37
38
|
const commander_1 = require("commander");
|
|
38
39
|
const fs = __importStar(require("fs"));
|
|
39
40
|
const path = __importStar(require("path"));
|
|
@@ -2064,7 +2065,7 @@ program
|
|
|
2064
2065
|
// Try to start sub-module UI servers with graceful fallback
|
|
2065
2066
|
const subModules = [
|
|
2066
2067
|
{ name: 'DeepBrain', icon: '🧠', pkg: 'deepbrain', port: 4001, serveMethod: 'serveUI' },
|
|
2067
|
-
{ name: 'AgentKits', icon: '📊', pkg: '
|
|
2068
|
+
{ name: 'AgentKits', icon: '📊', pkg: 'agentkits', port: 4002, serveMethod: 'serveUI' },
|
|
2068
2069
|
{ name: 'Workstation', icon: '👤', pkg: 'agent-workstation', port: 4003, serveMethod: 'serveUI' },
|
|
2069
2070
|
];
|
|
2070
2071
|
const moduleStatuses = [];
|
|
@@ -2075,7 +2076,7 @@ program
|
|
|
2075
2076
|
moduleStatuses.push(` ${icon.success} ${mod.icon} ${mod.name} already running on :${mod.port}`);
|
|
2076
2077
|
continue;
|
|
2077
2078
|
}
|
|
2078
|
-
const modExports =
|
|
2079
|
+
const modExports = await dynamicImport(mod.pkg);
|
|
2079
2080
|
if (typeof modExports[mod.serveMethod] === 'function') {
|
|
2080
2081
|
modExports[mod.serveMethod]({ port: mod.port });
|
|
2081
2082
|
await new Promise(r => setTimeout(r, 600));
|
|
@@ -2085,11 +2086,11 @@ program
|
|
|
2085
2086
|
: ` ${icon.warn} ${mod.icon} ${mod.name} failed to start`);
|
|
2086
2087
|
}
|
|
2087
2088
|
else {
|
|
2088
|
-
moduleStatuses.push(` ${
|
|
2089
|
+
moduleStatuses.push(` ${icon.success} ${mod.icon} ${mod.name} installed`);
|
|
2089
2090
|
}
|
|
2090
2091
|
}
|
|
2091
2092
|
catch {
|
|
2092
|
-
moduleStatuses.push(` ${color.dim('○')} ${mod.icon} ${mod.name} not installed`);
|
|
2093
|
+
moduleStatuses.push(` ${color.dim('○')} ${mod.icon} ${mod.name} not installed (npm i ${mod.pkg})`);
|
|
2093
2094
|
}
|
|
2094
2095
|
}
|
|
2095
2096
|
if (moduleStatuses.length > 0) {
|