@aiyiran/myclaw 1.0.146 → 1.0.152
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-tts.js +40 -38
- package/create_agent.js +8 -15
- package/index.js +378 -233
- package/inject-clear-models.js +117 -0
- package/inject-image.js +2 -2
- package/inject-minimax.js +35 -1
- package/inject-search.js +13 -4
- package/inject-token.js +1 -1
- package/inject-zai.js +40 -1
- package/package.json +1 -1
- package/patch-agent.js +17 -17
- package/patch-manifest.json +10 -2
- package/patch-skill.js +15 -15
- package/patch.js +48 -44
package/assets/myclaw-tts.js
CHANGED
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
// ═══
|
|
47
|
+
// ═══ 状态文字(带 ↑ 图标) ═══
|
|
48
48
|
var STATE_TEXT = {
|
|
49
|
-
idle: '播放',
|
|
50
|
-
generating: '生成中',
|
|
51
|
-
playing: '播放中',
|
|
49
|
+
idle: '↑ 播放',
|
|
50
|
+
generating: '↑ 生成中',
|
|
51
|
+
playing: '↑ 播放中',
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
// ═══ 提取消息文字 ═══
|
|
@@ -63,7 +63,19 @@
|
|
|
63
63
|
if (!chatText) return '';
|
|
64
64
|
|
|
65
65
|
var text = chatText.textContent || '';
|
|
66
|
-
|
|
66
|
+
text = text.replace(/\s+/g, ' ').trim();
|
|
67
|
+
|
|
68
|
+
// 讯飞 TTS 长度限制:截断到 3200 字符
|
|
69
|
+
var MAX_LENGTH = 3200;
|
|
70
|
+
if (text.length > MAX_LENGTH) {
|
|
71
|
+
text = text.substring(0, MAX_LENGTH);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// log 显示文本开头和结尾
|
|
75
|
+
var preview = text.substring(0, 20) + '...' + text.substring(Math.max(0, text.length - 20));
|
|
76
|
+
console.log('[myclaw-tts] 提取文本 (' + text.length + ' 字符):', preview);
|
|
77
|
+
|
|
78
|
+
return text;
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
// ═══ 创建按钮 ═══
|
|
@@ -140,13 +152,6 @@
|
|
|
140
152
|
};
|
|
141
153
|
tts.vcn = IFLYTEK_CONFIG.vcn;
|
|
142
154
|
tts.speak(text);
|
|
143
|
-
|
|
144
|
-
// 等待合成完成进入播放状态
|
|
145
|
-
setTimeout(function () {
|
|
146
|
-
if (playerState === 'generating') {
|
|
147
|
-
updateBtn(btn, 'playing');
|
|
148
|
-
}
|
|
149
|
-
}, 150);
|
|
150
155
|
}
|
|
151
156
|
});
|
|
152
157
|
|
|
@@ -155,28 +160,13 @@
|
|
|
155
160
|
console.log('[myclaw-tts] ✅ 播放按钮已注入');
|
|
156
161
|
}
|
|
157
162
|
|
|
158
|
-
// ═══
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
// 直接是 footer
|
|
166
|
-
if (node.classList && node.classList.contains('chat-group-footer')) {
|
|
167
|
-
injectBtn(node);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// footer 内部的子节点
|
|
171
|
-
if (node.querySelectorAll) {
|
|
172
|
-
node.querySelectorAll('.chat-group-footer').forEach(injectBtn);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}).observe(document.documentElement, { childList: true, subtree: true });
|
|
177
|
-
|
|
178
|
-
// 立即处理已有的 footer
|
|
179
|
-
document.querySelectorAll('.chat-group-footer').forEach(injectBtn);
|
|
163
|
+
// ═══ 定期扫描 footer 并注入按钮 ═══
|
|
164
|
+
function scanFooters() {
|
|
165
|
+
document.querySelectorAll('.chat-group-footer').forEach(function (footer) {
|
|
166
|
+
if (!footer.querySelector('.myclaw-tts-btn')) {
|
|
167
|
+
injectBtn(footer);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
180
170
|
}
|
|
181
171
|
|
|
182
172
|
// ═══ 初始化 TTS ═══
|
|
@@ -195,8 +185,11 @@
|
|
|
195
185
|
onStatusChange: function (oldStatus, newStatus) {
|
|
196
186
|
console.log('[myclaw-tts] status:', oldStatus, '->', newStatus);
|
|
197
187
|
|
|
198
|
-
if (newStatus === 'idle' && playerState === 'generating') {
|
|
199
|
-
//
|
|
188
|
+
if (oldStatus === 'synthesizing' && newStatus === 'idle' && playerState === 'generating') {
|
|
189
|
+
// 合成完成,开始播放
|
|
190
|
+
if (currentBtn) updateBtn(currentBtn, 'playing');
|
|
191
|
+
} else if (newStatus === 'idle' && playerState === 'generating' && oldStatus !== 'synthesizing') {
|
|
192
|
+
// 连接失败或其他错误(非正常完成)
|
|
200
193
|
if (currentBtn) updateBtn(currentBtn, 'idle');
|
|
201
194
|
currentBtn = null;
|
|
202
195
|
}
|
|
@@ -220,8 +213,10 @@
|
|
|
220
213
|
var style = document.createElement('style');
|
|
221
214
|
style.id = 'myclaw-tts-styles';
|
|
222
215
|
style.textContent = [
|
|
223
|
-
/* 按钮基础样式 */
|
|
216
|
+
/* 按钮基础样式 — 默认隐藏,生成完毕后显示,永远不透明 */
|
|
224
217
|
'.myclaw-tts-btn {',
|
|
218
|
+
' display: none !important;',
|
|
219
|
+
' opacity: 1 !important;',
|
|
225
220
|
' background: rgba(59, 130, 246, 0.1);',
|
|
226
221
|
' border: 1px solid rgba(59, 130, 246, 0.3);',
|
|
227
222
|
' border-radius: 4px;',
|
|
@@ -252,6 +247,10 @@
|
|
|
252
247
|
' 0%, 100% { opacity: 1; }',
|
|
253
248
|
' 50% { opacity: 0.5; }',
|
|
254
249
|
'}',
|
|
250
|
+
/* 生成完毕(有 chat-delete-wrap)时显示 */
|
|
251
|
+
'.chat-group-footer:has(.chat-delete-wrap) .myclaw-tts-btn {',
|
|
252
|
+
' display: inline-flex !important;',
|
|
253
|
+
'}',
|
|
255
254
|
].join('\n');
|
|
256
255
|
document.head.appendChild(style);
|
|
257
256
|
}
|
|
@@ -260,7 +259,10 @@
|
|
|
260
259
|
function init() {
|
|
261
260
|
injectStyles();
|
|
262
261
|
initTts();
|
|
263
|
-
|
|
262
|
+
// 立即扫描一次
|
|
263
|
+
scanFooters();
|
|
264
|
+
// 定期扫描新出现的 footer
|
|
265
|
+
setInterval(scanFooters, 1000);
|
|
264
266
|
console.log('[myclaw-tts] ✅ 初始化完成');
|
|
265
267
|
}
|
|
266
268
|
|
package/create_agent.js
CHANGED
|
@@ -89,11 +89,7 @@ function buildBirthMessage() {
|
|
|
89
89
|
const h = String(nowBj.getUTCHours()).padStart(2, '0');
|
|
90
90
|
const min = String(nowBj.getUTCMinutes()).padStart(2, '0');
|
|
91
91
|
const ts = `${y}年${m}月${d}日${h}:${min}`;
|
|
92
|
-
return
|
|
93
|
-
`你好,你的生日是北京时间${ts},请记录这个信息。\n` +
|
|
94
|
-
'欢迎你来到这个世界,我是你的造物主,我们是伙伴,我叫做孙依然,' +
|
|
95
|
-
'你可以叫我依然,请多多指教,共同成长。'
|
|
96
|
-
);
|
|
92
|
+
return `你好,你的生日是北京时间${ts},请记录这个信息。`;
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
/**
|
|
@@ -121,8 +117,6 @@ function defaultWorkspaceFiles(agentId) {
|
|
|
121
117
|
),
|
|
122
118
|
'USER.md': (
|
|
123
119
|
'# USER.md\n\n' +
|
|
124
|
-
'- Name: 孙依然\n' +
|
|
125
|
-
'- What to call them: 依然\n' +
|
|
126
120
|
'- Timezone: Asia/Shanghai\n\n' +
|
|
127
121
|
'Build understanding gradually and respectfully.\n'
|
|
128
122
|
),
|
|
@@ -240,20 +234,20 @@ function createAgent(rawName, opts) {
|
|
|
240
234
|
fail('配置文件写入失败: ' + err.message + '\n备份文件: ' + normalizePath(backupPath));
|
|
241
235
|
}
|
|
242
236
|
|
|
243
|
-
//
|
|
237
|
+
// 发送首条消息:发起后不等待,后续由后端服务处理
|
|
244
238
|
const birthMessage = opts.firstMessage || buildBirthMessage();
|
|
245
239
|
let firstMessageSent = false;
|
|
246
|
-
let firstMessageError = null;
|
|
247
240
|
|
|
248
241
|
try {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
242
|
+
const { spawn } = require('child_process');
|
|
243
|
+
spawn('openclaw', ['agent', '--agent', agentId, '--message', birthMessage, '--json'], {
|
|
244
|
+
detached: true,
|
|
245
|
+
stdio: 'ignore',
|
|
246
|
+
shell: true,
|
|
247
|
+
}).unref();
|
|
253
248
|
firstMessageSent = true;
|
|
254
249
|
} catch (err) {
|
|
255
250
|
firstMessageSent = false;
|
|
256
|
-
firstMessageError = err.message;
|
|
257
251
|
}
|
|
258
252
|
|
|
259
253
|
// 返回结果
|
|
@@ -266,7 +260,6 @@ function createAgent(rawName, opts) {
|
|
|
266
260
|
configBackup: normalizePath(backupPath),
|
|
267
261
|
birthMessage: birthMessage,
|
|
268
262
|
firstMessageSent: firstMessageSent,
|
|
269
|
-
firstMessageError: firstMessageError,
|
|
270
263
|
};
|
|
271
264
|
}
|
|
272
265
|
|