openclaw-openagent 1.0.9 → 1.0.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.
Files changed (64) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/src/app/remote-agent-tool.js +110 -14
  3. package/dist/src/app/types.d.ts +2 -2
  4. package/dist/src/plugin-ui/adapters/adapters/oc-2026-04.js +103 -0
  5. package/dist/src/plugin-ui/adapters/adapters/oc-2026-05.js +125 -0
  6. package/dist/src/plugin-ui/adapters/adapters/oc-2026-06.js +125 -0
  7. package/dist/src/plugin-ui/adapters/adapters/oc-unknown.js +48 -0
  8. package/dist/src/plugin-ui/adapters/oc-2026-04.js +103 -0
  9. package/dist/src/plugin-ui/adapters/oc-2026-05.js +125 -0
  10. package/dist/src/plugin-ui/adapters/oc-2026-06.js +125 -0
  11. package/dist/src/plugin-ui/adapters/oc-unknown.js +48 -0
  12. package/dist/src/plugin-ui/assets/bg.png +0 -0
  13. package/dist/src/plugin-ui/assets/icon.png +0 -0
  14. package/dist/src/plugin-ui/assets/openagent-override.js +2480 -1004
  15. package/dist/src/plugin-ui/index.d.ts +1 -1
  16. package/dist/src/plugin-ui/index.js +2 -2
  17. package/dist/src/plugin-ui/ui-extension-loader/index.d.ts +2 -1
  18. package/dist/src/plugin-ui/ui-extension-loader/index.js +5 -5
  19. package/dist/src/plugin-ui/ui-extension-loader/registry-regex.js +128 -13
  20. package/dist/src/plugin-ui/ui-extension-loader/types.d.ts +4 -1
  21. package/dist/src/state/store.d.ts +21 -0
  22. package/dist/src/state/store.js +54 -0
  23. package/dist/src/transport/oasn/oasn-invocation.d.ts +3 -0
  24. package/dist/src/transport/oasn/oasn-invocation.js +28 -12
  25. package/dist/src/transport/oasn/oasn-types.d.ts +8 -4
  26. package/index.ts +1 -1
  27. package/openclaw.plugin.json +1 -1
  28. package/package.json +5 -4
  29. package/src/app/remote-agent-tool.ts +131 -16
  30. package/src/app/types.ts +2 -2
  31. package/src/plugin-ui/adapters/oc-2026-04.js +103 -0
  32. package/src/plugin-ui/adapters/oc-2026-05.js +125 -0
  33. package/src/plugin-ui/adapters/oc-2026-06.js +125 -0
  34. package/src/plugin-ui/adapters/oc-unknown.js +48 -0
  35. package/src/plugin-ui/assets/bg.png +0 -0
  36. package/src/plugin-ui/assets/icon.png +0 -0
  37. package/src/plugin-ui/assets/openagent-override.js +2480 -1004
  38. package/src/plugin-ui/build.cjs +309 -23
  39. package/src/plugin-ui/index.ts +2 -2
  40. package/src/plugin-ui/modules/agent-book/panel/agent-book.js +187 -14
  41. package/src/plugin-ui/modules/agent-book/panel/agent-card.js +26 -10
  42. package/src/plugin-ui/modules/agent-book/panel/agent-data.js +1 -1
  43. package/src/plugin-ui/modules/agent-book/panel/inject-ui.js +149 -1
  44. package/src/plugin-ui/modules/agent-book/panel/styles.js +352 -210
  45. package/src/plugin-ui/modules/agent-book/remote-agent-tool/components-core.js +4 -2
  46. package/src/plugin-ui/modules/agent-book/remote-agent-tool/thought-chain-card.js +4 -1
  47. package/src/plugin-ui/modules/agent-book/scanner.js +17 -5
  48. package/src/plugin-ui/modules/agent-book/travelcard/travel-styles.js +5 -0
  49. package/src/plugin-ui/modules/loader/bootstrap.js +1 -1
  50. package/src/plugin-ui/modules/loader/shared-state.js +278 -0
  51. package/src/plugin-ui/modules/remote-agent/execution-card.js +385 -124
  52. package/src/plugin-ui/modules/remote-agent/native-style-adapter.js +5 -23
  53. package/src/plugin-ui/modules/remote-agent/output-card.js +97 -31
  54. package/src/plugin-ui/modules/remote-agent/render-hooks.js +149 -58
  55. package/src/plugin-ui/modules/remote-agent/styles.js +690 -523
  56. package/src/plugin-ui/modules/remote-agent/tool-card-model.js +77 -3
  57. package/src/plugin-ui/postinstall-deploy.cjs +52 -0
  58. package/src/plugin-ui/ui-extension-loader/index.ts +6 -6
  59. package/src/plugin-ui/ui-extension-loader/registry-regex.ts +131 -14
  60. package/src/plugin-ui/ui-extension-loader/types.ts +5 -1
  61. package/src/state/store.ts +80 -0
  62. package/src/transport/oasn/oasn-invocation.ts +47 -12
  63. package/src/transport/oasn/oasn-types.ts +6 -2
  64. package/src/types/openclaw-plugin-sdk-media-store.d.ts +9 -0
@@ -11,6 +11,11 @@
11
11
  // UI 结构使用 shared thought-chain styles,数据来源是 RenderHook model。
12
12
 
13
13
  function _clRenderExecutionCard(model) {
14
+ // ── V2 版本判断:≥ 2026.6.9 启用新版 UI ──
15
+ if (typeof _clIsHostVersionGte === 'function' && _clIsHostVersionGte('2026.6.9')) {
16
+ return _clRenderExecutionCardV2(model);
17
+ }
18
+
14
19
  var container = document.createElement('div');
15
20
  container.className = 'cl-remote-agent-card cl-thought-chain';
16
21
  if (CL && typeof CL.diagMarkCard === 'function') {
@@ -20,111 +25,46 @@ function _clRenderExecutionCard(model) {
20
25
  container.appendChild(_clCreateOpenAgentHeader(model));
21
26
 
22
27
  var content = document.createElement('div');
23
- content.className = 'cl-thought-chain-content cl-thought-chain-content--execution';
28
+ content.className = 'cl-thought-chain-content cl-thought-chain-content--execution cl-content-collapsed';
24
29
  container.appendChild(content);
25
30
 
26
- // ── Agent Pill ──
27
- console.log('[cl-exec] 🏷️ agentName=' + JSON.stringify(model.agentName) + ' agentId=' + JSON.stringify(model.agentId));
28
- var pillSlot = document.createElement('div');
29
- pillSlot.className = 'cl-thought-chain-pill-slot';
30
- var pill = _clCreateAgentPill(model.agentName, model.agentId, model.agentAvatar);
31
- pillSlot.appendChild(pill);
32
- content.appendChild(pillSlot);
33
-
34
- // ── 分隔线 ──
35
- var divider = document.createElement('div');
36
- divider.className = 'cl-thought-chain-divider';
37
- content.appendChild(divider);
38
-
39
- // ── 思考步骤区 ──
40
- var stepsSection = document.createElement('div');
41
- stepsSection.className = 'cl-thought-chain-steps-section';
42
-
43
- // 标题栏
44
- var header = document.createElement('div');
45
- header.className = 'cl-tools-collapse-header';
46
-
47
- var headerIcon = document.createElement('span');
48
- headerIcon.className = 'cl-tools-collapse-header-icon';
49
- headerIcon.textContent = '▼';
50
-
51
- var headerTitle = document.createElement('span');
52
- headerTitle.className = 'cl-tools-collapse-header-title';
53
-
54
- // 从 chunks 提取步骤
55
- var steps = [];
56
- for (var i = 0; i < model.chunks.length; i++) {
57
- var chunk = model.chunks[i];
58
- if (chunk.type === 'step') {
59
- steps.push({ title: chunk.title, detail: chunk.detail || '' });
60
- }
61
- }
62
-
63
- // 合并预缓冲步骤(WS 先于 Lit 渲染到达时)
64
- if (model._bufferedSteps && model._bufferedSteps.length > 0) {
65
- steps = model._bufferedSteps;
66
- }
67
- if (typeof _cl_compactThoughtSteps === 'function') {
68
- steps = _cl_compactThoughtSteps(steps);
69
- }
70
-
71
- headerTitle.textContent = '思考中...';
72
-
73
- header.appendChild(headerIcon);
74
- header.appendChild(headerTitle);
75
-
76
- // 步骤列表(可折叠)
77
- var body = document.createElement('div');
78
- body.className = 'cl-tools-collapse-body cl-expanded';
79
-
80
- for (var si = 0; si < steps.length; si++) {
81
- var isLatest = (si === steps.length - 1);
82
- var stepEl = _clCreateStepElement(steps[si], isLatest);
83
- body.appendChild(stepEl);
31
+ // ── Agent 详情卡片(Figma 346:181) ──
32
+ try {
33
+ var detailCard = _clCreateAgentDetailCard(model);
34
+ content.appendChild(detailCard);
35
+ } catch(e) {
36
+ console.warn('[cl-exec] detail card creation failed:', e);
84
37
  }
85
38
 
86
- // 折叠/展开
87
- header.style.cursor = 'pointer';
88
- header.addEventListener('click', function(evt) {
89
- evt.stopPropagation(); // 防止外层容器拦截
90
- var isExpanded = body.classList.contains('cl-expanded');
91
- console.log('[cl-exec] 🖱️ header click: expanded=' + isExpanded + ' bodyChildren=' + body.childElementCount);
92
- if (isExpanded) {
93
- body.classList.remove('cl-expanded');
94
- body.classList.add('cl-collapsed');
95
- headerIcon.classList.add('cl-collapsed');
96
- if (typeof _cl_setCardUiState === 'function') {
97
- _cl_setCardUiState(model, { stepsExpanded: false });
98
- }
99
- } else {
100
- body.classList.remove('cl-collapsed');
101
- body.classList.add('cl-expanded');
102
- headerIcon.classList.remove('cl-collapsed');
103
- if (typeof _cl_setCardUiState === 'function') {
104
- _cl_setCardUiState(model, { stepsExpanded: true });
105
- }
106
- }
107
- });
108
-
109
- stepsSection.appendChild(header);
110
- stepsSection.appendChild(body);
111
- content.appendChild(stepsSection);
39
+ // ── 进度文字(Figma 346:253) — 动态读取 response.progress?.safe_status_message ──
40
+ var progressRow = document.createElement('div');
41
+ progressRow.className = 'cl-exec-progress-row';
42
+ var progressText = document.createElement('p');
43
+ progressText.className = 'cl-exec-progress-text';
44
+ progressText.textContent = (model.progressMessage || model.rawText || '').trim() || '思考中,正在了解你的需求';
45
+ progressRow.appendChild(progressText);
46
+ // 箭头图标
47
+ var arrowIcon = document.createElement('span');
48
+ arrowIcon.className = 'cl-exec-progress-arrow';
49
+ arrowIcon.innerHTML = '<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M5 4L9 7L5 10" stroke="#555" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
50
+ progressRow.appendChild(arrowIcon);
51
+ content.appendChild(progressRow);
52
+ if (model.status === 'completed') progressRow.style.display = 'none';
112
53
 
113
54
  // ── 异步更新真实 Agent 身份 ──
114
55
  if ((model.agentId || model.agentName) && typeof fetchAgentById === 'function') {
115
56
  fetchAgentById(model.agentId, model.agentName).then(function(agent) {
116
57
  if (!agent) return;
117
- var pa = container.querySelector('.cl-agent-pill-avatar');
118
- var pn = container.querySelector('.cl-agent-pill-name');
119
- if (pa && typeof avatarUrl === 'function') {
120
- var resolvedAvatar = avatarUrl(agent);
121
- console.log('[cl-diag][pill] fetch-update agentId=' + JSON.stringify(model.agentId)
122
- + ' name=' + JSON.stringify(agent.name || model.agentName)
123
- + ' src=' + JSON.stringify(resolvedAvatar));
124
- pa.src = resolvedAvatar;
125
- pa.style.display = '';
126
- }
127
- _clSetAgentPillName(container, agent.name || model.agentName);
58
+ var avatarEl = container.querySelector('.cl-exec-agent-avatar');
59
+ var nameEl = container.querySelector('.cl-exec-agent-name');
60
+ var bioEl = container.querySelector('.cl-exec-agent-bio');
61
+ var agentBio = _clGetAgentDescriptionText(agent);
62
+ // avatar 保持 icon.png,不覆盖
63
+ if (nameEl) nameEl.textContent = agent.name || model.agentName;
64
+ if (bioEl && agentBio) bioEl.textContent = agentBio;
65
+ var starsEl = container.querySelector('.cl-exec-star-count');
66
+ if (starsEl && agent.claws) starsEl.textContent = _cl_formatStarCount(agent.claws);
67
+ if (starsEl && agent.stars && !agent.claws) starsEl.textContent = _cl_formatStarCount(agent.stars);
128
68
  _clSetOpenAgentHeaderAgent(container, agent.name || model.agentName);
129
69
  }).catch(function() {});
130
70
  }
@@ -133,40 +73,137 @@ function _clRenderExecutionCard(model) {
133
73
  _cl_applyCardUiState(container, model);
134
74
  }
135
75
 
136
- console.log('[cl-exec] execution card built: steps=' + steps.length);
76
+ console.log('[cl-exec] execution card built');
137
77
  return container;
138
78
  }
139
79
 
140
- // ── 共用 DOM 构建函数 ──
80
+ function _clGetAgentDescriptionText(model) {
81
+ if (typeof _clPickAgentDescription === 'function') {
82
+ var direct = _clPickAgentDescription(model || {});
83
+ if (direct) return direct;
84
+ if (model && typeof CL !== 'undefined' && CL && typeof CL.getAgentIdentity === 'function') {
85
+ var identity = CL.getAgentIdentity(
86
+ model.agentId || model.agent_id || model.id || model.tag,
87
+ model.agentName || model.agent_name || model.name
88
+ );
89
+ var identityBio = _clPickAgentDescription(identity || {});
90
+ if (identityBio) return identityBio;
91
+ }
92
+ return '';
93
+ }
94
+ if (!model) return '';
95
+ return model.agentBio || model.bio || model.description || model.desc || model.agentDescription || model.agent_description || model.MOM || '';
96
+ }
141
97
 
142
- function _clCreateOpenAgentHeader(model) {
143
- var header = document.createElement('div');
144
- header.className = 'cl-openagent-header';
145
- header.style.cursor = 'pointer';
98
+ function _clSyncOutputFooterVisibility(card, isCollapsed) {
99
+ if (!card || !card.querySelector || !card.querySelector('.cl-openagent-header--output')) return;
100
+ var footers = card.querySelectorAll('.cl-output-footer');
101
+ for (var i = 0; i < footers.length; i++) {
102
+ footers[i].style.display = isCollapsed ? 'none' : '';
103
+ }
104
+ }
146
105
 
147
- var caret = document.createElement('span');
148
- caret.className = 'cl-openagent-header-caret';
149
- caret.textContent = '';
150
- header.appendChild(caret);
106
+ function _clGetAgentStatusText(status) {
107
+ if (status === 'completed') return '执行已完成';
108
+ if (status === 'failed' || status === 'error') return '执行失败';
109
+ return '正在执行任务';
110
+ }
151
111
 
152
- var icon = document.createElement('span');
153
- icon.className = 'cl-openagent-header-icon';
154
- icon.setAttribute('aria-hidden', 'true');
155
- header.appendChild(icon);
112
+ function _clIsAgentTerminalStatus(status) {
113
+ return status === 'completed' || status === 'failed' || status === 'error';
114
+ }
156
115
 
157
- var title = document.createElement('div');
158
- title.className = 'cl-openagent-header-title';
116
+ // ── Agent 详情卡片(Figma 266:11136) ──
117
+ function _clCreateAgentDetailCard(model) {
118
+ var card = document.createElement('div');
119
+ card.className = 'cl-exec-detail-card';
159
120
 
160
- var primary = document.createElement('span');
161
- primary.className = 'cl-openagent-header-primary';
162
- primary.textContent = 'OpenAgent @' + (model.agentName || 'Remote Agent');
163
- title.appendChild(primary);
121
+ var row = document.createElement('div');
122
+ row.className = 'cl-exec-detail-row';
164
123
 
165
- var secondary = document.createElement('span');
166
- secondary.className = 'cl-openagent-header-secondary';
167
- title.appendChild(secondary);
124
+ // 头像 68×68
125
+ var avatar = document.createElement('img');
126
+ avatar.className = 'cl-exec-agent-avatar';
127
+ avatar.alt = model.agentName || '';
128
+ avatar.src = './icon.png';
129
+ avatar.onerror = function() { this.style.visibility = 'hidden'; };
130
+ row.appendChild(avatar);
131
+
132
+ // 信息列
133
+ var info = document.createElement('div');
134
+ info.className = 'cl-exec-detail-info';
135
+
136
+ // 名称行:名称 + 星级徽章
137
+ var nameRow = document.createElement('div');
138
+ nameRow.className = 'cl-exec-name-row';
139
+
140
+ var nameEl = document.createElement('p');
141
+ nameEl.className = 'cl-exec-agent-name';
142
+ nameEl.textContent = model.agentName || 'Remote Agent';
143
+ nameRow.appendChild(nameEl);
144
+
145
+ // 星级徽章
146
+ var starBadge = document.createElement('div');
147
+ starBadge.className = 'cl-exec-star-badge';
148
+ var starSvgOutline = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M6.46401 1.8327C6.66621 1.36177 7.33396 1.36174 7.53612 1.8327L8.82412 4.83481L12.0718 5.1373C12.5808 5.18469 12.7873 5.8177 12.4039 6.15586L9.95148 8.31772L10.6687 11.5101C10.7809 12.0098 10.2404 12.4012 9.80052 12.139L7.00006 10.4699L4.19904 12.139C3.75913 12.4012 3.21924 12.0098 3.33145 11.5101L4.04808 8.31772L1.59626 6.15586C1.21282 5.81777 1.4189 5.18488 1.9278 5.1373L5.17601 4.83481L6.46401 1.8327ZM5.89435 5.8226L3.10073 6.08237L5.20905 7.94118L4.59325 10.6818L7.00006 9.24798L9.40575 10.6818L8.79108 7.94118L10.8983 6.08237L8.10521 5.8226L6.9995 3.24603L5.89435 5.8226Z" fill="#555555"/></svg>';
149
+ starBadge.innerHTML = starSvgOutline +
150
+ '<span class="cl-exec-star-count">' + (model.agentStars || '3.2万') + '</span>';
151
+ nameRow.appendChild(starBadge);
152
+ info.appendChild(nameRow);
153
+
154
+ var bioEl = document.createElement('p');
155
+ bioEl.className = 'cl-exec-agent-bio';
156
+ bioEl.textContent = _clGetAgentDescriptionText(model);
157
+ info.appendChild(bioEl);
158
+
159
+ row.appendChild(info);
160
+ card.appendChild(row);
161
+
162
+ return card;
163
+ }
168
164
 
169
- header.appendChild(title);
165
+ // ── 共用 DOM 构建函数 ──
166
+
167
+ function _clCreateOpenAgentHeader(model) {
168
+ var header = document.createElement('div');
169
+ header.className = 'cl-openagent-header';
170
+ if (model._outputMode) header.classList.add('cl-openagent-header--output');
171
+ header.style.cursor = 'pointer';
172
+
173
+ // 展开/收起图标
174
+ var expandIcon = document.createElement('span');
175
+ expandIcon.className = 'cl-openagent-expand-icon';
176
+ // 收起态三角(向右)
177
+ expandIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none"><path d="M9.75 6.79978C10.0833 6.99223 10.0833 7.47336 9.75 7.66581L6.75 9.39786C6.41667 9.59031 6 9.34975 6 8.96485L6 5.50075C6 5.11585 6.41667 4.87528 6.75 5.06773L9.75 6.79978Z" fill="#666666"/></svg>';
178
+ // 展开态三角(向下)
179
+ var expandedSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none"><path d="M8.43313 8.98291C8.24068 9.31624 7.75955 9.31624 7.5671 8.98291L5.83505 5.98291C5.6426 5.64958 5.88316 5.23291 6.26806 5.23291L9.73216 5.23291C10.1171 5.23291 10.3576 5.64958 10.1652 5.98291L8.43313 8.98291Z" fill="#666666"/></svg>';
180
+ header.appendChild(expandIcon);
181
+
182
+ // OASN 小图标
183
+ var oasnBadge = document.createElement('span');
184
+ oasnBadge.className = 'cl-openagent-badge';
185
+ header.appendChild(oasnBadge);
186
+
187
+ // 文字行
188
+ var textRow = document.createElement('span');
189
+ textRow.className = 'cl-openagent-text-row';
190
+
191
+ var labelOpenAgent = document.createElement('span');
192
+ labelOpenAgent.className = 'cl-openagent-label';
193
+ labelOpenAgent.textContent = 'OpenAgent';
194
+ textRow.appendChild(labelOpenAgent);
195
+
196
+ var labelAgent = document.createElement('span');
197
+ labelAgent.className = 'cl-openagent-agent';
198
+ labelAgent.textContent = '@' + (model.agentName || 'Remote Agent');
199
+ textRow.appendChild(labelAgent);
200
+
201
+ var labelStatus = document.createElement('span');
202
+ labelStatus.className = 'cl-openagent-status';
203
+ labelStatus.textContent = _clGetAgentStatusText(model.status);
204
+ textRow.appendChild(labelStatus);
205
+
206
+ header.appendChild(textRow);
170
207
 
171
208
  // 点击 header 折叠/展开卡片内容
172
209
  header.addEventListener('click', function(e) {
@@ -176,7 +213,11 @@ function _clCreateOpenAgentHeader(model) {
176
213
  var content = card.querySelector('.cl-thought-chain-content');
177
214
  if (!content) return;
178
215
  var isCollapsed = content.classList.toggle('cl-content-collapsed');
179
- caret.textContent = isCollapsed ? '▶' : '▼';
216
+ _clSyncOutputFooterVisibility(card, isCollapsed);
217
+ // 切换图标
218
+ expandIcon.innerHTML = isCollapsed
219
+ ? '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none"><path d="M9.75 6.79978C10.0833 6.99223 10.0833 7.47336 9.75 7.66581L6.75 9.39786C6.41667 9.59031 6 9.34975 6 8.96485L6 5.50075C6 5.11585 6.41667 4.87528 6.75 5.06773L9.75 6.79978Z" fill="#666666"/></svg>'
220
+ : '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none"><path d="M8.43313 8.98291C8.24068 9.31624 7.75955 9.31624 7.5671 8.98291L5.83505 5.98291C5.6426 5.64958 5.88316 5.23291 6.26806 5.23291L9.73216 5.23291C10.1171 5.23291 10.3576 5.64958 10.1652 5.98291L8.43313 8.98291Z" fill="#666666"/></svg>';
180
221
  if (typeof _cl_setCardUiState === 'function') {
181
222
  _cl_setCardUiState(model, { contentCollapsed: isCollapsed });
182
223
  }
@@ -186,8 +227,8 @@ function _clCreateOpenAgentHeader(model) {
186
227
  }
187
228
 
188
229
  function _clSetOpenAgentHeaderAgent(container, agentName) {
189
- var title = container && container.querySelector('.cl-openagent-header-primary');
190
- if (title) title.textContent = 'OpenAgent @' + (agentName || 'Remote Agent');
230
+ var label = container && container.querySelector('.cl-openagent-agent');
231
+ if (label) label.textContent = '@' + (agentName || 'Remote Agent');
191
232
  }
192
233
 
193
234
  function _clCreateAgentPill(agentName, agentId, agentAvatar) {
@@ -209,7 +250,7 @@ function _clCreateAgentPill(agentName, agentId, agentAvatar) {
209
250
  console.log('[cl-diag][pill] create agentName=' + JSON.stringify(agentName || '')
210
251
  + ' agentId=' + JSON.stringify(agentId || '')
211
252
  + ' src=' + JSON.stringify(avatar.getAttribute('src')));
212
- avatar.onerror = function() { this.style.display = 'none'; };
253
+ avatar.onerror = function() { this.style.visibility = 'hidden'; };
213
254
  pill.appendChild(avatar);
214
255
 
215
256
  var nameEl = document.createElement('span');
@@ -267,3 +308,223 @@ function _clCreateStepElement(step, isLatest) {
267
308
 
268
309
  return item;
269
310
  }
311
+
312
+
313
+ // ── 动态更新 header 状态文字 ──
314
+ function _clUpdateAgentStatusText(cardNode, status) {
315
+ var label = cardNode && cardNode.querySelector('.cl-openagent-status');
316
+ if (label) label.textContent = _clGetAgentStatusText(status);
317
+ var progressRow = cardNode && cardNode.querySelector('.cl-exec-progress-row');
318
+ if (progressRow) progressRow.style.display = _clIsAgentTerminalStatus(status) ? 'none' : '';
319
+ }
320
+
321
+ function _cl_formatStarCount(count) {
322
+ var n = Number(count);
323
+ if (!isFinite(n)) return '3.2万';
324
+ if (n >= 10000) return (n / 10000).toFixed(1).replace(/.0$/, '') + '万';
325
+ if (n >= 1000) return (n / 1000).toFixed(1).replace(/.0$/, '') + 'k';
326
+ return String(Math.floor(n));
327
+ }
328
+
329
+ // ═══════════════════════════════════════════════════════════════
330
+ // V2 执行卡片渲染(2026.6.9+ 新版 UI)
331
+ // ═══════════════════════════════════════════════════════════════
332
+
333
+ function _clRenderExecutionCardV2(model) {
334
+ var container = document.createElement('div');
335
+ container.className = 'cl-remote-agent-card cl-thought-chain cl-exec-v2';
336
+ if (CL && typeof CL.diagMarkCard === 'function') {
337
+ CL.diagMarkCard(container, 'execution', { tcid: model.toolCallId || '' });
338
+ }
339
+
340
+ container.appendChild(_clCreateOpenAgentHeaderV2(model));
341
+
342
+ var content = document.createElement('div');
343
+ content.className = 'cl-thought-chain-content cl-thought-chain-content--execution cl-content-collapsed';
344
+ container.appendChild(content);
345
+
346
+ // ── Agent 详情卡片 V2 ──
347
+ try {
348
+ var detailCard = _clCreateAgentDetailCardV2(model);
349
+ content.appendChild(detailCard);
350
+ } catch(e) {
351
+ console.warn('[cl-exec-v2] detail card creation failed:', e);
352
+ }
353
+
354
+ // ── 进度文字 V2 ──
355
+ var progressRow = document.createElement('div');
356
+ progressRow.className = 'cl-exec-progress-row cl-exec-progress-row-v2';
357
+ var progressText = document.createElement('p');
358
+ progressText.className = 'cl-exec-progress-text';
359
+ progressText.textContent = (model.progressMessage || model.rawText || '').trim() || '思考中,正在了解你的需求';
360
+ progressRow.appendChild(progressText);
361
+ var arrowIcon = document.createElement('span');
362
+ arrowIcon.className = 'cl-exec-progress-arrow';
363
+ arrowIcon.innerHTML = '<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M5 4L9 7L5 10" stroke="#555" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
364
+ progressRow.appendChild(arrowIcon);
365
+ content.appendChild(progressRow);
366
+ if (model.status === 'completed') progressRow.style.display = 'none';
367
+
368
+ // ── 步骤列表容器(供 _cl_updateCardSteps 使用)──
369
+ var stepsHeader = document.createElement('div');
370
+ stepsHeader.className = 'cl-tools-collapse-header cl-tools-collapse-header-v2';
371
+ var stepsHeaderIcon = document.createElement('span');
372
+ stepsHeaderIcon.className = 'cl-tools-collapse-header-icon';
373
+ stepsHeaderIcon.textContent = '▼';
374
+ stepsHeader.appendChild(stepsHeaderIcon);
375
+ var stepsHeaderTitle = document.createElement('span');
376
+ stepsHeaderTitle.className = 'cl-tools-collapse-header-title cl-tools-collapse-header-title-v2';
377
+ stepsHeaderTitle.textContent = '思考中...';
378
+ stepsHeader.appendChild(stepsHeaderTitle);
379
+ content.appendChild(stepsHeader);
380
+
381
+ var stepsBody = document.createElement('div');
382
+ stepsBody.className = 'cl-tools-collapse-body cl-tools-collapse-body-v2 cl-expanded';
383
+ content.appendChild(stepsBody);
384
+
385
+ // ─ Footer(Figma: -由xxx完成 + 星级)──
386
+ var footer = document.createElement('div');
387
+ footer.className = 'cl-output-footer cl-output-footer-v2';
388
+ footer.innerHTML = '<span class="cl-output-footer-text">-由' + (model.agentName || 'Remote Agent') + '完成</span>'
389
+ + '<span class="cl-output-footer-star"><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M7 1.16L8.356 5.33H12.78L9.195 7.94L10.565 12.1L7 9.51L3.435 12.1L4.805 7.94L1.22 5.33H5.644L7 1.16Z" stroke="#999" stroke-width="0.8"/></svg></span>'
390
+ + '<span class="cl-output-footer-count">' + (model.agentStars || '3.2万') + '</span>';
391
+ container.appendChild(footer);
392
+
393
+ // ── 异步更新真实 Agent 身份 ──
394
+ if ((model.agentId || model.agentName) && typeof fetchAgentById === 'function') {
395
+ fetchAgentById(model.agentId, model.agentName).then(function(agent) {
396
+ if (!agent) return;
397
+ var avatarEl = container.querySelector('.cl-exec-agent-avatar-v2');
398
+ var nameEl = container.querySelector('.cl-exec-agent-name-v2');
399
+ var bioEl = container.querySelector('.cl-exec-agent-bio-v2');
400
+ var agentBio = _clGetAgentDescriptionText(agent);
401
+ if (nameEl) nameEl.textContent = agent.name || model.agentName;
402
+ if (bioEl && agentBio) bioEl.textContent = agentBio;
403
+ var starsEl = container.querySelector('.cl-exec-star-count-v2');
404
+ if (starsEl && agent.claws) starsEl.textContent = _cl_formatStarCount(agent.claws);
405
+ if (starsEl && agent.stars && !agent.claws) starsEl.textContent = _cl_formatStarCount(agent.stars);
406
+ }).catch(function() {});
407
+ }
408
+
409
+ if (typeof _cl_applyCardUiState === 'function') {
410
+ _cl_applyCardUiState(container, model);
411
+ }
412
+
413
+ console.log('[cl-exec-v2] execution card built');
414
+ return container;
415
+ }
416
+
417
+ // ── V2 Header(粉色背景 + 圆形头像 + 无 @agentName)──
418
+ function _clCreateOpenAgentHeaderV2(model) {
419
+ var header = document.createElement('div');
420
+ header.className = 'cl-openagent-header cl-openagent-header-v2';
421
+ if (model._outputMode) header.classList.add('cl-openagent-header--output');
422
+ header.style.cursor = 'pointer';
423
+
424
+ // 展开/收起图标
425
+ var expandIcon = document.createElement('span');
426
+ expandIcon.className = 'cl-openagent-expand-icon';
427
+ expandIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none"><path d="M9.75 6.79978C10.0833 6.99223 10.0833 7.47336 9.75 7.66581L6.75 9.39786C6.41667 9.59031 6 9.34975 6 8.96485L6 5.50075C6 5.11585 6.41667 4.87528 6.75 5.06773L9.75 6.79978Z" fill="#666666"/></svg>';
428
+ var expandedSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none"><path d="M8.43313 8.98291C8.24068 9.31624 7.75955 9.31624 7.5671 8.98291L5.83505 5.98291C5.6426 5.64958 5.88316 5.23291 6.26806 5.23291L9.73216 5.23291C10.1171 5.23291 10.3576 5.64958 10.1652 5.98291L8.43313 8.98291Z" fill="#666666"/></svg>';
429
+ header.appendChild(expandIcon);
430
+
431
+ // 圆形灰色头像(替代小徽章)
432
+ var avatar = document.createElement('span');
433
+ avatar.className = 'cl-openagent-avatar-v2';
434
+ header.appendChild(avatar);
435
+
436
+ // 文字行:OpenAgent + 状态文字(去掉 @agentName)
437
+ var textRow = document.createElement('span');
438
+ textRow.className = 'cl-openagent-text-row';
439
+
440
+ var labelOpenAgent = document.createElement('span');
441
+ labelOpenAgent.className = 'cl-openagent-label';
442
+ labelOpenAgent.textContent = 'OpenAgent';
443
+ textRow.appendChild(labelOpenAgent);
444
+
445
+ var labelStatus = document.createElement('span');
446
+ labelStatus.className = 'cl-openagent-status';
447
+ labelStatus.textContent = _clGetAgentStatusText(model.status);
448
+ textRow.appendChild(labelStatus);
449
+
450
+ header.appendChild(textRow);
451
+
452
+ // 点击 header 折叠/展开卡片内容
453
+ header.addEventListener('click', function(e) {
454
+ e.stopPropagation();
455
+ var card = header.closest('.cl-remote-agent-card');
456
+ if (!card) return;
457
+ var content = card.querySelector('.cl-thought-chain-content');
458
+ if (!content) return;
459
+ var isCollapsed = content.classList.toggle('cl-content-collapsed');
460
+ _clSyncOutputFooterVisibility(card, isCollapsed);
461
+ expandIcon.innerHTML = isCollapsed
462
+ ? '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none"><path d="M9.75 6.79978C10.0833 6.99223 10.0833 7.47336 9.75 7.66581L6.75 9.39786C6.41667 9.59031 6 9.34975 6 8.96485L6 5.50075C6 5.11585 6.41667 4.87528 6.75 5.06773L9.75 6.79978Z" fill="#666666"/></svg>'
463
+ : expandedSvg;
464
+ if (typeof _cl_setCardUiState === 'function') {
465
+ _cl_setCardUiState(model, { contentCollapsed: isCollapsed });
466
+ }
467
+ });
468
+
469
+ return header;
470
+ }
471
+
472
+ // ─ V2 Agent 详情卡片(大头像 + 右置星级 + 网格点背景)──
473
+ function _clCreateAgentDetailCardV2(model) {
474
+ var card = document.createElement('div');
475
+ card.className = 'cl-exec-detail-card cl-exec-detail-card-v2';
476
+
477
+ var row = document.createElement('div');
478
+ row.className = 'cl-exec-detail-row cl-exec-detail-row-v2';
479
+
480
+ // 大头像 80×80
481
+ var avatar = document.createElement('img');
482
+ avatar.className = 'cl-exec-agent-avatar cl-exec-agent-avatar-v2';
483
+ avatar.alt = model.agentName || '';
484
+ avatar.src = './icon.png';
485
+ avatar.onerror = function() { this.style.visibility = 'hidden'; };
486
+ row.appendChild(avatar);
487
+
488
+ // 信息列
489
+ var info = document.createElement('div');
490
+ info.className = 'cl-exec-detail-info cl-exec-detail-info-v2';
491
+
492
+ // 名称(无星级徽章,星级右置到卡片右上角)
493
+ var nameEl = document.createElement('p');
494
+ nameEl.className = 'cl-exec-agent-name cl-exec-agent-name-v2';
495
+ nameEl.textContent = model.agentName || 'Remote Agent';
496
+ info.appendChild(nameEl);
497
+
498
+ // 描述文字
499
+ var bioEl = document.createElement('p');
500
+ bioEl.className = 'cl-exec-agent-bio cl-exec-agent-bio-v2';
501
+ bioEl.textContent = _clGetAgentDescriptionText(model);
502
+ info.appendChild(bioEl);
503
+
504
+ row.appendChild(info);
505
+ card.appendChild(row);
506
+
507
+ // 星级徽章右置到卡片右上角
508
+ var starBadge = document.createElement('div');
509
+ starBadge.className = 'cl-exec-star-badge cl-exec-star-badge-v2';
510
+ var starSvgOutline = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M6.46401 1.8327C6.66621 1.36177 7.33396 1.36174 7.53612 1.8327L8.82412 4.83481L12.0718 5.1373C12.5808 5.18469 12.7873 5.8177 12.4039 6.15586L9.95148 8.31772L10.6687 11.5101C10.7809 12.0098 10.2404 12.4012 9.80052 12.139L7.00006 10.4699L4.19904 12.139C3.75913 12.4012 3.21924 12.0098 3.33145 11.5101L4.04808 8.31772L1.59626 6.15586C1.21282 5.81777 1.4189 5.18488 1.9278 5.1373L5.17601 4.83481L6.46401 1.8327ZM5.89435 5.8226L3.10073 6.08237L5.20905 7.94118L4.59325 10.6818L7.00006 9.24798L9.40575 10.6818L8.79108 7.94118L10.8983 6.08237L8.10521 5.8226L6.9995 3.24603L5.89435 5.8226Z" fill="#555555"/></svg>';
511
+ starBadge.innerHTML = starSvgOutline +
512
+ '<span class="cl-exec-star-count cl-exec-star-count-v2">' + (model.agentStars || '3.2万') + '</span>';
513
+ card.appendChild(starBadge);
514
+
515
+ return card;
516
+ }
517
+
518
+ // ── V2 状态文字更新 ──
519
+ function _clUpdateAgentStatusTextV2(cardNode, status) {
520
+ var label = cardNode && cardNode.querySelector('.cl-openagent-status');
521
+ if (label) label.textContent = _clGetAgentStatusText(status);
522
+ // 进度文字行:完成后隐藏
523
+ var progressRow = cardNode && cardNode.querySelector('.cl-exec-progress-row-v2');
524
+ if (progressRow) progressRow.style.display = _clIsAgentTerminalStatus(status) ? 'none' : '';
525
+ // 步骤列表:完成后隐藏
526
+ var stepsBody = cardNode && cardNode.querySelector('.cl-tools-collapse-body-v2');
527
+ if (stepsBody) stepsBody.style.display = _clIsAgentTerminalStatus(status) ? 'none' : '';
528
+ var stepsHeader = cardNode && cardNode.querySelector('.cl-tools-collapse-header-v2');
529
+ if (stepsHeader) stepsHeader.style.display = _clIsAgentTerminalStatus(status) ? 'none' : '';
530
+ }
@@ -8,30 +8,12 @@
8
8
 
9
9
  (function _clInitNativeStyleAdapter() {
10
10
  var _clNativeStyleSampled = false;
11
+ var hostAdapter = CL.hostAdapter || {};
12
+ var nativeStyle = hostAdapter.nativeStyle || {};
11
13
 
12
- var SHELL_SELECTORS = [
13
- '.chat-tool-card:not(:has(.cl-remote-agent-card))',
14
- '.chat-tool-msg-collapse:not(:has(.cl-remote-agent-card))',
15
- '.chat-tools-collapse:not(:has(.cl-remote-agent-card))',
16
- // v5.x+ variants
17
- '.tool-card:not(:has(.cl-remote-agent-card))',
18
- '.chat-tool-card__wrapper:not(:has(.cl-remote-agent-card))'
19
- ];
20
-
21
- var SUMMARY_SELECTORS = [
22
- '.chat-tool-card__header',
23
- '.chat-tool-card__title',
24
- '.chat-tool-msg-summary:not(.cl-remote-agent-host-shell *)',
25
- '.chat-tools-summary:not(.cl-remote-agent-host-shell *)',
26
- // v5.x+ variants
27
- '.tool-card__header',
28
- '.tool-card__title'
29
- ];
30
-
31
- var INDENT_SELECTORS = [
32
- '.chat-group.tool:not(:has(.cl-remote-agent-card))',
33
- '.chat-bubble:not(:has(.cl-remote-agent-card))'
34
- ];
14
+ var SHELL_SELECTORS = nativeStyle.shellSelectors || [];
15
+ var SUMMARY_SELECTORS = nativeStyle.summarySelectors || [];
16
+ var INDENT_SELECTORS = nativeStyle.indentSelectors || [];
35
17
 
36
18
  // Fallback 默认值(和当前 styles.js 折叠态写死值保持一致,避免跳变)
37
19
  var FALLBACKS = {