@aiyiran/myclaw 1.0.195 → 1.0.197
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/assets/myclaw-artifacts.js +263 -0
- package/assets/myclaw-inject.js +3 -3
- package/package.json +1 -1
- package/patch.js +19 -45
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* MyClaw Artifacts — 学生作品展示面板
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* 功能:
|
|
7
|
+
* 右下角 "🎨 作品" 按钮,点击弹出作品面板
|
|
8
|
+
* 从 workspace 的 .myclaw/__MY_ARTIFACTS__.json 读取作品清单
|
|
9
|
+
*
|
|
10
|
+
* JSON 数据格式:
|
|
11
|
+
* {
|
|
12
|
+
* "workspace_id": "main",
|
|
13
|
+
* "assets": [
|
|
14
|
+
* { "name": "射击游戏", "type": "html", "path": "myclaw/shooting-game.html" }
|
|
15
|
+
* ]
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* URL 拼接规则:
|
|
19
|
+
* {origin}/cmd/api/preview?path={wsPrefix}/{asset.path}
|
|
20
|
+
* main → workspace, 其他 → workspace-{name}
|
|
21
|
+
* ============================================================================
|
|
22
|
+
*/
|
|
23
|
+
(function () {
|
|
24
|
+
'use strict';
|
|
25
|
+
|
|
26
|
+
// ═══ 状态 ═══
|
|
27
|
+
var artifactsOpen = false;
|
|
28
|
+
|
|
29
|
+
// ═══ 工具:从 URL 解析 agent 名称 ═══
|
|
30
|
+
function getAgentName() {
|
|
31
|
+
var params = new URLSearchParams(window.location.search);
|
|
32
|
+
// 优先从 session 参数解析: agent:main:feishu:... → main
|
|
33
|
+
var session = params.get('session');
|
|
34
|
+
if (session) {
|
|
35
|
+
var decoded = decodeURIComponent(session);
|
|
36
|
+
if (decoded.indexOf('agent:') === 0) {
|
|
37
|
+
var parts = decoded.split(':');
|
|
38
|
+
if (parts.length >= 2) return parts[1];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// fallback: agent 参数
|
|
42
|
+
var agent = params.get('agent');
|
|
43
|
+
if (agent) return agent;
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ═══ 创建按钮 ═══
|
|
48
|
+
function createArtifactsButton() {
|
|
49
|
+
if (document.querySelector('#myclaw-artifacts-btn')) return;
|
|
50
|
+
|
|
51
|
+
var btn = document.createElement('div');
|
|
52
|
+
btn.id = 'myclaw-artifacts-btn';
|
|
53
|
+
btn.style.cssText = [
|
|
54
|
+
'position: fixed',
|
|
55
|
+
'bottom: 8px',
|
|
56
|
+
'right: 140px',
|
|
57
|
+
'padding: 3px 10px',
|
|
58
|
+
'background: rgba(100, 100, 100, 0.7)',
|
|
59
|
+
'color: #fff',
|
|
60
|
+
'font-size: 11px',
|
|
61
|
+
'font-weight: bold',
|
|
62
|
+
'font-family: monospace',
|
|
63
|
+
'border-radius: 4px',
|
|
64
|
+
'z-index: 99999',
|
|
65
|
+
'user-select: none',
|
|
66
|
+
'cursor: pointer',
|
|
67
|
+
'transition: all 0.2s',
|
|
68
|
+
'letter-spacing: 0.5px',
|
|
69
|
+
].join(';');
|
|
70
|
+
btn.textContent = '\uD83C\uDFA8 \u4F5C\u54C1';
|
|
71
|
+
btn.title = '\u67E5\u770B\u5B66\u751F\u4F5C\u54C1';
|
|
72
|
+
|
|
73
|
+
btn.onmouseenter = function () { btn.style.background = 'rgba(80, 80, 80, 0.95)'; btn.style.transform = 'scale(1.05)'; };
|
|
74
|
+
btn.onmouseleave = function () { if (!artifactsOpen) { btn.style.background = 'rgba(100, 100, 100, 0.7)'; } btn.style.transform = 'scale(1)'; };
|
|
75
|
+
btn.onclick = function (e) {
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
if (artifactsOpen) {
|
|
78
|
+
closeArtifactsPanel();
|
|
79
|
+
} else {
|
|
80
|
+
openArtifactsPanel();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
document.body.appendChild(btn);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ═══ 打开面板 ═══
|
|
88
|
+
function openArtifactsPanel() {
|
|
89
|
+
if (document.querySelector('#myclaw-artifacts-modal')) return;
|
|
90
|
+
artifactsOpen = true;
|
|
91
|
+
|
|
92
|
+
// 按钮 active 态
|
|
93
|
+
var btn = document.querySelector('#myclaw-artifacts-btn');
|
|
94
|
+
if (btn) btn.style.background = 'rgba(80, 80, 80, 0.95)';
|
|
95
|
+
|
|
96
|
+
// 遮罩
|
|
97
|
+
var overlay = document.createElement('div');
|
|
98
|
+
overlay.id = 'myclaw-artifacts-modal';
|
|
99
|
+
overlay.style.cssText = [
|
|
100
|
+
'position: fixed',
|
|
101
|
+
'top: 0',
|
|
102
|
+
'left: 0',
|
|
103
|
+
'width: 100vw',
|
|
104
|
+
'height: 100vh',
|
|
105
|
+
'background: rgba(0, 0, 0, 0.3)',
|
|
106
|
+
'z-index: 99998',
|
|
107
|
+
'display: flex',
|
|
108
|
+
'align-items: center',
|
|
109
|
+
'justify-content: center',
|
|
110
|
+
'animation: myclaw-fade-in 0.15s ease',
|
|
111
|
+
].join(';');
|
|
112
|
+
|
|
113
|
+
// 面板容器
|
|
114
|
+
var box = document.createElement('div');
|
|
115
|
+
box.style.cssText = [
|
|
116
|
+
'width: 480px',
|
|
117
|
+
'max-height: 70vh',
|
|
118
|
+
'background: #1e1e2e',
|
|
119
|
+
'border-radius: 8px',
|
|
120
|
+
'overflow: hidden',
|
|
121
|
+
'display: flex',
|
|
122
|
+
'flex-direction: column',
|
|
123
|
+
'box-shadow: 0 8px 32px rgba(0,0,0,0.4)',
|
|
124
|
+
].join(';');
|
|
125
|
+
|
|
126
|
+
// 标题栏
|
|
127
|
+
var header = document.createElement('div');
|
|
128
|
+
header.style.cssText = [
|
|
129
|
+
'display: flex',
|
|
130
|
+
'align-items: center',
|
|
131
|
+
'justify-content: space-between',
|
|
132
|
+
'padding: 10px 16px',
|
|
133
|
+
'background: #2d2d3f',
|
|
134
|
+
'color: #cdd6f4',
|
|
135
|
+
'font-size: 14px',
|
|
136
|
+
'font-family: monospace',
|
|
137
|
+
'user-select: none',
|
|
138
|
+
].join(';');
|
|
139
|
+
header.innerHTML = '<span>\uD83C\uDFA8 \u5B66\u751F\u4F5C\u54C1</span>';
|
|
140
|
+
|
|
141
|
+
var closeBtn = document.createElement('span');
|
|
142
|
+
closeBtn.textContent = '\u2715';
|
|
143
|
+
closeBtn.style.cssText = 'cursor:pointer;padding:2px 6px;border-radius:3px;font-size:14px;transition:background 0.15s;';
|
|
144
|
+
closeBtn.onmouseenter = function () { closeBtn.style.background = 'rgba(255,255,255,0.1)'; };
|
|
145
|
+
closeBtn.onmouseleave = function () { closeBtn.style.background = 'none'; };
|
|
146
|
+
closeBtn.onclick = function () { closeArtifactsPanel(); };
|
|
147
|
+
header.appendChild(closeBtn);
|
|
148
|
+
|
|
149
|
+
// 内容区
|
|
150
|
+
var content = document.createElement('div');
|
|
151
|
+
content.id = 'myclaw-artifacts-content';
|
|
152
|
+
content.style.cssText = [
|
|
153
|
+
'flex: 1',
|
|
154
|
+
'overflow-y: auto',
|
|
155
|
+
'padding: 16px',
|
|
156
|
+
'color: #cdd6f4',
|
|
157
|
+
'font-family: monospace',
|
|
158
|
+
'font-size: 13px',
|
|
159
|
+
].join(';');
|
|
160
|
+
|
|
161
|
+
// 加载中
|
|
162
|
+
content.innerHTML = '<div style="text-align:center;padding:32px;color:#888;">加载中...</div>';
|
|
163
|
+
|
|
164
|
+
box.appendChild(header);
|
|
165
|
+
box.appendChild(content);
|
|
166
|
+
overlay.appendChild(box);
|
|
167
|
+
|
|
168
|
+
// 点击遮罩关闭
|
|
169
|
+
overlay.onclick = function (e) {
|
|
170
|
+
if (e.target === overlay) closeArtifactsPanel();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
document.body.appendChild(overlay);
|
|
174
|
+
|
|
175
|
+
// 异步请求数据
|
|
176
|
+
fetchArtifacts(content);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ═══ 请求数据 ═══
|
|
180
|
+
function fetchArtifacts(contentEl) {
|
|
181
|
+
var url = window.location.origin + '/cmd/api/preview?path=.myclaw/__MY_ARTIFACTS__.json';
|
|
182
|
+
fetch(url)
|
|
183
|
+
.then(function (res) {
|
|
184
|
+
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
185
|
+
return res.json();
|
|
186
|
+
})
|
|
187
|
+
.then(function (data) {
|
|
188
|
+
if (!data || !data.assets || !data.assets.length) {
|
|
189
|
+
contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#888;">暂无作品</div>';
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
renderArtifactsList(contentEl, data);
|
|
193
|
+
})
|
|
194
|
+
.catch(function (err) {
|
|
195
|
+
console.error('[myclaw-artifacts] 加载失败:', err);
|
|
196
|
+
contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#ff6b6b;">加载失败,请稍后重试</div>';
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ═══ 渲染列表 ═══
|
|
201
|
+
function renderArtifactsList(container, data) {
|
|
202
|
+
container.innerHTML = '';
|
|
203
|
+
// 拼接: base + workspace前缀 + / + 资源路径
|
|
204
|
+
// main → workspace, 其他 → workspace-{name}
|
|
205
|
+
var wsName = data.workspace_id || '';
|
|
206
|
+
var wsPrefix = wsName === 'main' ? 'workspace' : 'workspace-' + wsName;
|
|
207
|
+
var baseUrl = window.location.origin + '/cmd/api/preview?path=' + wsPrefix + '/';
|
|
208
|
+
|
|
209
|
+
data.assets.forEach(function (asset) {
|
|
210
|
+
var card = document.createElement('a');
|
|
211
|
+
card.href = baseUrl + asset.path;
|
|
212
|
+
card.target = '_blank';
|
|
213
|
+
card.rel = 'noopener noreferrer';
|
|
214
|
+
card.style.cssText = [
|
|
215
|
+
'display: block',
|
|
216
|
+
'padding: 12px 14px',
|
|
217
|
+
'margin-bottom: 10px',
|
|
218
|
+
'background: #2d2d3f',
|
|
219
|
+
'border-radius: 6px',
|
|
220
|
+
'color: #cdd6f4',
|
|
221
|
+
'text-decoration: none',
|
|
222
|
+
'transition: background 0.15s',
|
|
223
|
+
'cursor: pointer',
|
|
224
|
+
].join(';');
|
|
225
|
+
card.onmouseenter = function () { card.style.background = '#3d3d5c'; };
|
|
226
|
+
card.onmouseleave = function () { card.style.background = '#2d2d3f'; };
|
|
227
|
+
|
|
228
|
+
var title = document.createElement('div');
|
|
229
|
+
title.style.cssText = 'font-size: 14px; font-weight: bold; margin-bottom: 4px;';
|
|
230
|
+
title.textContent = asset.name || '未命名作品';
|
|
231
|
+
|
|
232
|
+
var meta = document.createElement('div');
|
|
233
|
+
meta.style.cssText = 'font-size: 11px; color: #888;';
|
|
234
|
+
meta.textContent = asset.type ? asset.type.toUpperCase() : '';
|
|
235
|
+
|
|
236
|
+
card.appendChild(title);
|
|
237
|
+
card.appendChild(meta);
|
|
238
|
+
container.appendChild(card);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ═══ 关闭面板 ═══
|
|
243
|
+
function closeArtifactsPanel() {
|
|
244
|
+
var modal = document.querySelector('#myclaw-artifacts-modal');
|
|
245
|
+
if (modal) modal.remove();
|
|
246
|
+
artifactsOpen = false;
|
|
247
|
+
|
|
248
|
+
var btn = document.querySelector('#myclaw-artifacts-btn');
|
|
249
|
+
if (btn) btn.style.background = 'rgba(100, 100, 100, 0.7)';
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ═══ 启动 ═══
|
|
253
|
+
function init() {
|
|
254
|
+
createArtifactsButton();
|
|
255
|
+
console.log('[myclaw-artifacts] ✅ 初始化完成');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (document.readyState === 'loading') {
|
|
259
|
+
document.addEventListener('DOMContentLoaded', init);
|
|
260
|
+
} else {
|
|
261
|
+
init();
|
|
262
|
+
}
|
|
263
|
+
})();
|
package/assets/myclaw-inject.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
bar.style.cssText = [
|
|
38
38
|
"position: fixed",
|
|
39
39
|
"bottom: 8px",
|
|
40
|
-
"right:
|
|
40
|
+
"right: 40px",
|
|
41
41
|
"padding: 2px 8px",
|
|
42
42
|
"background: none",
|
|
43
43
|
"color: rgba(150, 150, 150, 0.4)",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
btn.style.cssText = [
|
|
71
71
|
"position: fixed",
|
|
72
72
|
"bottom: 8px",
|
|
73
|
-
"right:
|
|
73
|
+
"right: 120px",
|
|
74
74
|
"padding: 2px 8px",
|
|
75
75
|
"background: none",
|
|
76
76
|
"color: rgba(150, 150, 150, 0.4)",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
btn.style.cssText = [
|
|
106
106
|
"position: fixed",
|
|
107
107
|
"bottom: 8px",
|
|
108
|
-
"right:
|
|
108
|
+
"right: 190px",
|
|
109
109
|
"padding: 3px 10px",
|
|
110
110
|
"background: rgba(59, 130, 246, 0.85)",
|
|
111
111
|
"color: #fff",
|
package/package.json
CHANGED
package/patch.js
CHANGED
|
@@ -26,6 +26,7 @@ const INJECT_FILENAME = 'myclaw-inject.js';
|
|
|
26
26
|
const VOICE_SDK_FILENAME = 'voice-input.js';
|
|
27
27
|
const VOICE_OUTPUT_SDK_FILENAME = 'voice-output.js';
|
|
28
28
|
const TTS_INJECT_FILENAME = 'myclaw-tts.js';
|
|
29
|
+
const ARTIFACTS_INJECT_FILENAME = 'myclaw-artifacts.js';
|
|
29
30
|
const BACKUP_SUFFIX = '.myclaw-backup';
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -115,6 +116,8 @@ function patch() {
|
|
|
115
116
|
const voiceOutputSdkDest = path.join(uiDir, VOICE_OUTPUT_SDK_FILENAME);
|
|
116
117
|
const ttsInjectSrc = path.join(__dirname, 'assets', TTS_INJECT_FILENAME);
|
|
117
118
|
const ttsInjectDest = path.join(uiDir, TTS_INJECT_FILENAME);
|
|
119
|
+
const artifactsInjectSrc = path.join(__dirname, 'assets', ARTIFACTS_INJECT_FILENAME);
|
|
120
|
+
const artifactsInjectDest = path.join(uiDir, ARTIFACTS_INJECT_FILENAME);
|
|
118
121
|
const version = getMyclawVersion();
|
|
119
122
|
|
|
120
123
|
console.log('[myclaw-patch] → control-ui: ' + uiDir);
|
|
@@ -166,6 +169,14 @@ function patch() {
|
|
|
166
169
|
console.error('[myclaw-patch] ⚠ TTS 注入脚本复制失败 (非致命): ' + err.message);
|
|
167
170
|
}
|
|
168
171
|
|
|
172
|
+
// 5.5 复制 Artifacts 注入脚本
|
|
173
|
+
try {
|
|
174
|
+
fs.copyFileSync(artifactsInjectSrc, artifactsInjectDest);
|
|
175
|
+
console.log('[myclaw-patch] ✅ Artifacts 注入脚本已复制');
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.error('[myclaw-patch] ⚠ Artifacts 注入脚本复制失败 (非致命): ' + err.message);
|
|
178
|
+
}
|
|
179
|
+
|
|
169
180
|
// 6. Patch index.html(幂等)
|
|
170
181
|
try {
|
|
171
182
|
let html = fs.readFileSync(indexPath, 'utf8');
|
|
@@ -183,6 +194,7 @@ function patch() {
|
|
|
183
194
|
'<script src="./' + VOICE_OUTPUT_SDK_FILENAME + '"></script>',
|
|
184
195
|
'<script src="./' + VOICE_SDK_FILENAME + '"></script>',
|
|
185
196
|
'<script src="./' + TTS_INJECT_FILENAME + '"></script>',
|
|
197
|
+
'<script src="./' + ARTIFACTS_INJECT_FILENAME + '"></script>',
|
|
186
198
|
'<script src="./' + INJECT_FILENAME + '"></script>',
|
|
187
199
|
'',
|
|
188
200
|
].join('\n');
|
|
@@ -246,51 +258,6 @@ function patch() {
|
|
|
246
258
|
console.error('[myclaw-patch] ⚠ Permissions-Policy 修复失败 (非致命): ' + err.message);
|
|
247
259
|
}
|
|
248
260
|
|
|
249
|
-
// 8. Patch X-Frame-Options + frame-ancestors(允许同域 iframe 嵌入)
|
|
250
|
-
try {
|
|
251
|
-
const distParent = path.resolve(uiDir, '..');
|
|
252
|
-
const distFiles = fs.readdirSync(distParent);
|
|
253
|
-
let framePatched = false;
|
|
254
|
-
|
|
255
|
-
for (const f of distFiles) {
|
|
256
|
-
if (f.endsWith('.js' + BACKUP_SUFFIX)) continue; // 跳过备份文件
|
|
257
|
-
const isTarget = (f.startsWith('gateway-cli-') || f.startsWith('server-')) && f.endsWith('.js');
|
|
258
|
-
if (!isTarget) continue;
|
|
259
|
-
|
|
260
|
-
const filePath = path.join(distParent, f);
|
|
261
|
-
let content = fs.readFileSync(filePath, 'utf8');
|
|
262
|
-
let modified = false;
|
|
263
|
-
|
|
264
|
-
// X-Frame-Options: DENY → SAMEORIGIN
|
|
265
|
-
if (content.includes('"DENY"')) {
|
|
266
|
-
const backupFile = filePath + BACKUP_SUFFIX;
|
|
267
|
-
if (!fs.existsSync(backupFile)) {
|
|
268
|
-
fs.copyFileSync(filePath, backupFile);
|
|
269
|
-
}
|
|
270
|
-
content = content.replace(/"X-Frame-Options",\s*"DENY"/g, '"X-Frame-Options", "SAMEORIGIN"');
|
|
271
|
-
modified = true;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// frame-ancestors 'none' → 'self'
|
|
275
|
-
if (content.includes("'none'") && content.includes("frame-ancestors")) {
|
|
276
|
-
content = content.replace(/frame-ancestors\s*'none'/g, "frame-ancestors 'self'");
|
|
277
|
-
modified = true;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (modified) {
|
|
281
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
282
|
-
console.log('[myclaw-patch] ✅ 已修复 iframe 安全头 (X-Frame-Options + frame-ancestors): ' + f);
|
|
283
|
-
framePatched = true;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (!framePatched) {
|
|
288
|
-
console.log('[myclaw-patch] ⚠ 未找到 iframe 安全头配置');
|
|
289
|
-
}
|
|
290
|
-
} catch (err) {
|
|
291
|
-
console.error('[myclaw-patch] ⚠ iframe 安全头修复失败 (非致命): ' + err.message);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
261
|
console.log('[myclaw-patch] ✅ 注入完成,重启 Gateway 后生效');
|
|
295
262
|
return { success: true, uiDir: uiDir, version: version };
|
|
296
263
|
}
|
|
@@ -311,6 +278,7 @@ function unpatch() {
|
|
|
311
278
|
const voiceSdkDest = path.join(uiDir, VOICE_SDK_FILENAME);
|
|
312
279
|
const voiceOutputSdkDest = path.join(uiDir, VOICE_OUTPUT_SDK_FILENAME);
|
|
313
280
|
const ttsInjectDest = path.join(uiDir, TTS_INJECT_FILENAME);
|
|
281
|
+
const artifactsInjectDest = path.join(uiDir, ARTIFACTS_INJECT_FILENAME);
|
|
314
282
|
|
|
315
283
|
// 恢复备份
|
|
316
284
|
if (fs.existsSync(backupPath)) {
|
|
@@ -343,6 +311,12 @@ function unpatch() {
|
|
|
343
311
|
console.log('[myclaw-patch] ✅ TTS 注入脚本已删除');
|
|
344
312
|
}
|
|
345
313
|
|
|
314
|
+
// 删除 Artifacts 注入脚本
|
|
315
|
+
if (fs.existsSync(artifactsInjectDest)) {
|
|
316
|
+
fs.unlinkSync(artifactsInjectDest);
|
|
317
|
+
console.log('[myclaw-patch] ✅ Artifacts 注入脚本已删除');
|
|
318
|
+
}
|
|
319
|
+
|
|
346
320
|
// 恢复 gateway-cli-*.js 的 Permissions-Policy
|
|
347
321
|
try {
|
|
348
322
|
const distParent = path.resolve(uiDir, '..');
|