feat(mindspace): 0630004 空间 UI、聊天连接、微信分享与 Agent 能力
含 MindSpace 三列布局与统计修复、聊天加载态与连接降级、平台页脚标记与 og:site_name 微信卡片、勾选资料删除 Agent 接口及内部话术过滤。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+13
-3
@@ -1,7 +1,7 @@
|
||||
import type { Message, MessageContent } from '../types';
|
||||
import { mergeMessageContent } from '../../message-stream.mjs';
|
||||
import { mergeConversationSnapshot as mergeConversationSnapshotCore } from '../../chat-finish-sync.mjs';
|
||||
import { deriveUserFacingText } from '../../conversation-display.mjs';
|
||||
import { deriveUserFacingText, deriveAssistantFacingText } from '../../conversation-display.mjs';
|
||||
import { stripUserAddressPrefix } from './userAddress';
|
||||
|
||||
const IMAGE_URL_LINE_RE = /^\[图片\d+]: (.+)$/;
|
||||
@@ -182,12 +182,22 @@ export function getDisplayText(message: Message): string {
|
||||
return stripImageUrlLines(deriveUserFacingText(raw));
|
||||
}
|
||||
if ('displayText' in message.metadata) {
|
||||
return stripImageUrlLines(message.metadata.displayText ?? '');
|
||||
return stripImageUrlLines(deriveAssistantFacingText(message.metadata.displayText ?? ''));
|
||||
}
|
||||
const systemText = getSystemNotificationText(message);
|
||||
if (systemText) return systemText;
|
||||
const visible = getVisibleText(message);
|
||||
return visible;
|
||||
return stripImageUrlLines(deriveAssistantFacingText(visible));
|
||||
}
|
||||
|
||||
export function shouldShowChatMessage(message: Message): boolean {
|
||||
if (message.role === 'user') return true;
|
||||
if (getDisplayText(message).trim()) return true;
|
||||
if (getThinking(message)) return true;
|
||||
if (getSystemNotificationText(message)) return true;
|
||||
return message.content.some(
|
||||
(item) => item.type === 'toolRequest' || item.type === 'toolResponse' || item.type === 'actionRequired',
|
||||
);
|
||||
}
|
||||
|
||||
export function pushMessage(messages: Message[], incoming: Message): Message[] {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { prepareHtmlPageBrandMarkers } from '../../mindspace-page-tag.mjs';
|
||||
|
||||
export const MINDSPACE_PAGE_CONTENT_MESSAGE = 'mindspace:page-content';
|
||||
|
||||
const EDITOR_STYLE = `<style id="mindspace-visual-editor-style">
|
||||
@@ -218,6 +220,23 @@ const EDITOR_STYLE = `<style id="mindspace-visual-editor-style">
|
||||
background: rgba(24, 33, 29, 0.08);
|
||||
cursor: pointer;
|
||||
}
|
||||
.mindspace-editor-legend[data-collapsed="true"] {
|
||||
width: auto;
|
||||
max-width: min(280px, calc(100vw - 24px));
|
||||
gap: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.mindspace-editor-legend[data-collapsed="true"] .mindspace-editor-legend-body {
|
||||
display: none;
|
||||
}
|
||||
.mindspace-editor-legend[data-collapsed="true"] .mindspace-editor-legend-title::after {
|
||||
content: ' · 点击展开';
|
||||
font-weight: 400;
|
||||
color: #6d7771;
|
||||
}
|
||||
[data-mindspace-editing="true"] [data-mindspace-page-tag] {
|
||||
display: none !important;
|
||||
}
|
||||
</style>`;
|
||||
|
||||
const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
@@ -226,9 +245,14 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
var TEXT_SELECTOR = 'h1,h2,h3,h4,h5,h6,p,li,td,th,figcaption,blockquote,span,a,label,small,strong,em,b,i,u,sub,sup,cite,time,address,dt,dd,button,.sub,.tagline,[class*="title"],[class*="subtitle"],[class*="desc"],[class*="text"]';
|
||||
var BLOCK_CHILD_SELECTOR = 'div,section,article,header,footer,main,p,h1,h2,h3,h4,h5,h6,ul,ol,table,form,video,audio,iframe,svg,canvas';
|
||||
var MEDIA_BLOCK_SELECTOR = 'img,video,iframe,svg,canvas,table,ul,ol,form';
|
||||
var PAGE_TAG_SELECTOR = '[data-mindspace-page-tag]';
|
||||
var popover = null;
|
||||
var emitTimer = null;
|
||||
|
||||
function isProtectedNode(el) {
|
||||
return !!(el && el.closest && el.closest(PAGE_TAG_SELECTOR));
|
||||
}
|
||||
|
||||
function debounceEmit() {
|
||||
if (emitTimer) window.clearTimeout(emitTimer);
|
||||
emitTimer = window.setTimeout(emitChange, 350);
|
||||
@@ -479,6 +503,7 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
var nodes = document.querySelectorAll('body, main, section, article, header, footer, div');
|
||||
nodes.forEach(function (el) {
|
||||
if (el.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(el)) return;
|
||||
if (el.isContentEditable) return;
|
||||
var style = window.getComputedStyle(el);
|
||||
var cls = String(el.className || '');
|
||||
@@ -497,18 +522,22 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
function markMediaTargets() {
|
||||
document.querySelectorAll('img').forEach(function (img) {
|
||||
if (img.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(img)) return;
|
||||
markEditable(img, 'media', '点击换图片');
|
||||
});
|
||||
document.querySelectorAll('video').forEach(function (video) {
|
||||
if (video.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(video)) return;
|
||||
markEditable(video, 'media', '点击换视频');
|
||||
});
|
||||
document.querySelectorAll('audio').forEach(function (audio) {
|
||||
if (audio.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(audio)) return;
|
||||
markEditable(audio, 'media', '点击换音频');
|
||||
});
|
||||
document.querySelectorAll('iframe').forEach(function (iframe) {
|
||||
if (iframe.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(iframe)) return;
|
||||
iframe.setAttribute('data-mindspace-media-target', 'true');
|
||||
markEditable(iframe, 'media', '点击换嵌入');
|
||||
});
|
||||
@@ -517,6 +546,7 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
function markLinkTargets() {
|
||||
document.querySelectorAll('a[href]').forEach(function (anchor) {
|
||||
if (anchor.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(anchor)) return;
|
||||
anchor.setAttribute('data-mindspace-link-target', 'true');
|
||||
markEditable(anchor, 'link', '双击改链接');
|
||||
});
|
||||
@@ -525,6 +555,7 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
function enableTextEditing() {
|
||||
document.querySelectorAll(TEXT_SELECTOR).forEach(function (el) {
|
||||
if (el.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(el)) return;
|
||||
if (el.querySelector && el.querySelector(MEDIA_BLOCK_SELECTOR)) return;
|
||||
if (el.matches('a[data-mindspace-link-target="true"]')) return;
|
||||
var textParent = el.closest('[data-mindspace-edit-kind="text"]');
|
||||
@@ -536,6 +567,7 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
|
||||
document.querySelectorAll('div').forEach(function (el) {
|
||||
if (el.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(el)) return;
|
||||
if (el.hasAttribute('contenteditable')) return;
|
||||
if (el.querySelector(BLOCK_CHILD_SELECTOR)) return;
|
||||
if (el.querySelector(MEDIA_BLOCK_SELECTOR)) return;
|
||||
@@ -550,16 +582,19 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
var legend = document.createElement('div');
|
||||
legend.className = 'mindspace-editor-legend';
|
||||
legend.innerHTML =
|
||||
'<strong>编辑模式 · 可修改区域</strong>' +
|
||||
'<strong class="mindspace-editor-legend-title">编辑模式 · 可修改区域</strong>' +
|
||||
'<div class="mindspace-editor-legend-body">' +
|
||||
'<div class="mindspace-editor-legend-items">' +
|
||||
'<div class="mindspace-editor-legend-item"><span class="mindspace-editor-legend-swatch" data-kind="text"></span><span>蓝色虚线 = 文字,直接点击修改</span></div>' +
|
||||
'<div class="mindspace-editor-legend-item"><span class="mindspace-editor-legend-swatch" data-kind="media"></span><span>橙色虚线 = 图片/音视频,点击替换</span></div>' +
|
||||
'<div class="mindspace-editor-legend-item"><span class="mindspace-editor-legend-swatch" data-kind="link"></span><span>紫色虚线 = 链接,双击改地址</span></div>' +
|
||||
'<div class="mindspace-editor-legend-item"><span class="mindspace-editor-legend-swatch" data-kind="background"></span><span>绿色虚线 = 背景区域,点击换背景</span></div>' +
|
||||
'</div>' +
|
||||
'<button type="button" class="mindspace-editor-legend-toggle" data-action="toggle-highlights">隐藏标记</button>';
|
||||
'<button type="button" class="mindspace-editor-legend-toggle" data-action="toggle-highlights">隐藏标记</button>' +
|
||||
'</div>';
|
||||
document.body.appendChild(legend);
|
||||
legend.querySelector('[data-action="toggle-highlights"]').addEventListener('click', function () {
|
||||
legend.querySelector('[data-action="toggle-highlights"]').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
var hidden = document.body.getAttribute('data-mindspace-highlights') === 'off';
|
||||
if (hidden) {
|
||||
document.body.removeAttribute('data-mindspace-highlights');
|
||||
@@ -569,12 +604,21 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
this.textContent = '显示标记';
|
||||
}
|
||||
});
|
||||
legend.addEventListener('click', function () {
|
||||
if (legend.getAttribute('data-collapsed') === 'true') {
|
||||
legend.removeAttribute('data-collapsed');
|
||||
}
|
||||
});
|
||||
window.setTimeout(function () {
|
||||
legend.setAttribute('data-collapsed', 'true');
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function onClick(event) {
|
||||
var target = event.target;
|
||||
if (!(target instanceof Element)) return;
|
||||
if (target.closest('.mindspace-editor-popover,.mindspace-editor-guide,.mindspace-editor-legend')) return;
|
||||
if (isProtectedNode(target)) return;
|
||||
|
||||
if (target.tagName === 'IMG') {
|
||||
event.preventDefault();
|
||||
@@ -601,6 +645,7 @@ const EDITOR_SCRIPT = `<script id="mindspace-visual-editor-script">
|
||||
function onDblClick(event) {
|
||||
var target = event.target;
|
||||
if (!(target instanceof Element)) return;
|
||||
if (isProtectedNode(target)) return;
|
||||
var anchor = target.closest('a[data-mindspace-link-target="true"]');
|
||||
if (!anchor) return;
|
||||
event.preventDefault();
|
||||
@@ -644,7 +689,7 @@ export function stripPreviewEditCspMeta(html: string): string {
|
||||
}
|
||||
|
||||
export function buildEditablePreviewDocument(html: string): string {
|
||||
const source = String(html ?? '').trim();
|
||||
const source = prepareHtmlPageBrandMarkers(String(html ?? '').trim());
|
||||
const cleaned = stripPreviewEditCspMeta(source)
|
||||
.replace(/<style id="mindspace-visual-editor-style">[\s\S]*?<\/style>/gi, '')
|
||||
.replace(/<script id="mindspace-visual-editor-script">[\s\S]*?<\/script>/gi, '');
|
||||
|
||||
Reference in New Issue
Block a user