fix: send full block tree as task description

This commit is contained in:
Tienson Qin
2026-02-28 00:40:01 +08:00
parent 96829c97ad
commit b8d44aecb5
2 changed files with 31 additions and 17 deletions

View File

@@ -1,8 +1,8 @@
(ns logseq.agents.dispatch
(:require [clojure.string :as string]
[logseq.agents.handler :as agent-handler]
[logseq.sync.common :as common]
[logseq.sync.platform.core :as platform]
[logseq.agents.handler :as agent-handler]
[logseq.sync.worker.http :as http]
[promesa.core :as p]))
@@ -25,16 +25,12 @@
:else
(http/not-found))))
(p/catch (fn [error]
(let [err-type (str (type error))
message (try (.-message error) (catch :default _ nil))
data (try (ex-data error) (catch :default _ nil))
stack (try (.-stack error) (catch :default _ nil))
json-str (try (js/JSON.stringify error) (catch :default _ nil))]
;; Avoid deep error introspection here. Some V8/runtime failures can
;; abort the process while materializing stack/JSON from optimized frames.
(let [message (try (.-message error) (catch :default _ nil))
data (try (ex-data error) (catch :default _ nil))]
(common/json-response
{:error "agents dispatch error"
:debug-type err-type
:debug-message message
:debug-data (when data (pr-str data))
:debug-json json-str
:debug-stack stack}
:debug-message (or message (str error))
:debug-data (when data (pr-str data))}
500))))))

View File

@@ -61,18 +61,36 @@
:repo-url repo-url}
(string? base-branch) (assoc :base-branch base-branch))))))
(defn- block-line-content
[block]
(blank->nil (:block/title block)))
(defn- block-tree->lines
([block]
(block-tree->lines block 0))
([block depth]
(let [indent (apply str (repeat (max 0 depth) " "))
content (block-line-content block)
children (:block/_parent block)
own-line (when (string? content)
[(str indent "- " content)])
child-lines (mapcat #(block-tree->lines % (inc depth)) children)]
(into (or own-line [])
child-lines))))
(defn- task-content
[block]
(let [lines (block-tree->lines block)]
(some->> lines seq (string/join "\n"))))
(defn- task-context
([block]
(task-context block nil))
([block opts]
(let [block-uuid (:block/uuid block)
node-id (some-> block-uuid str)
node-title (or (blank->nil (:block/raw-title block))
(blank->nil (:block/title block))
"")
content (or (blank->nil (:block/raw-title block))
(blank->nil (:block/title block))
"")
node-title (blank->nil (:block/title block))
content (task-content block)
project-page (:logseq.property/project block)
agent-page (:logseq.property/agent block)
project (when project-page (project-config project-page opts))