|
@@ -196,6 +196,9 @@ const parseMessagesForLibrary = (messages: Message[]): ComponentLibraryItem[] =>
|
|
|
|
|
|
// 提取表格
|
|
|
extractTablesFromTokens(tokens, messageIndex, libraryItems)
|
|
|
+
|
|
|
+ // 提取结构化数据
|
|
|
+ extractStructDataFromTokens(tokens, messageIndex, libraryItems)
|
|
|
})
|
|
|
|
|
|
return libraryItems
|
|
@@ -243,6 +246,32 @@ const extractEchartsFromTokens = (tokens: any[], messageIndex: number, libraryIt
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+// 从tokens中提取echarts代码块
|
|
|
+const extractStructDataFromTokens = (tokens: any[], messageIndex: number, libraryItems: ComponentLibraryItem[]) => {
|
|
|
+ tokens.forEach((token, tokenIndex) => {
|
|
|
+ if (token.type === 'fence') {
|
|
|
+ const info = token.info ? token.info.trim() : ''
|
|
|
+ const content = token.content.trim()
|
|
|
+
|
|
|
+ if (info === 'structdata') {
|
|
|
+ try {
|
|
|
+ libraryItems.push({
|
|
|
+ id: `struct-${messageIndex}-${tokenIndex}`,
|
|
|
+ icon: PieChart,
|
|
|
+ description: `来自消息的动态图表`,
|
|
|
+ type: 'structdata',
|
|
|
+ data: content,
|
|
|
+ preview: content,
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.warn('解析struct配置失败:', error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// 解析表格数据的接口
|
|
|
interface TableData {
|
|
|
headers: string[]
|