Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 块级加入 `人工智能` https://github.com/siyuan-note/siyuan/issues/7566

Liang Dinge09b37e2855b
diff --git a/kernel/model/ai.go b/kernel/model/ai.go
index 401e690140..bc48dc5a9e 100644
--- a/kernel/model/ai.go
+++ b/kernel/model/ai.go
@@ -19,7 +19,9 @@ package model
import (
"bytes"
- "github.com/siyuan-note/siyuan/kernel/sql"
+ "github.com/88250/lute/ast"
+ "github.com/88250/lute/parse"
+ "github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@@ -70,12 +72,40 @@ func isOpenAIAPIEnabled() bool {
}
func getBlocksContent(ids []string) string {
- sqlBlocks := sql.GetBlocks(ids)
+ var nodes []*ast.Node
+ trees := map[string]*parse.Tree{}
+ for _, id := range ids {
+ bt := treenode.GetBlockTree(id)
+ if nil == bt {
+ continue
+ }
+
+ var tree *parse.Tree
+ if tree = trees[bt.RootID]; nil == tree {
+ tree, _ = loadTreeByBlockID(bt.RootID)
+ if nil == tree {
+ continue
+ }
+
+ trees[bt.RootID] = tree
+ }
+
+ if node := treenode.GetNodeInTree(tree, id); nil != node {
+ if ast.NodeDocument == node.Type {
+ for child := node.FirstChild; nil != child; child = child.Next {
+ nodes = append(nodes, child)
+ }
+ } else {
+ nodes = append(nodes, node)
+ }
+ }
+ }
+
buf := bytes.Buffer{}
- for _, sqlBlock := range sqlBlocks {
- buf.WriteString(sqlBlock.Content)
+ for _, node := range nodes {
+ content := treenode.NodeStaticContent(node, nil, true)
+ buf.WriteString(content)
buf.WriteString("\n\n")
}
-
return buf.String()
}