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.
Files changed (132) hide show
  1. package/dist/index.js +2 -0
  2. package/dist/src/config/config-schema.d.ts +9 -0
  3. package/dist/src/config/config-schema.js +6 -0
  4. package/dist/src/messaging/executor.d.ts +2 -3
  5. package/dist/src/messaging/executor.js +4 -31
  6. package/dist/src/plugin-ui/assets/openagent-override.js +124 -18
  7. package/dist/src/proxy/auth-proxy.js +5 -0
  8. package/dist/src/runtime/update-checker.d.ts +18 -0
  9. package/dist/src/runtime/update-checker.js +216 -0
  10. package/index.ts +3 -0
  11. package/package.json +1 -3
  12. package/src/app/channel-tools.ts +0 -249
  13. package/src/app/discovery-tools.ts +0 -273
  14. package/src/app/download-file-tool.ts +0 -133
  15. package/src/app/hooks.ts +0 -144
  16. package/src/app/index.ts +0 -84
  17. package/src/app/messaging-tools.ts +0 -79
  18. package/src/app/ops-tools.ts +0 -155
  19. package/src/app/remote-agent-tool.ts +0 -762
  20. package/src/app/types.ts +0 -68
  21. package/src/app/upload-file-tool.ts +0 -411
  22. package/src/app/verbose-preflight.ts +0 -190
  23. package/src/auth/config.ts +0 -266
  24. package/src/auth/credential-manager.ts +0 -146
  25. package/src/auth/index.ts +0 -24
  26. package/src/auth/verify.ts +0 -99
  27. package/src/channel.ts +0 -566
  28. package/src/compat.ts +0 -94
  29. package/src/config/config-schema.ts +0 -39
  30. package/src/messaging/aggregator.ts +0 -120
  31. package/src/messaging/collector.ts +0 -89
  32. package/src/messaging/executor.ts +0 -72
  33. package/src/messaging/inbound.ts +0 -150
  34. package/src/messaging/index.ts +0 -11
  35. package/src/messaging/mention-protocol.ts +0 -94
  36. package/src/messaging/process-c2c-request.ts +0 -564
  37. package/src/messaging/process-message.ts +0 -373
  38. package/src/messaging/scheduler.ts +0 -55
  39. package/src/messaging/types.ts +0 -38
  40. package/src/plugin-ui/adapters/oc-2026-04.js +0 -103
  41. package/src/plugin-ui/adapters/oc-2026-05.js +0 -125
  42. package/src/plugin-ui/adapters/oc-2026-06.js +0 -125
  43. package/src/plugin-ui/adapters/oc-unknown.js +0 -48
  44. package/src/plugin-ui/assets/agentbook-icon.svg +0 -5
  45. package/src/plugin-ui/assets/bg.png +0 -0
  46. package/src/plugin-ui/assets/icon.png +0 -0
  47. package/src/plugin-ui/assets/magic.svg +0 -5
  48. package/src/plugin-ui/assets/openagent-override.js +0 -11156
  49. package/src/plugin-ui/build.cjs +0 -463
  50. package/src/plugin-ui/index.ts +0 -18
  51. package/src/plugin-ui/modules/agent-book/panel/agent-book.js +0 -570
  52. package/src/plugin-ui/modules/agent-book/panel/agent-card.js +0 -170
  53. package/src/plugin-ui/modules/agent-book/panel/agent-data.js +0 -643
  54. package/src/plugin-ui/modules/agent-book/panel/inject-ui.js +0 -665
  55. package/src/plugin-ui/modules/agent-book/panel/mention-state.js +0 -206
  56. package/src/plugin-ui/modules/agent-book/panel/styles.js +0 -833
  57. package/src/plugin-ui/modules/agent-book/panel/theme-adapter.js +0 -86
  58. package/src/plugin-ui/modules/agent-book/remote-agent-tool/components-core.js +0 -295
  59. package/src/plugin-ui/modules/agent-book/remote-agent-tool/thought-chain-card.js +0 -211
  60. package/src/plugin-ui/modules/agent-book/scanner.js +0 -131
  61. package/src/plugin-ui/modules/agent-book/travelcard/travel-cards.js +0 -500
  62. package/src/plugin-ui/modules/agent-book/travelcard/travel-engine.js +0 -652
  63. package/src/plugin-ui/modules/agent-book/travelcard/travel-styles.js +0 -256
  64. package/src/plugin-ui/modules/loader/bootstrap.js +0 -38
  65. package/src/plugin-ui/modules/loader/shared-state.js +0 -838
  66. package/src/plugin-ui/modules/loader/ws-intercept.js +0 -199
  67. package/src/plugin-ui/modules/remote-agent/chunk-parser.js +0 -161
  68. package/src/plugin-ui/modules/remote-agent/execution-card.js +0 -530
  69. package/src/plugin-ui/modules/remote-agent/markdown-renderer.js +0 -256
  70. package/src/plugin-ui/modules/remote-agent/media-links.js +0 -151
  71. package/src/plugin-ui/modules/remote-agent/native-style-adapter.js +0 -134
  72. package/src/plugin-ui/modules/remote-agent/output-card.js +0 -342
  73. package/src/plugin-ui/modules/remote-agent/progress-store.js +0 -363
  74. package/src/plugin-ui/modules/remote-agent/render-hooks.js +0 -1700
  75. package/src/plugin-ui/modules/remote-agent/styles.js +0 -896
  76. package/src/plugin-ui/modules/remote-agent/tool-card-model.js +0 -130
  77. package/src/plugin-ui/postinstall-deploy.cjs +0 -52
  78. package/src/plugin-ui/ui-extension-loader/backup.ts +0 -92
  79. package/src/plugin-ui/ui-extension-loader/index.ts +0 -276
  80. package/src/plugin-ui/ui-extension-loader/locator.ts +0 -152
  81. package/src/plugin-ui/ui-extension-loader/manifest.ts +0 -57
  82. package/src/plugin-ui/ui-extension-loader/registry-regex.ts +0 -944
  83. package/src/plugin-ui/ui-extension-loader/removed-extensions.ts +0 -70
  84. package/src/plugin-ui/ui-extension-loader/types.ts +0 -72
  85. package/src/proxy/auth-proxy.ts +0 -409
  86. package/src/runtime/account.ts +0 -549
  87. package/src/runtime/index.ts +0 -7
  88. package/src/runtime/plugin-runtime.ts +0 -94
  89. package/src/runtime/registry.ts +0 -71
  90. package/src/sdk/CLASS_MAP.md +0 -143
  91. package/src/sdk/index.d.ts +0 -126
  92. package/src/sdk/index.js +0 -23990
  93. package/src/sdk/modules/cloud-search-module.js +0 -1117
  94. package/src/sdk/modules/follow-module.js +0 -1069
  95. package/src/sdk/modules/group-module.js +0 -7397
  96. package/src/sdk/modules/relationship-module.js +0 -2269
  97. package/src/sdk/modules/signaling-module.js +0 -1468
  98. package/src/sdk/modules/tim-upload-plugin.js +0 -730
  99. package/src/sdk/node-env/http-request.js +0 -90
  100. package/src/sdk/node-env/index.js +0 -57
  101. package/src/sdk/node-env/storage.js +0 -114
  102. package/src/sdk/package.json +0 -10
  103. package/src/sdk/tsconfig.json +0 -16
  104. package/src/state/pending-invocation-store.ts +0 -43
  105. package/src/state/store.ts +0 -756
  106. package/src/tim/c2c.ts +0 -451
  107. package/src/tim/channels.ts +0 -364
  108. package/src/tim/client.ts +0 -330
  109. package/src/tim/index.ts +0 -18
  110. package/src/tim/messages.ts +0 -166
  111. package/src/tim/sdk-logger-init.ts +0 -50
  112. package/src/tools.ts +0 -10
  113. package/src/transport/factory.ts +0 -95
  114. package/src/transport/oasn/index.ts +0 -17
  115. package/src/transport/oasn/oasn-agent-card.ts +0 -111
  116. package/src/transport/oasn/oasn-discovery.ts +0 -108
  117. package/src/transport/oasn/oasn-files.ts +0 -210
  118. package/src/transport/oasn/oasn-http.ts +0 -529
  119. package/src/transport/oasn/oasn-invocation.ts +0 -604
  120. package/src/transport/oasn/oasn-normalize.ts +0 -133
  121. package/src/transport/oasn/oasn-register.ts +0 -33
  122. package/src/transport/oasn/oasn-transport.ts +0 -318
  123. package/src/transport/oasn/oasn-types.ts +0 -404
  124. package/src/transport/tim/index.ts +0 -8
  125. package/src/transport/tim/tim-transport.ts +0 -515
  126. package/src/transport/types.ts +0 -538
  127. package/src/types/openclaw-plugin-sdk-media-store.d.ts +0 -9
  128. package/src/types/openclaw.d.ts +0 -97
  129. package/src/types/tencentcloud-chat.d.ts +0 -15
  130. package/src/util/http.ts +0 -113
  131. package/src/util/logger.ts +0 -131
  132. package/src/util/url-resolver.ts +0 -77
@@ -1,256 +0,0 @@
1
- // ── OpenAgent Markdown Renderer — 安全的 line-based markdown → HTML 转换 ──
2
- //
3
- // 不依赖宿主 marked.js,也不依赖 window.__openagentMarked。
4
- // 只支持 remote agent output 需要的 markdown 子集。
5
- // 所有输出经过白名单 sanitize,防止 XSS。
6
- //
7
- // 支持的语法:
8
- // # / ## / ### / #### → 标题
9
- // - item / * item → 无序列表
10
- // 1. item → 有序列表
11
- // **bold** → 粗体
12
- // *italic* → 斜体
13
- // `code` → 行内代码
14
- // ```lang ... ``` → fenced code block
15
- // [text](url) → 链接(仅 http/https/mailto)
16
- // --- → 水平分隔线
17
- // 段落 / 换行
18
- //
19
- // OpenAgent travel card tags(sh_card, tr_card 等)作为 literal custom tags 保留。
20
- // la_card 是住宿区域卡片占位,目前不再展示,渲染前静默剔除。
21
-
22
- // ── 安全工具 ──
23
-
24
- var _CL_SAFE_PROTOCOLS = ['http:', 'https:', 'mailto:'];
25
-
26
- // OpenAgent travel card tag 白名单
27
- var _CL_TRAVEL_TAGS = ['sh_card', 'tr_card', 'i_card', 'la_card', 'fr_card', 'bg_card', 'time_data_card'];
28
-
29
- function _clStripSuppressedTravelTags(text) {
30
- return String(text || '')
31
- .replace(/<la_card(?:\s[^>]*)?>[\s\S]*?<\/la_card>/gi, '')
32
- .replace(/&lt;la_card(?:\s[\s\S]*?)?&gt;[\s\S]*?&lt;\/la_card&gt;/gi, '')
33
- .replace(/<la_card(?:\s[^>]*)?\/?>/gi, '')
34
- .replace(/&lt;la_card(?:\s[\s\S]*?)?\/?&gt;/gi, '');
35
- }
36
-
37
- function _clEscapeHtml(str) {
38
- return str
39
- .replace(/&/g, '&amp;')
40
- .replace(/</g, '&lt;')
41
- .replace(/>/g, '&gt;')
42
- .replace(/"/g, '&quot;')
43
- .replace(/'/g, '&#39;');
44
- }
45
-
46
- function _clIsSafeUrl(url) {
47
- try {
48
- var parsed = new URL(url, 'https://placeholder.invalid');
49
- return _CL_SAFE_PROTOCOLS.indexOf(parsed.protocol) >= 0;
50
- } catch (e) {
51
- return false;
52
- }
53
- }
54
-
55
- // ── inline markdown 解析 ──
56
-
57
- function _clRenderInlineMarkdown(text) {
58
- // 先 escape HTML
59
- var escaped = _clEscapeHtml(text);
60
-
61
- // inline code: `code` — 最先处理,code 内部不做进一步解析
62
- escaped = escaped.replace(/`([^`]+)`/g, '<code>$1</code>');
63
-
64
- // bold: **text**
65
- escaped = escaped.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
66
-
67
- // italic: *text* (不匹配 ** 开头的)
68
- escaped = escaped.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, '<em>$1</em>');
69
-
70
- // links: [text](url) — 只允许安全协议
71
- escaped = escaped.replace(/\[([^\]]+)\]\(([^)]+)\)/g, function(match, linkText, url) {
72
- // url 已经被 escape 过,需要还原来检查协议
73
- var rawUrl = url.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/g, "'");
74
- if (_clIsSafeUrl(rawUrl)) {
75
- return '<a href="' + _clEscapeHtml(rawUrl) + '" target="_blank" rel="noopener noreferrer">' + linkText + '</a>';
76
- }
77
- return linkText;
78
- });
79
-
80
- return escaped;
81
- }
82
-
83
- // ── 主渲染函数 ──
84
-
85
- /**
86
- * 将 markdown 文本转换为安全的 HTML 字符串。
87
- *
88
- * OpenAgent travel card tags 作为 literal DOM 标签保留(无属性透传),
89
- * 供 travel-engine.js 后续处理。
90
- *
91
- * @param {string} text - 原始 markdown 文本
92
- * @returns {string} 安全的 HTML 字符串
93
- */
94
- function _clRenderOutputMarkdown(text) {
95
- if (!text || typeof text !== 'string') return '';
96
- text = _clStripSuppressedTravelTags(text);
97
-
98
- // ── 第 1 步:提取并保护 OpenAgent travel card tags ──
99
- // 将 <tag_name>...</tag_name> 替换为占位符,防止被 HTML escape
100
- var travelPlaceholders = [];
101
- var tagPattern = new RegExp(
102
- '<(' + _CL_TRAVEL_TAGS.join('|') + ')(?:\\s[^>]*)?>([\\s\\S]*?)<\\/\\1>',
103
- 'gi'
104
- );
105
- var protectedText = text.replace(tagPattern, function(match, tagName, innerContent) {
106
- var idx = travelPlaceholders.length;
107
- // 保留 tag name(小写),escape inner content,不透传任何 attribute
108
- var safeTag = '<' + tagName.toLowerCase() + '>' + _clEscapeHtml(innerContent) + '</' + tagName.toLowerCase() + '>';
109
- travelPlaceholders.push(safeTag);
110
- return '\x00CL_TRAVEL_' + idx + '\x00';
111
- });
112
-
113
- // 也处理 self-closing 或空 travel tags: <tag_name> 或 <tag_name/>
114
- var selfClosePattern = new RegExp(
115
- '<(' + _CL_TRAVEL_TAGS.join('|') + ')(?:\\s[^>]*)?\\/?>',
116
- 'gi'
117
- );
118
- protectedText = protectedText.replace(selfClosePattern, function(match, tagName) {
119
- var idx = travelPlaceholders.length;
120
- travelPlaceholders.push('<' + tagName.toLowerCase() + '></' + tagName.toLowerCase() + '>');
121
- return '\x00CL_TRAVEL_' + idx + '\x00';
122
- });
123
-
124
- // ── 第 2 步:逐行解析 markdown ──
125
- var lines = protectedText.split('\n');
126
- var html = [];
127
- var inCodeBlock = false;
128
- var codeBlockContent = [];
129
- var codeBlockLang = '';
130
- var inList = false;
131
- var listType = ''; // 'ul' or 'ol'
132
- var paragraphLines = [];
133
-
134
- function flushParagraph() {
135
- if (paragraphLines.length > 0) {
136
- var combined = paragraphLines.join('<br>');
137
- html.push('<p>' + combined + '</p>');
138
- paragraphLines = [];
139
- }
140
- }
141
-
142
- function flushList() {
143
- if (inList) {
144
- html.push('</' + listType + '>');
145
- inList = false;
146
- listType = '';
147
- }
148
- }
149
-
150
- for (var i = 0; i < lines.length; i++) {
151
- var line = lines[i];
152
-
153
- // fenced code block: ``` or ```lang
154
- if (/^```/.test(line)) {
155
- if (!inCodeBlock) {
156
- flushParagraph();
157
- flushList();
158
- inCodeBlock = true;
159
- codeBlockLang = line.replace(/^```\s*/, '').trim();
160
- codeBlockContent = [];
161
- continue;
162
- } else {
163
- // end of code block — content is already collected and will be escaped
164
- var codeHtml = _clEscapeHtml(codeBlockContent.join('\n'));
165
- if (codeBlockLang) {
166
- html.push('<pre><code class="language-' + _clEscapeHtml(codeBlockLang) + '">' + codeHtml + '</code></pre>');
167
- } else {
168
- html.push('<pre><code>' + codeHtml + '</code></pre>');
169
- }
170
- inCodeBlock = false;
171
- codeBlockContent = [];
172
- codeBlockLang = '';
173
- continue;
174
- }
175
- }
176
-
177
- if (inCodeBlock) {
178
- codeBlockContent.push(line);
179
- continue;
180
- }
181
-
182
- // horizontal rule: --- or *** or ___
183
- if (/^(\s*[-*_]\s*){3,}$/.test(line)) {
184
- flushParagraph();
185
- flushList();
186
- html.push('<hr>');
187
- continue;
188
- }
189
-
190
- // headings: # to ####
191
- var headingMatch = /^(#{1,4})\s+(.+)$/.exec(line);
192
- if (headingMatch) {
193
- flushParagraph();
194
- flushList();
195
- var level = headingMatch[1].length;
196
- html.push('<h' + level + '>' + _clRenderInlineMarkdown(headingMatch[2]) + '</h' + level + '>');
197
- continue;
198
- }
199
-
200
- // unordered list: - item or * item
201
- var ulMatch = /^(\s*)[-*]\s+(.+)$/.exec(line);
202
- if (ulMatch) {
203
- flushParagraph();
204
- if (!inList || listType !== 'ul') {
205
- flushList();
206
- html.push('<ul>');
207
- inList = true;
208
- listType = 'ul';
209
- }
210
- html.push('<li>' + _clRenderInlineMarkdown(ulMatch[2]) + '</li>');
211
- continue;
212
- }
213
-
214
- // ordered list: 1. item
215
- var olMatch = /^(\s*)\d+\.\s+(.+)$/.exec(line);
216
- if (olMatch) {
217
- flushParagraph();
218
- if (!inList || listType !== 'ol') {
219
- flushList();
220
- html.push('<ol>');
221
- inList = true;
222
- listType = 'ol';
223
- }
224
- html.push('<li>' + _clRenderInlineMarkdown(olMatch[2]) + '</li>');
225
- continue;
226
- }
227
-
228
- // empty line → flush paragraph and list
229
- if (line.trim() === '') {
230
- flushParagraph();
231
- flushList();
232
- continue;
233
- }
234
-
235
- // regular text → accumulate into paragraph
236
- flushList();
237
- paragraphLines.push(_clRenderInlineMarkdown(line));
238
- }
239
-
240
- // handle unclosed code block
241
- if (inCodeBlock) {
242
- var remainingCode = _clEscapeHtml(codeBlockContent.join('\n'));
243
- html.push('<pre><code>' + remainingCode + '</code></pre>');
244
- }
245
-
246
- flushParagraph();
247
- flushList();
248
-
249
- // ── 第 3 步:还原 travel card 占位符 ──
250
- var result = html.join('\n');
251
- for (var j = 0; j < travelPlaceholders.length; j++) {
252
- result = result.replace('\x00CL_TRAVEL_' + j + '\x00', travelPlaceholders[j]);
253
- }
254
-
255
- return result;
256
- }
@@ -1,151 +0,0 @@
1
- // ── OpenAgent Media Links — toolResult MEDIA: protocol renderer ──
2
- //
3
- // OpenClaw host parses MEDIA: links in assistant text, but remote-agent
4
- // toolResult text is rendered through the plugin card path. Keep this parser
5
- // local to the card so OASN artifacts become visible downloads.
6
-
7
- function _clExtractOpenagentMediaLinksFromText(rawText) {
8
- var value = String(rawText || '');
9
- var links = [];
10
- var seen = Object.create(null);
11
-
12
- function addUrl(rawUrl) {
13
- var url = _clNormalizeOpenagentMediaUrl(rawUrl);
14
- if (!url || seen[url]) return;
15
- seen[url] = true;
16
-
17
- var fileName = _clGetOpenagentMediaFileName(url);
18
- links.push({
19
- url: url,
20
- fileName: fileName,
21
- extension: _clInferOpenagentMediaExtension(fileName),
22
- });
23
- }
24
-
25
- var re = /^\s*MEDIA:\s*(\S+)\s*$/gm;
26
- var match;
27
-
28
- while ((match = re.exec(value)) !== null) {
29
- addUrl(match[1]);
30
- }
31
-
32
- var markdownRe = /\[[^\]]+\]\((https?:\/\/[^)\s]+|\/[^)\s]+)\)/g;
33
- while ((match = markdownRe.exec(value)) !== null) {
34
- addUrl(match[1]);
35
- }
36
-
37
- return links;
38
- }
39
-
40
- function _clExtractOpenagentMediaLinksFromModel(model) {
41
- var allText = [];
42
- if (model && model.rawText) allText.push(model.rawText);
43
- var chunks = model && Array.isArray(model.chunks) ? model.chunks : [];
44
- for (var i = 0; i < chunks.length; i++) {
45
- if (chunks[i] && chunks[i].text) allText.push(chunks[i].text);
46
- }
47
- return _clExtractOpenagentMediaLinksFromText(allText.join('\n'));
48
- }
49
-
50
- function _clNormalizeOpenagentMediaUrl(rawUrl) {
51
- var value = String(rawUrl || '').trim();
52
- if (!value) return '';
53
- value = value.replace(/^[`'"]+/, '').replace(/[`'".,;)\]]+$/, '');
54
-
55
- if (value.charAt(0) === '/') return value;
56
-
57
- try {
58
- var parsed = new URL(value);
59
- if (parsed.protocol === 'http:' || parsed.protocol === 'https:') return value;
60
- } catch (e) {}
61
-
62
- return '';
63
- }
64
-
65
- function _clGetOpenagentMediaFileName(url) {
66
- var pathValue = '';
67
- try {
68
- var base = (typeof window !== 'undefined' && window.location && window.location.href)
69
- ? window.location.href
70
- : 'http://127.0.0.1/';
71
- pathValue = new URL(url, base).pathname || '';
72
- } catch (e) {
73
- pathValue = String(url || '').split('?')[0] || '';
74
- }
75
-
76
- var parts = pathValue.split('/');
77
- var fileName = parts[parts.length - 1] || 'artifact';
78
- try {
79
- fileName = decodeURIComponent(fileName);
80
- } catch (e) {}
81
- return fileName || 'artifact';
82
- }
83
-
84
- function _clInferOpenagentMediaExtension(fileName) {
85
- var match = String(fileName || '').toLowerCase().match(/\.([a-z0-9]{1,12})$/);
86
- return match ? match[1] : '';
87
- }
88
-
89
- function _clStripOpenagentMediaLines(rawText) {
90
- return String(rawText || '')
91
- .split(/\r?\n/)
92
- .filter(function(line) { return !/^\s*MEDIA:\s*/.test(line); })
93
- .join('\n')
94
- .trim();
95
- }
96
-
97
- function _clCreateOpenagentMediaLinksSection(links) {
98
- if (!Array.isArray(links) || links.length === 0) return null;
99
-
100
- var section = document.createElement('div');
101
- section.className = 'cl-openagent-media-links';
102
-
103
- for (var i = 0; i < links.length; i++) {
104
- var link = links[i] || {};
105
- if (!link.url) continue;
106
-
107
- var anchor = document.createElement('a');
108
- anchor.className = 'cl-openagent-media-link';
109
- anchor.href = link.url;
110
- anchor.target = '_blank';
111
- anchor.rel = 'noopener noreferrer';
112
- anchor.download = link.fileName || '';
113
- anchor.title = link.fileName || link.url;
114
-
115
- var icon = document.createElement('span');
116
- icon.className = 'cl-openagent-media-link-icon';
117
- icon.textContent = _clGetOpenagentMediaIconText(link.extension);
118
- anchor.appendChild(icon);
119
-
120
- var text = document.createElement('span');
121
- text.className = 'cl-openagent-media-link-text';
122
- text.textContent = _clGetOpenagentMediaActionText(link.extension);
123
- anchor.appendChild(text);
124
-
125
- var file = document.createElement('span');
126
- file.className = 'cl-openagent-media-link-file';
127
- file.textContent = link.fileName || 'artifact';
128
- anchor.appendChild(file);
129
-
130
- section.appendChild(anchor);
131
- }
132
-
133
- return section.childNodes.length > 0 ? section : null;
134
- }
135
-
136
- function _clGetOpenagentMediaActionText(extension) {
137
- var ext = String(extension || '').toUpperCase();
138
- if (!ext) return '下载附件';
139
- return '下载 ' + ext;
140
- }
141
-
142
- function _clGetOpenagentMediaIconText(extension) {
143
- extension = String(extension || '').toLowerCase();
144
- if (extension === 'pptx' || extension === 'ppt') return 'P';
145
- if (extension === 'docx' || extension === 'doc') return 'D';
146
- if (extension === 'xlsx' || extension === 'xls' || extension === 'csv') return 'X';
147
- if (extension === 'json') return '{}';
148
- if (extension === 'md' || extension === 'txt') return 'T';
149
- if (extension === 'zip') return 'Z';
150
- return 'F';
151
- }
@@ -1,134 +0,0 @@
1
- // ── OpenAgent Native Style Adapter ──
2
- //
3
- // 从当前页面的 OpenClaw 原生 ToolCard 读取尺寸参数,
4
- // 写入 CSS variables 供 OpenAgent 折叠态消费。
5
- //
6
- // 颜色不做 computed style,继续使用 OpenClaw 宿主 CSS variables(var(--card) 等)。
7
- // 只读取:padding, borderRadius, gap, minHeight, fontSize, lineHeight。
8
-
9
- (function _clInitNativeStyleAdapter() {
10
- var _clNativeStyleSampled = false;
11
- var hostAdapter = CL.hostAdapter || {};
12
- var nativeStyle = hostAdapter.nativeStyle || {};
13
-
14
- var SHELL_SELECTORS = nativeStyle.shellSelectors || [];
15
- var SUMMARY_SELECTORS = nativeStyle.summarySelectors || [];
16
- var INDENT_SELECTORS = nativeStyle.indentSelectors || [];
17
-
18
- // Fallback 默认值(和当前 styles.js 折叠态写死值保持一致,避免跳变)
19
- var FALLBACKS = {
20
- '--cl-native-shell-padding': '8px',
21
- '--cl-native-shell-radius': '14px',
22
- '--cl-native-shell-gap': '4px',
23
- '--cl-native-summary-padding': '6px 10px',
24
- '--cl-native-summary-radius': '10px',
25
- '--cl-native-summary-gap': '6px',
26
- '--cl-native-summary-min-height': '34px',
27
- '--cl-native-summary-font-size': '13px',
28
- '--cl-native-summary-line-height': '1.2',
29
- '--cl-native-tool-indent': '0px'
30
- };
31
-
32
- function findFirst(selectors) {
33
- for (var i = 0; i < selectors.length; i++) {
34
- var el = document.querySelector(selectors[i]);
35
- if (el) return el;
36
- }
37
- return null;
38
- }
39
-
40
- function readSize(cs, prop) {
41
- var val = cs ? cs[prop] : '';
42
- // 过滤无意义值
43
- if (!val || val === 'auto' || val === 'none' || val === 'normal' || val === '0px') return '';
44
- return val;
45
- }
46
-
47
- function setVar(name, value) {
48
- try {
49
- document.documentElement.style.setProperty(name, value);
50
- } catch (err) {}
51
- }
52
-
53
- function applyFallbacks() {
54
- for (var key in FALLBACKS) {
55
- if (Object.prototype.hasOwnProperty.call(FALLBACKS, key)) {
56
- setVar(key, FALLBACKS[key]);
57
- }
58
- }
59
- console.log('[cl-adapter] applied fallback native style variables');
60
- }
61
-
62
- function sampleFromDOM() {
63
- if (_clNativeStyleSampled) return;
64
-
65
- var shellEl = findFirst(SHELL_SELECTORS);
66
- var summaryEl = findFirst(SUMMARY_SELECTORS);
67
-
68
- if (!shellEl && !summaryEl) {
69
- // 页面没有原生 ToolCard,使用 fallback
70
- applyFallbacks();
71
- // 不设 _clNativeStyleSampled = true,下次 render hook 再尝试
72
- return;
73
- }
74
-
75
- _clNativeStyleSampled = true;
76
-
77
- if (shellEl) {
78
- var scs = getComputedStyle(shellEl);
79
- setVar('--cl-native-shell-padding', readSize(scs, 'padding') || FALLBACKS['--cl-native-shell-padding']);
80
- setVar('--cl-native-shell-radius', readSize(scs, 'borderRadius') || FALLBACKS['--cl-native-shell-radius']);
81
- setVar('--cl-native-shell-gap', readSize(scs, 'gap') || FALLBACKS['--cl-native-shell-gap']);
82
- console.log('[cl-adapter] sampled shell from ' + (shellEl.className || '').substring(0, 40));
83
- } else {
84
- setVar('--cl-native-shell-padding', FALLBACKS['--cl-native-shell-padding']);
85
- setVar('--cl-native-shell-radius', FALLBACKS['--cl-native-shell-radius']);
86
- setVar('--cl-native-shell-gap', FALLBACKS['--cl-native-shell-gap']);
87
- }
88
-
89
- if (summaryEl) {
90
- var hcs = getComputedStyle(summaryEl);
91
- setVar('--cl-native-summary-padding', readSize(hcs, 'padding') || FALLBACKS['--cl-native-summary-padding']);
92
- setVar('--cl-native-summary-radius', readSize(hcs, 'borderRadius') || FALLBACKS['--cl-native-summary-radius']);
93
- setVar('--cl-native-summary-gap', readSize(hcs, 'gap') || FALLBACKS['--cl-native-summary-gap']);
94
- setVar('--cl-native-summary-min-height', readSize(hcs, 'minHeight') || FALLBACKS['--cl-native-summary-min-height']);
95
- setVar('--cl-native-summary-font-size', readSize(hcs, 'fontSize') || FALLBACKS['--cl-native-summary-font-size']);
96
- setVar('--cl-native-summary-line-height', readSize(hcs, 'lineHeight') || FALLBACKS['--cl-native-summary-line-height']);
97
- console.log('[cl-adapter] sampled summary from ' + (summaryEl.className || '').substring(0, 40));
98
- } else {
99
- setVar('--cl-native-summary-padding', FALLBACKS['--cl-native-summary-padding']);
100
- setVar('--cl-native-summary-radius', FALLBACKS['--cl-native-summary-radius']);
101
- setVar('--cl-native-summary-gap', FALLBACKS['--cl-native-summary-gap']);
102
- setVar('--cl-native-summary-min-height', FALLBACKS['--cl-native-summary-min-height']);
103
- setVar('--cl-native-summary-font-size', FALLBACKS['--cl-native-summary-font-size']);
104
- setVar('--cl-native-summary-line-height', FALLBACKS['--cl-native-summary-line-height']);
105
- }
106
-
107
- // ── 缩进采样 ──
108
- var indentEl = findFirst(INDENT_SELECTORS);
109
- if (indentEl) {
110
- // 二次确认不含 OpenAgent card(防止 :has() 时序问题)
111
- if (indentEl.querySelector && indentEl.querySelector('.cl-remote-agent-card')) {
112
- indentEl = null;
113
- }
114
- }
115
- if (indentEl) {
116
- var ics = getComputedStyle(indentEl);
117
- var plVal = parseFloat(ics.paddingLeft) || 0;
118
- var mlVal = parseFloat(ics.marginLeft) || 0;
119
- var indent = Math.max(plVal, mlVal);
120
- setVar('--cl-native-tool-indent', indent > 0 ? indent + 'px' : '0px');
121
- console.log('[cl-adapter] sampled indent=' + indent + 'px from ' + (indentEl.className || '').substring(0, 40));
122
- } else {
123
- setVar('--cl-native-tool-indent', FALLBACKS['--cl-native-tool-indent']);
124
- }
125
- }
126
-
127
- // 暴露为全局函数,render hook 首次命中 remote-agent 时 lazy 调用
128
- window._clEnsureNativeToolStyleVars = sampleFromDOM;
129
-
130
- // 写入 fallback(确保即使未采样也有值可用)
131
- applyFallbacks();
132
-
133
- console.log('[cl-adapter] ✅ native style adapter initialized');
134
- })();