@springbrand/message-panel 0.1.3-alpha.2 → 0.1.3-alpha.22
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/cloud-os/README.md +6 -6
- package/cloud-os/assets/followup-arrow.svg +3 -0
- package/cloud-os/assets/loading-corner.svg +3 -0
- package/cloud-os/assets/loading-mark.svg +16 -0
- package/cloud-os/assets/loading-spark.svg +3 -0
- package/cloud-os/assets/model-selected.svg +5 -0
- package/cloud-os/capability-chip.tsx +35 -0
- package/cloud-os/chat/activity-indicator.tsx +29 -0
- package/cloud-os/chat/cloud-os-chat-messages.tsx +130 -70
- package/cloud-os/chat/markdown-message.tsx +85 -40
- package/cloud-os/chat/rich-blocks.tsx +494 -190
- package/cloud-os/chat/tool-presentation.ts +67 -6
- package/cloud-os/chat/tool-rows.tsx +87 -43
- package/cloud-os/chat/transcript-model.ts +215 -23
- package/cloud-os/composer/cloud-os-chat-input.tsx +242 -127
- package/cloud-os/composer/cloud-os-model-select.tsx +105 -0
- package/cloud-os/file-view.tsx +266 -0
- package/cloud-os/index.ts +29 -2
- package/cloud-os/layout/cloud-os-workspace-split.tsx +107 -24
- package/cloud-os/primitives/workshop-controls.tsx +2 -2
- package/cloud-os/styles/cloud-os.css +93 -19
- package/demo/camel-chat-showcase.tsx +21 -13
- package/demo/chat-scenarios.ts +100 -40
- package/demo/cloud-os-chat-showcase.tsx +51 -17
- package/demo/fixtures.ts +4 -5
- package/demo/message-panel-gallery.tsx +16 -2
- package/package.json +3 -4
- package/src/camel/camel-chat-messages.tsx +82 -77
- package/src/camel/camel-prompt-input.tsx +2 -1
- package/src/camel/camel-tool-presentation.tsx +19 -15
- package/src/camel/camel-turn.ts +1 -17
- package/src/chat-summary-panel.tsx +1 -1
- package/src/composer/chat-composer.tsx +2 -1
- package/src/composer/composer-trigger-popover.tsx +1 -1
- package/src/composer/composer.tsx +2 -1
- package/src/composer/index.ts +1 -0
- package/src/composer/key-rules.ts +12 -0
- package/src/contracts.ts +0 -2
- package/src/message-panel.tsx +0 -23
- package/src/parts/index.tsx +102 -63
- package/src/styles/index.css +4 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { memo, useMemo, type ReactNode } from "react";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
defaultRehypePlugins,
|
|
4
|
+
Streamdown,
|
|
5
|
+
type Components,
|
|
6
|
+
type StreamdownProps,
|
|
7
|
+
} from "streamdown";
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* UIMessage 协议里没有对应概念,留着只会是死代码。
|
|
9
|
-
* 保留的部分:skipHtml、remark-gfm、表格外包一层横向滚动、外链白名单 + target=_blank。
|
|
10
|
-
* 加上的部分:resolveUrl —— 本仓的消息里会出现 `sandbox:/workspace/...` 这种
|
|
11
|
-
* 只有宿主知道怎么翻译成可访问 URL 的地址,原来由 camel 的同名钩子负责。
|
|
10
|
+
* Streamdown 依然使用原生标签,避免它的默认 Tailwind 组件样式覆盖 cloud-os CSS。
|
|
11
|
+
* resolveUrl 负责把 `sandbox:/workspace/...` 翻译成可访问 URL。
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
export type CloudOsUrlResolver = (url: string) => string | null | undefined;
|
|
@@ -25,54 +25,99 @@ export function safeExternalUrl(href: string | undefined): string | undefined {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
51
|
-
}
|
|
28
|
+
const STREAMDOWN_REHYPE_PLUGINS = Object.values(
|
|
29
|
+
defaultRehypePlugins,
|
|
30
|
+
) as NonNullable<StreamdownProps["rehypePlugins"]>;
|
|
31
|
+
|
|
32
|
+
type UrlNode = {
|
|
33
|
+
type?: string;
|
|
34
|
+
properties?: Record<string, unknown>;
|
|
35
|
+
children?: UrlNode[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function resolveUrlsPlugin(resolveUrl: CloudOsUrlResolver) {
|
|
39
|
+
return () => (tree: UrlNode) => {
|
|
40
|
+
const visit = (node: UrlNode): void => {
|
|
41
|
+
if (node.type === "element" && node.properties) {
|
|
42
|
+
for (const attribute of ["href", "src"]) {
|
|
43
|
+
const url = node.properties[attribute];
|
|
44
|
+
if (typeof url !== "string") continue;
|
|
45
|
+
const resolved = resolveUrl(url);
|
|
46
|
+
if (resolved === null) delete node.properties[attribute];
|
|
47
|
+
else if (resolved !== undefined) node.properties[attribute] = resolved;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
node.children?.forEach(visit);
|
|
51
|
+
};
|
|
52
|
+
visit(tree);
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
const
|
|
56
|
-
|
|
56
|
+
const DEFAULT_COMPONENTS: Components = {
|
|
57
|
+
blockquote: "blockquote",
|
|
58
|
+
code: "code",
|
|
59
|
+
h1: "h1",
|
|
60
|
+
h2: "h2",
|
|
61
|
+
h3: "h3",
|
|
62
|
+
h4: "h4",
|
|
63
|
+
h5: "h5",
|
|
64
|
+
h6: "h6",
|
|
65
|
+
hr: "hr",
|
|
66
|
+
li: "li",
|
|
67
|
+
ol: "ol",
|
|
68
|
+
p: "p",
|
|
69
|
+
pre: "pre",
|
|
70
|
+
section: "section",
|
|
71
|
+
strong: "strong",
|
|
72
|
+
sub: "sub",
|
|
73
|
+
sup: "sup",
|
|
74
|
+
table: "table",
|
|
75
|
+
tbody: "tbody",
|
|
76
|
+
td: "td",
|
|
77
|
+
th: "th",
|
|
78
|
+
thead: "thead",
|
|
79
|
+
tr: "tr",
|
|
80
|
+
ul: "ul",
|
|
81
|
+
img: ({ node: _node, src, ...props }) =>
|
|
82
|
+
src ? <img {...props} src={src} /> : null,
|
|
83
|
+
a: ({ node: _node, href, children, ...props }) => {
|
|
84
|
+
const safeHref = safeExternalUrl(href);
|
|
85
|
+
if (!safeHref) return <>{children}</>;
|
|
86
|
+
return (
|
|
87
|
+
<a {...props} href={safeHref} target="_blank" rel="noopener noreferrer">
|
|
88
|
+
{children}
|
|
89
|
+
</a>
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
57
93
|
|
|
58
94
|
export const MarkdownMessage = memo(function MarkdownMessage({
|
|
59
95
|
message,
|
|
60
96
|
resolveUrl,
|
|
97
|
+
streaming = false,
|
|
61
98
|
}: {
|
|
62
99
|
message: string;
|
|
63
100
|
resolveUrl?: CloudOsUrlResolver;
|
|
101
|
+
streaming?: boolean;
|
|
64
102
|
}): ReactNode {
|
|
65
|
-
const
|
|
66
|
-
() =>
|
|
103
|
+
const rehypePlugins = useMemo(
|
|
104
|
+
() =>
|
|
105
|
+
resolveUrl
|
|
106
|
+
? [resolveUrlsPlugin(resolveUrl), ...STREAMDOWN_REHYPE_PLUGINS]
|
|
107
|
+
: STREAMDOWN_REHYPE_PLUGINS,
|
|
67
108
|
[resolveUrl],
|
|
68
109
|
);
|
|
69
110
|
return (
|
|
70
|
-
<
|
|
111
|
+
<Streamdown
|
|
112
|
+
className="space-y-0"
|
|
113
|
+
controls={false}
|
|
114
|
+
mode={streaming ? "streaming" : "static"}
|
|
115
|
+
isAnimating={streaming}
|
|
116
|
+
rehypePlugins={rehypePlugins}
|
|
71
117
|
skipHtml
|
|
72
|
-
|
|
73
|
-
components={components}
|
|
118
|
+
components={DEFAULT_COMPONENTS}
|
|
74
119
|
>
|
|
75
120
|
{message}
|
|
76
|
-
</
|
|
121
|
+
</Streamdown>
|
|
77
122
|
);
|
|
78
123
|
});
|