openclaw-openagent 1.0.12 → 1.0.14
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/dist/index.js +2 -0
- package/dist/src/config/config-schema.d.ts +9 -0
- package/dist/src/config/config-schema.js +6 -0
- package/dist/src/messaging/executor.d.ts +2 -3
- package/dist/src/messaging/executor.js +4 -31
- package/dist/src/plugin-ui/assets/openagent-override.js +124 -18
- package/dist/src/proxy/auth-proxy.js +5 -0
- package/dist/src/runtime/update-checker.d.ts +18 -0
- package/dist/src/runtime/update-checker.js +216 -0
- package/index.ts +3 -0
- package/package.json +1 -3
- package/src/app/channel-tools.ts +0 -249
- package/src/app/discovery-tools.ts +0 -273
- package/src/app/download-file-tool.ts +0 -133
- package/src/app/hooks.ts +0 -144
- package/src/app/index.ts +0 -84
- package/src/app/messaging-tools.ts +0 -79
- package/src/app/ops-tools.ts +0 -155
- package/src/app/remote-agent-tool.ts +0 -762
- package/src/app/types.ts +0 -68
- package/src/app/upload-file-tool.ts +0 -411
- package/src/app/verbose-preflight.ts +0 -190
- package/src/auth/config.ts +0 -266
- package/src/auth/credential-manager.ts +0 -146
- package/src/auth/index.ts +0 -24
- package/src/auth/verify.ts +0 -99
- package/src/channel.ts +0 -566
- package/src/compat.ts +0 -94
- package/src/config/config-schema.ts +0 -39
- package/src/messaging/aggregator.ts +0 -120
- package/src/messaging/collector.ts +0 -89
- package/src/messaging/executor.ts +0 -72
- package/src/messaging/inbound.ts +0 -150
- package/src/messaging/index.ts +0 -11
- package/src/messaging/mention-protocol.ts +0 -94
- package/src/messaging/process-c2c-request.ts +0 -564
- package/src/messaging/process-message.ts +0 -373
- package/src/messaging/scheduler.ts +0 -55
- package/src/messaging/types.ts +0 -38
- package/src/plugin-ui/adapters/oc-2026-04.js +0 -103
- package/src/plugin-ui/adapters/oc-2026-05.js +0 -125
- package/src/plugin-ui/adapters/oc-2026-06.js +0 -125
- package/src/plugin-ui/adapters/oc-unknown.js +0 -48
- package/src/plugin-ui/assets/agentbook-icon.svg +0 -5
- package/src/plugin-ui/assets/bg.png +0 -0
- package/src/plugin-ui/assets/icon.png +0 -0
- package/src/plugin-ui/assets/magic.svg +0 -5
- package/src/plugin-ui/assets/openagent-override.js +0 -11156
- package/src/plugin-ui/build.cjs +0 -463
- package/src/plugin-ui/index.ts +0 -18
- package/src/plugin-ui/modules/agent-book/panel/agent-book.js +0 -570
- package/src/plugin-ui/modules/agent-book/panel/agent-card.js +0 -170
- package/src/plugin-ui/modules/agent-book/panel/agent-data.js +0 -643
- package/src/plugin-ui/modules/agent-book/panel/inject-ui.js +0 -665
- package/src/plugin-ui/modules/agent-book/panel/mention-state.js +0 -206
- package/src/plugin-ui/modules/agent-book/panel/styles.js +0 -833
- package/src/plugin-ui/modules/agent-book/panel/theme-adapter.js +0 -86
- package/src/plugin-ui/modules/agent-book/remote-agent-tool/components-core.js +0 -295
- package/src/plugin-ui/modules/agent-book/remote-agent-tool/thought-chain-card.js +0 -211
- package/src/plugin-ui/modules/agent-book/scanner.js +0 -131
- package/src/plugin-ui/modules/agent-book/travelcard/travel-cards.js +0 -500
- package/src/plugin-ui/modules/agent-book/travelcard/travel-engine.js +0 -652
- package/src/plugin-ui/modules/agent-book/travelcard/travel-styles.js +0 -256
- package/src/plugin-ui/modules/loader/bootstrap.js +0 -38
- package/src/plugin-ui/modules/loader/shared-state.js +0 -838
- package/src/plugin-ui/modules/loader/ws-intercept.js +0 -199
- package/src/plugin-ui/modules/remote-agent/chunk-parser.js +0 -161
- package/src/plugin-ui/modules/remote-agent/execution-card.js +0 -530
- package/src/plugin-ui/modules/remote-agent/markdown-renderer.js +0 -256
- package/src/plugin-ui/modules/remote-agent/media-links.js +0 -151
- package/src/plugin-ui/modules/remote-agent/native-style-adapter.js +0 -134
- package/src/plugin-ui/modules/remote-agent/output-card.js +0 -342
- package/src/plugin-ui/modules/remote-agent/progress-store.js +0 -363
- package/src/plugin-ui/modules/remote-agent/render-hooks.js +0 -1700
- package/src/plugin-ui/modules/remote-agent/styles.js +0 -896
- package/src/plugin-ui/modules/remote-agent/tool-card-model.js +0 -130
- package/src/plugin-ui/postinstall-deploy.cjs +0 -52
- package/src/plugin-ui/ui-extension-loader/backup.ts +0 -92
- package/src/plugin-ui/ui-extension-loader/index.ts +0 -276
- package/src/plugin-ui/ui-extension-loader/locator.ts +0 -152
- package/src/plugin-ui/ui-extension-loader/manifest.ts +0 -57
- package/src/plugin-ui/ui-extension-loader/registry-regex.ts +0 -944
- package/src/plugin-ui/ui-extension-loader/removed-extensions.ts +0 -70
- package/src/plugin-ui/ui-extension-loader/types.ts +0 -72
- package/src/proxy/auth-proxy.ts +0 -409
- package/src/runtime/account.ts +0 -549
- package/src/runtime/index.ts +0 -7
- package/src/runtime/plugin-runtime.ts +0 -94
- package/src/runtime/registry.ts +0 -71
- package/src/sdk/CLASS_MAP.md +0 -143
- package/src/sdk/index.d.ts +0 -126
- package/src/sdk/index.js +0 -23990
- package/src/sdk/modules/cloud-search-module.js +0 -1117
- package/src/sdk/modules/follow-module.js +0 -1069
- package/src/sdk/modules/group-module.js +0 -7397
- package/src/sdk/modules/relationship-module.js +0 -2269
- package/src/sdk/modules/signaling-module.js +0 -1468
- package/src/sdk/modules/tim-upload-plugin.js +0 -730
- package/src/sdk/node-env/http-request.js +0 -90
- package/src/sdk/node-env/index.js +0 -57
- package/src/sdk/node-env/storage.js +0 -114
- package/src/sdk/package.json +0 -10
- package/src/sdk/tsconfig.json +0 -16
- package/src/state/pending-invocation-store.ts +0 -43
- package/src/state/store.ts +0 -756
- package/src/tim/c2c.ts +0 -451
- package/src/tim/channels.ts +0 -364
- package/src/tim/client.ts +0 -330
- package/src/tim/index.ts +0 -18
- package/src/tim/messages.ts +0 -166
- package/src/tim/sdk-logger-init.ts +0 -50
- package/src/tools.ts +0 -10
- package/src/transport/factory.ts +0 -95
- package/src/transport/oasn/index.ts +0 -17
- package/src/transport/oasn/oasn-agent-card.ts +0 -111
- package/src/transport/oasn/oasn-discovery.ts +0 -108
- package/src/transport/oasn/oasn-files.ts +0 -210
- package/src/transport/oasn/oasn-http.ts +0 -529
- package/src/transport/oasn/oasn-invocation.ts +0 -604
- package/src/transport/oasn/oasn-normalize.ts +0 -133
- package/src/transport/oasn/oasn-register.ts +0 -33
- package/src/transport/oasn/oasn-transport.ts +0 -318
- package/src/transport/oasn/oasn-types.ts +0 -404
- package/src/transport/tim/index.ts +0 -8
- package/src/transport/tim/tim-transport.ts +0 -515
- package/src/transport/types.ts +0 -538
- package/src/types/openclaw-plugin-sdk-media-store.d.ts +0 -9
- package/src/types/openclaw.d.ts +0 -97
- package/src/types/tencentcloud-chat.d.ts +0 -15
- package/src/util/http.ts +0 -113
- package/src/util/logger.ts +0 -131
- package/src/util/url-resolver.ts +0 -77
package/src/plugin-ui/build.cjs
DELETED
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* build.js — 将 modules/ 下的源模块按显式顺序拼接为 openagent-override.js
|
|
4
|
-
*
|
|
5
|
-
* 用法: node src/plugin-ui/build.cjs
|
|
6
|
-
* 输出: src/plugin-ui/assets/openagent-override.js
|
|
7
|
-
*
|
|
8
|
-
* 规则:
|
|
9
|
-
* - 顺序由 MANIFEST 数组决定,新增模块必须手动注册
|
|
10
|
-
* - 缺少任何模块立即报错退出
|
|
11
|
-
* - 产物不入 Git,通过 prepack hook 在 npm pack/publish 时自动生成
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const fs = require('fs');
|
|
15
|
-
const path = require('path');
|
|
16
|
-
const crypto = require('crypto');
|
|
17
|
-
const childProcess = require('child_process');
|
|
18
|
-
|
|
19
|
-
// ── 读取 OpenClaw 版本(用于注入到产物中)──
|
|
20
|
-
function resolveBuildHostVersion() {
|
|
21
|
-
// 优先使用环境变量
|
|
22
|
-
if (process.env.OPENCLAW_HOST_VERSION) return normalizeHostVersion(process.env.OPENCLAW_HOST_VERSION);
|
|
23
|
-
|
|
24
|
-
var packageCandidates = [
|
|
25
|
-
path.join(__dirname, '..', '..', 'node_modules', 'openclaw', 'package.json'),
|
|
26
|
-
path.join(__dirname, '..', '..', 'package.json'),
|
|
27
|
-
];
|
|
28
|
-
for (var i = 0; i < packageCandidates.length; i++) {
|
|
29
|
-
try {
|
|
30
|
-
if (!fs.existsSync(packageCandidates[i])) continue;
|
|
31
|
-
var candidatePkg = JSON.parse(fs.readFileSync(packageCandidates[i], 'utf-8'));
|
|
32
|
-
if (candidatePkg && candidatePkg.name === 'openclaw') {
|
|
33
|
-
var exactVersion = normalizeHostVersion(candidatePkg.version);
|
|
34
|
-
if (exactVersion) return exactVersion;
|
|
35
|
-
}
|
|
36
|
-
var depVersion = candidatePkg && candidatePkg.devDependencies && candidatePkg.devDependencies.openclaw;
|
|
37
|
-
depVersion = normalizeHostVersion(String(depVersion || '').replace(/^[\^~>=<]+/, '').trim());
|
|
38
|
-
if (depVersion) return depVersion;
|
|
39
|
-
} catch (e) {}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return '';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ═══════════════════════════════════════════════════════════════
|
|
46
|
-
// MANIFEST — 显式构建顺序,不要用 readdir+sort
|
|
47
|
-
// 新增模块必须在此注册,否则不进产物
|
|
48
|
-
// ═══════════════════════════════════════════════════════════════
|
|
49
|
-
const MANIFEST = [
|
|
50
|
-
// ── loader ──
|
|
51
|
-
'loader/shared-state.js',
|
|
52
|
-
'loader/ws-intercept.js',
|
|
53
|
-
// ── agent-book/panel ──
|
|
54
|
-
'agent-book/panel/agent-data.js',
|
|
55
|
-
'agent-book/panel/agent-card.js',
|
|
56
|
-
'agent-book/panel/theme-adapter.js', // 必须在 styles.js 之前,设置 --oa-* CSS 变量
|
|
57
|
-
'agent-book/panel/styles.js',
|
|
58
|
-
'agent-book/panel/mention-state.js',
|
|
59
|
-
'agent-book/panel/agent-book.js',
|
|
60
|
-
'agent-book/panel/inject-ui.js',
|
|
61
|
-
// ── agent-book/remote-agent-tool ──
|
|
62
|
-
'agent-book/remote-agent-tool/components-core.js',
|
|
63
|
-
'agent-book/remote-agent-tool/thought-chain-card.js',
|
|
64
|
-
// ── agent-book/travelcard ──
|
|
65
|
-
'agent-book/travelcard/travel-styles.js',
|
|
66
|
-
'agent-book/travelcard/travel-cards.js',
|
|
67
|
-
'agent-book/travelcard/travel-engine.js',
|
|
68
|
-
// ── agent-book (跨模块) ──
|
|
69
|
-
'agent-book/scanner.js',
|
|
70
|
-
// ── remote-agent(renderToolCardSidebar hook)──
|
|
71
|
-
// 顺序:adapter → styles → parser/model → UI cards → hooks
|
|
72
|
-
'remote-agent/native-style-adapter.js',
|
|
73
|
-
'remote-agent/styles.js',
|
|
74
|
-
'remote-agent/chunk-parser.js',
|
|
75
|
-
'remote-agent/progress-store.js',
|
|
76
|
-
'remote-agent/tool-card-model.js',
|
|
77
|
-
'remote-agent/execution-card.js',
|
|
78
|
-
'remote-agent/markdown-renderer.js',
|
|
79
|
-
'remote-agent/media-links.js',
|
|
80
|
-
'remote-agent/output-card.js',
|
|
81
|
-
'remote-agent/render-hooks.js',
|
|
82
|
-
// ── loader (bootstrap 必须最后) ──
|
|
83
|
-
'loader/bootstrap.js',
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
// ═══════════════════════════════════════════════════════════════
|
|
87
|
-
|
|
88
|
-
const modulesDir = path.join(__dirname, 'modules');
|
|
89
|
-
const adaptersDir = path.join(__dirname, 'adapters');
|
|
90
|
-
const assetsDir = path.join(__dirname, 'assets');
|
|
91
|
-
const outFile = path.join(assetsDir, 'openagent-override.js');
|
|
92
|
-
const iconFile = path.join(assetsDir, 'icon.png');
|
|
93
|
-
const bgFile = path.join(assetsDir, 'bg.png');
|
|
94
|
-
const HOST_VERSION_TOKEN = "hostVersion: '__OPENCLAW_HOST_VERSION__'";
|
|
95
|
-
const BUILD_ID_TOKEN = "buildId: '__OPENAGENT_BUILD_ID__'";
|
|
96
|
-
const BUILD_ID_ASSIGNMENT_RE = /buildId:\s*(?:"[^"]*"|'[^']*')/;
|
|
97
|
-
const HOST_ADAPTER_START = '/*__OPENAGENT_HOST_ADAPTER_START__*/';
|
|
98
|
-
const HOST_ADAPTER_END = '/*__OPENAGENT_HOST_ADAPTER_END__*/';
|
|
99
|
-
const HOST_ADAPTER_BLOCK_RE = /\/\*__OPENAGENT_HOST_ADAPTER_START__\*\/[\s\S]*?\/\*__OPENAGENT_HOST_ADAPTER_END__\*\//;
|
|
100
|
-
|
|
101
|
-
function normalizeHostVersion(version) {
|
|
102
|
-
var match = String(version || '').match(/20\d{2}\.\d{1,2}\.\d{1,2}(?:-[A-Za-z0-9._-]+)?/);
|
|
103
|
-
return match ? match[0] : '';
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function injectHostVersion(content, hostVersion) {
|
|
107
|
-
hostVersion = normalizeHostVersion(hostVersion);
|
|
108
|
-
if (!hostVersion) return content;
|
|
109
|
-
return content.replace(HOST_VERSION_TOKEN, 'hostVersion: ' + JSON.stringify(hostVersion));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function resolveHostAdapterId(hostVersion) {
|
|
113
|
-
var parsed = normalizeHostVersion(hostVersion).split('.');
|
|
114
|
-
var year = parseInt(parsed[0], 10);
|
|
115
|
-
var month = parseInt(parsed[1], 10);
|
|
116
|
-
if (year === 2026 && month === 4) return 'oc-2026-04';
|
|
117
|
-
if (year === 2026 && month === 5) return 'oc-2026-05';
|
|
118
|
-
if (year === 2026 && month === 6) return 'oc-2026-06';
|
|
119
|
-
return 'oc-unknown';
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function getHostAdapterBlock(hostVersion) {
|
|
123
|
-
var adapterId = resolveHostAdapterId(hostVersion);
|
|
124
|
-
var adapterPath = path.join(adaptersDir, adapterId + '.js');
|
|
125
|
-
if (!fs.existsSync(adapterPath)) {
|
|
126
|
-
adapterId = 'oc-unknown';
|
|
127
|
-
adapterPath = path.join(adaptersDir, adapterId + '.js');
|
|
128
|
-
}
|
|
129
|
-
var adapterContent = fs.readFileSync(adapterPath, 'utf-8').trimEnd();
|
|
130
|
-
return [
|
|
131
|
-
HOST_ADAPTER_START,
|
|
132
|
-
'// HOST ADAPTER: ' + adapterId,
|
|
133
|
-
adapterContent,
|
|
134
|
-
HOST_ADAPTER_END,
|
|
135
|
-
].join('\n');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function injectHostAdapter(content, hostVersion) {
|
|
139
|
-
var block = getHostAdapterBlock(hostVersion);
|
|
140
|
-
if (HOST_ADAPTER_BLOCK_RE.test(content)) {
|
|
141
|
-
return content.replace(HOST_ADAPTER_BLOCK_RE, block);
|
|
142
|
-
}
|
|
143
|
-
return content;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function renderOverrideContent(content, hostVersion) {
|
|
147
|
-
return injectBuildId(injectHostAdapter(injectHostVersion(content, hostVersion), hostVersion));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function hashContent(content) {
|
|
151
|
-
return crypto.createHash('sha256').update(content).digest('hex').slice(0, 12);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function injectBuildId(content) {
|
|
155
|
-
var normalized = content.replace(BUILD_ID_ASSIGNMENT_RE, BUILD_ID_TOKEN);
|
|
156
|
-
var buildId = hashContent(normalized);
|
|
157
|
-
return normalized.replace(BUILD_ID_TOKEN, 'buildId: ' + JSON.stringify(buildId));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function resolveControlUiHostVersion(controlUiDir) {
|
|
161
|
-
if (process.env.OPENCLAW_HOST_VERSION) return normalizeHostVersion(process.env.OPENCLAW_HOST_VERSION);
|
|
162
|
-
|
|
163
|
-
var candidates = [
|
|
164
|
-
path.join(controlUiDir, '..', '..', 'package.json'),
|
|
165
|
-
path.join(controlUiDir, '..', 'package.json'),
|
|
166
|
-
];
|
|
167
|
-
for (var i = 0; i < candidates.length; i++) {
|
|
168
|
-
try {
|
|
169
|
-
if (!fs.existsSync(candidates[i])) continue;
|
|
170
|
-
var pkg = JSON.parse(fs.readFileSync(candidates[i], 'utf-8'));
|
|
171
|
-
if (pkg && pkg.name === 'openclaw') return normalizeHostVersion(pkg.version);
|
|
172
|
-
} catch (e) {}
|
|
173
|
-
}
|
|
174
|
-
return '';
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function pushUniquePath(list, candidate) {
|
|
178
|
-
if (!list || !candidate) return;
|
|
179
|
-
var resolved = path.resolve(candidate);
|
|
180
|
-
for (var i = 0; i < list.length; i++) {
|
|
181
|
-
if (path.resolve(list[i]) === resolved) return;
|
|
182
|
-
}
|
|
183
|
-
list.push(resolved);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function collectCommandOutputLines(command, args) {
|
|
187
|
-
try {
|
|
188
|
-
var result = childProcess.spawnSync(command, args, {
|
|
189
|
-
encoding: 'utf-8',
|
|
190
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
191
|
-
});
|
|
192
|
-
return String(result.stdout || '')
|
|
193
|
-
.split(/\r?\n/)
|
|
194
|
-
.map(function(line) { return line.trim(); })
|
|
195
|
-
.filter(Boolean);
|
|
196
|
-
} catch (e) {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function collectGlobalNodeModuleRoots() {
|
|
202
|
-
var roots = [];
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
pushUniquePath(roots, path.join(path.dirname(process.execPath), '..', 'lib', 'node_modules'));
|
|
206
|
-
} catch (e) {}
|
|
207
|
-
|
|
208
|
-
var npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
209
|
-
var npmRoots = collectCommandOutputLines(npmCommand, ['root', '-g']);
|
|
210
|
-
for (var n = 0; n < npmRoots.length; n++) {
|
|
211
|
-
pushUniquePath(roots, npmRoots[n]);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
var openclawLocator = process.platform === 'win32' ? 'where' : 'which';
|
|
215
|
-
var openclawBins = collectCommandOutputLines(openclawLocator, ['openclaw']);
|
|
216
|
-
for (var b = 0; b < openclawBins.length; b++) {
|
|
217
|
-
var binPath = openclawBins[b];
|
|
218
|
-
try {
|
|
219
|
-
pushUniquePath(roots, path.join(path.dirname(binPath), '..', 'lib', 'node_modules'));
|
|
220
|
-
} catch (e) {}
|
|
221
|
-
try {
|
|
222
|
-
var realBin = fs.realpathSync(binPath);
|
|
223
|
-
var needle = path.join('node_modules', 'openclaw');
|
|
224
|
-
var idx = realBin.lastIndexOf(needle);
|
|
225
|
-
if (idx >= 0) {
|
|
226
|
-
pushUniquePath(roots, realBin.substring(0, idx + 'node_modules'.length));
|
|
227
|
-
}
|
|
228
|
-
} catch (e) {}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return roots;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function addGlobalOpenclawTargets(deployTargets, assetTargets) {
|
|
235
|
-
var roots = collectGlobalNodeModuleRoots();
|
|
236
|
-
for (var i = 0; i < roots.length; i++) {
|
|
237
|
-
var root = roots[i];
|
|
238
|
-
pushUniquePath(deployTargets, path.join(root, 'openclaw', 'dist', 'control-ui', 'openagent-override.js'));
|
|
239
|
-
pushUniquePath(deployTargets, path.join(root, 'openclaw-openagent', 'src', 'plugin-ui', 'assets', 'openagent-override.js'));
|
|
240
|
-
pushUniquePath(deployTargets, path.join(root, 'openclaw-openagent', 'dist', 'src', 'plugin-ui', 'assets', 'openagent-override.js'));
|
|
241
|
-
|
|
242
|
-
pushUniquePath(assetTargets, path.join(root, 'openclaw', 'dist', 'control-ui'));
|
|
243
|
-
pushUniquePath(assetTargets, path.join(root, 'openclaw-openagent', 'src', 'plugin-ui', 'assets'));
|
|
244
|
-
pushUniquePath(assetTargets, path.join(root, 'openclaw-openagent', 'dist', 'src', 'plugin-ui', 'assets'));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function updateControlUiIndex(controlUiDir, contentHash, hostVersion) {
|
|
249
|
-
var indexPath = path.join(controlUiDir, 'index.html');
|
|
250
|
-
if (!fs.existsSync(indexPath)) return false;
|
|
251
|
-
|
|
252
|
-
var html = fs.readFileSync(indexPath, 'utf-8');
|
|
253
|
-
var htmlMarker = '<!--openagent:html-script-tag-->';
|
|
254
|
-
var hostVersionAttr = hostVersion ? ' data-openagent-host-version="' + hostVersion + '"' : '';
|
|
255
|
-
var scriptTag = htmlMarker + '<script src="./openagent-override.js?v=' + contentHash + '"' + hostVersionAttr + '></script>';
|
|
256
|
-
var markedScriptPattern = /(?:\/\*openagent:html-script-tag\*\/|<!--openagent:html-script-tag-->)<script[^>]*openagent-override[^>]*><\/script>\n?\s*/g;
|
|
257
|
-
var oldScriptPattern = /<script[^>]*openagent-override[^>]*><\/script>\n?\s*/g;
|
|
258
|
-
var nextHtml;
|
|
259
|
-
|
|
260
|
-
if (/(?:\/\*openagent:html-script-tag\*\/|<!--openagent:html-script-tag-->)/.test(html)) {
|
|
261
|
-
nextHtml = html.replace(markedScriptPattern, scriptTag + '\n ');
|
|
262
|
-
if (nextHtml === html && !nextHtml.includes('openagent-override.js')) {
|
|
263
|
-
nextHtml = nextHtml.replace(/(?:\/\*openagent:html-script-tag\*\/|<!--openagent:html-script-tag-->)/, scriptTag + '\n ');
|
|
264
|
-
} else if (nextHtml === html && nextHtml.includes('openagent-override.js')) {
|
|
265
|
-
nextHtml = nextHtml.replace(oldScriptPattern, '').replace(/(?:\/\*openagent:html-script-tag\*\/|<!--openagent:html-script-tag-->)/, scriptTag + '\n ');
|
|
266
|
-
}
|
|
267
|
-
} else {
|
|
268
|
-
nextHtml = html.replace(oldScriptPattern, '');
|
|
269
|
-
var viteAnchor = '<script type="module" crossorigin src="./assets/index-';
|
|
270
|
-
var anchorIdx = nextHtml.indexOf(viteAnchor);
|
|
271
|
-
if (anchorIdx >= 0) {
|
|
272
|
-
nextHtml = nextHtml.substring(0, anchorIdx) + scriptTag + '\n ' + nextHtml.substring(anchorIdx);
|
|
273
|
-
} else {
|
|
274
|
-
nextHtml = nextHtml.replace('</head>', scriptTag + '\n</head>');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (nextHtml && nextHtml !== html) {
|
|
279
|
-
fs.writeFileSync(indexPath, nextHtml, 'utf-8');
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const HEADER = `/**
|
|
286
|
-
* OpenAgent UI Override — Auto-generated, do not edit directly!
|
|
287
|
-
*
|
|
288
|
-
* Source: src/plugin-ui/modules/
|
|
289
|
-
* Built: ${new Date().toISOString()}
|
|
290
|
-
*
|
|
291
|
-
* To modify, edit the source modules and run:
|
|
292
|
-
* npm run build:override
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
(() => {
|
|
296
|
-
'use strict';
|
|
297
|
-
`;
|
|
298
|
-
|
|
299
|
-
const FOOTER = `
|
|
300
|
-
})();
|
|
301
|
-
`;
|
|
302
|
-
|
|
303
|
-
// ── Build Logic ──
|
|
304
|
-
|
|
305
|
-
function build() {
|
|
306
|
-
console.log(`\n[${new Date().toLocaleTimeString()}] Building override...`);
|
|
307
|
-
let body = '';
|
|
308
|
-
let errors = 0;
|
|
309
|
-
|
|
310
|
-
for (const file of MANIFEST) {
|
|
311
|
-
const filePath = path.join(modulesDir, file);
|
|
312
|
-
|
|
313
|
-
if (!fs.existsSync(filePath)) {
|
|
314
|
-
console.error(`❌ Missing module: ${file}`);
|
|
315
|
-
errors++;
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
320
|
-
body += `\n// ════════════════════════════════════════════════════════════════\n`;
|
|
321
|
-
body += `// MODULE: ${file}\n`;
|
|
322
|
-
body += `// ════════════════════════════════════════════════════════════════\n\n`;
|
|
323
|
-
body += content.trimEnd() + '\n';
|
|
324
|
-
if (file === 'loader/shared-state.js') {
|
|
325
|
-
body += `\n// ════════════════════════════════════════════════════════════════\n`;
|
|
326
|
-
body += `// MODULE: host-adapter/selected\n`;
|
|
327
|
-
body += `// ════════════════════════════════════════════════════════════════\n\n`;
|
|
328
|
-
body += getHostAdapterBlock('') + '\n';
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (errors > 0) {
|
|
333
|
-
console.error(`\n❌ Build failed: ${errors} missing module(s)`);
|
|
334
|
-
if (!isWatchMode) process.exit(1);
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// ── 不做构建时版本注入,由运行时 DOM/CSS 特征检测 ──
|
|
339
|
-
// (build.cjs 无法知道实际运行的 OpenClaw 版本)
|
|
340
|
-
var output = HEADER + body + FOOTER;
|
|
341
|
-
var assetOutput = renderOverrideContent(output, '');
|
|
342
|
-
|
|
343
|
-
fs.mkdirSync(path.dirname(outFile), { recursive: true });
|
|
344
|
-
fs.writeFileSync(outFile, assetOutput, 'utf-8');
|
|
345
|
-
|
|
346
|
-
const lineCount = assetOutput.split('\n').length;
|
|
347
|
-
console.log(`✅ Built: ${path.relative(process.cwd(), outFile)} (${lineCount} lines)`);
|
|
348
|
-
|
|
349
|
-
// ── Auto-deploy to runtime targets ──────────────────────────────────────
|
|
350
|
-
// 开发时自动复制到插件安装目录和 control-ui,省去手动 cp
|
|
351
|
-
// 任何 target 不存在都静默跳过(CI/CD 环境不影响)
|
|
352
|
-
|
|
353
|
-
const homedir = require('os').homedir();
|
|
354
|
-
|
|
355
|
-
const DEPLOY_TARGETS = [
|
|
356
|
-
// 插件安装目录(Gateway 启动时从这里读取并复制到 control-ui)
|
|
357
|
-
path.join(homedir, '.openclaw-docker/extensions/openclaw-openagent/src/inject/assets/openagent-override.js'),
|
|
358
|
-
path.join(homedir, '.openclaw-docker/extensions/openclaw-openagent/src/plugin-ui/assets/openagent-override.js'),
|
|
359
|
-
path.join(homedir, '.openclaw/extensions/openclaw-openagent/src/inject/assets/openagent-override.js'),
|
|
360
|
-
path.join(homedir, '.openclaw/extensions/openclaw-openagent/src/plugin-ui/assets/openagent-override.js'),
|
|
361
|
-
// 本地开发 dist/ 目录
|
|
362
|
-
path.join(__dirname, '..', '..', 'dist', 'src', 'plugin-ui', 'assets', 'openagent-override.js'),
|
|
363
|
-
// 本地 node_modules 中的 openclaw control-ui(Gateway 实际运行路径)
|
|
364
|
-
path.join(__dirname, '..', '..', 'node_modules', 'openclaw', 'dist', 'control-ui', 'openagent-override.js'),
|
|
365
|
-
// npm 全局安装 + 项目缓存(Gateway 可能从这些路径加载)
|
|
366
|
-
path.join(homedir, '.openclaw/npm/projects/openclaw-openagent/node_modules/openclaw-openagent/src/plugin-ui/assets/openagent-override.js'),
|
|
367
|
-
path.join(homedir, '.openclaw/npm/projects/openclaw-openagent/node_modules/openclaw-openagent/dist/src/plugin-ui/assets/openagent-override.js'),
|
|
368
|
-
path.join(homedir, '.nvm/versions/node/v22.21.1/lib/node_modules/openclaw-openagent/src/plugin-ui/assets/openagent-override.js'),
|
|
369
|
-
path.join(homedir, '.nvm/versions/node/v22.21.1/lib/node_modules/openclaw-openagent/dist/src/plugin-ui/assets/openagent-override.js'),
|
|
370
|
-
];
|
|
371
|
-
addGlobalOpenclawTargets(DEPLOY_TARGETS, null);
|
|
372
|
-
|
|
373
|
-
let deployed = 0;
|
|
374
|
-
for (const target of DEPLOY_TARGETS) {
|
|
375
|
-
try {
|
|
376
|
-
if (fs.existsSync(path.dirname(target))) {
|
|
377
|
-
const targetDir = path.dirname(target);
|
|
378
|
-
const hostVersion = path.basename(targetDir) === 'control-ui'
|
|
379
|
-
? resolveControlUiHostVersion(targetDir)
|
|
380
|
-
: '';
|
|
381
|
-
const targetOutput = renderOverrideContent(output, hostVersion);
|
|
382
|
-
fs.writeFileSync(target, targetOutput, 'utf-8');
|
|
383
|
-
if (hostVersion) {
|
|
384
|
-
const contentHash = hashContent(targetOutput);
|
|
385
|
-
if (updateControlUiIndex(targetDir, contentHash, hostVersion)) {
|
|
386
|
-
console.log(` ↻ updated index.html cache-bust (${hostVersion}, ${resolveHostAdapterId(hostVersion)}, ${contentHash})`);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
console.log(` → ${path.relative(homedir, target)}`);
|
|
390
|
-
deployed++;
|
|
391
|
-
}
|
|
392
|
-
} catch {}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (deployed > 0) {
|
|
396
|
-
console.log(`✅ Auto-deployed override to ${deployed} target(s)`);
|
|
397
|
-
} else {
|
|
398
|
-
console.log('ℹ️ No deploy targets found (standalone build)');
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// ── Shared asset deploy targets (control-ui + extension dirs) ──
|
|
402
|
-
const ASSET_DEPLOY_TARGETS = [
|
|
403
|
-
path.join(homedir, '.openclaw-docker/extensions/openclaw-openagent/src/inject/assets'),
|
|
404
|
-
path.join(homedir, '.openclaw-docker/extensions/openclaw-openagent/src/plugin-ui/assets'),
|
|
405
|
-
path.join(homedir, '.openclaw/extensions/openclaw-openagent/src/inject/assets'),
|
|
406
|
-
path.join(homedir, '.openclaw/extensions/openclaw-openagent/src/plugin-ui/assets'),
|
|
407
|
-
path.join(__dirname, '..', '..', 'dist', 'src', 'plugin-ui', 'assets'),
|
|
408
|
-
path.join(__dirname, '..', '..', 'node_modules', 'openclaw', 'dist', 'control-ui'),
|
|
409
|
-
path.join(homedir, '.openclaw/npm/projects/openclaw-openagent/node_modules/openclaw-openagent/src/plugin-ui/assets'),
|
|
410
|
-
path.join(homedir, '.openclaw/npm/projects/openclaw-openagent/node_modules/openclaw-openagent/dist/src/plugin-ui/assets'),
|
|
411
|
-
path.join(homedir, '.nvm/versions/node/v22.21.1/lib/node_modules/openclaw-openagent/src/plugin-ui/assets'),
|
|
412
|
-
path.join(homedir, '.nvm/versions/node/v22.21.1/lib/node_modules/openclaw-openagent/dist/src/plugin-ui/assets'),
|
|
413
|
-
];
|
|
414
|
-
addGlobalOpenclawTargets(null, ASSET_DEPLOY_TARGETS);
|
|
415
|
-
|
|
416
|
-
// ── Deploy image assets (icon.png, bg.png) ──
|
|
417
|
-
const IMAGE_ASSETS = [
|
|
418
|
-
{ file: iconFile, name: 'icon.png' },
|
|
419
|
-
{ file: bgFile, name: 'bg.png' },
|
|
420
|
-
];
|
|
421
|
-
|
|
422
|
-
for (const asset of IMAGE_ASSETS) {
|
|
423
|
-
if (!fs.existsSync(asset.file)) continue;
|
|
424
|
-
let deployed = 0;
|
|
425
|
-
for (const dir of ASSET_DEPLOY_TARGETS) {
|
|
426
|
-
try {
|
|
427
|
-
const dest = path.join(dir, asset.name);
|
|
428
|
-
if (fs.existsSync(dir)) {
|
|
429
|
-
fs.copyFileSync(asset.file, dest);
|
|
430
|
-
deployed++;
|
|
431
|
-
}
|
|
432
|
-
} catch {}
|
|
433
|
-
}
|
|
434
|
-
if (deployed > 0) {
|
|
435
|
-
console.log(`✅ Auto-deployed ${asset.name} to ${deployed} target(s)`);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// ── Execution ──
|
|
441
|
-
|
|
442
|
-
const isWatchMode = process.argv.includes('--watch');
|
|
443
|
-
|
|
444
|
-
build();
|
|
445
|
-
|
|
446
|
-
if (isWatchMode) {
|
|
447
|
-
console.log(`\n👀 Watching for changes in ${path.relative(process.cwd(), modulesDir)} and ${path.relative(process.cwd(), adaptersDir)}...`);
|
|
448
|
-
|
|
449
|
-
let debounceTimer;
|
|
450
|
-
function watchSourceDir(sourceDir) {
|
|
451
|
-
fs.watch(sourceDir, { recursive: true }, (eventType, filename) => {
|
|
452
|
-
// Ignore dot files and non-js files
|
|
453
|
-
if (!filename || filename.startsWith('.') || !filename.endsWith('.js')) return;
|
|
454
|
-
|
|
455
|
-
clearTimeout(debounceTimer);
|
|
456
|
-
debounceTimer = setTimeout(() => {
|
|
457
|
-
build();
|
|
458
|
-
}, 100);
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
watchSourceDir(modulesDir);
|
|
462
|
-
watchSourceDir(adaptersDir);
|
|
463
|
-
}
|
package/src/plugin-ui/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin UI — UIExtensionLoader 入口
|
|
3
|
-
*
|
|
4
|
-
* 将 UI 扩展加载委托给 ui-extension-loader 模块。
|
|
5
|
-
* 保持对外 API 不变(injectControlUiOverride),内部全部走新框架。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { loadUIExtensions } from './ui-extension-loader/index.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 加载全部 UI 扩展。
|
|
12
|
-
*
|
|
13
|
-
* 由 index.ts register() 调用。内部通过 Manifest Reconciler
|
|
14
|
-
* 自动完成扩展点的 apply / revert / skip。
|
|
15
|
-
*/
|
|
16
|
-
export async function injectControlUiOverride(hostVersion?: string): Promise<void> {
|
|
17
|
-
await loadUIExtensions({ hostVersion });
|
|
18
|
-
}
|