fix: ensure project repo url is loaded before showing chat

This commit is contained in:
Tienson Qin
2026-02-28 20:53:26 +08:00
parent 20c13b32cd
commit bf1a5e1768
2 changed files with 21 additions and 11 deletions

View File

@@ -2517,24 +2517,28 @@
(let [sessions (state/sub :agent/sessions)
session (get sessions (str (:block/uuid block)))
status (:status session)
ready? (agent-handler/task-ready? block)
runnable? (agent-handler/task-runnable? block)
running? (contains? #{"running" "paused"} status)
session-started? (boolean (:session-id session))
session-created? (or session-started?
(true? (pu/get-block-property-value block :logseq.property/agent-session-created?)))
btn-title (if ready?
btn-title (if runnable?
(if session-created? "Open chat" "Run agent")
"Set Project + Agent + Git Repo")]
"Set Project + Agent")]
[:div.flex.flex-row.items-center.gap-1
(shui/button
{:variant :ghost
:size :sm
:class "text-xs h-6 !px-2"
:title btn-title
:disabled (not ready?)
:disabled (not runnable?)
:on-click (fn [e]
(util/stop e)
(agent-chat/open-agent-chat-dialog! block))}
(p/do!
;; Ensure project is loaded
(db-async/<get-block (state/get-current-repo) (:db/id (:logseq.property/project block)))
(let [block' (db/entity (:db/id block))]
(agent-chat/open-agent-chat-dialog! block'))))}
(cond
running? "Running"
session-created? "Thread"

View File

@@ -103,19 +103,25 @@
:project project
:agent agent})))
(defn task-runnable?
[block]
(and (:logseq.property/project block)
(:logseq.property/agent block)))
(defn task-ready?
[block]
(let [{:keys [project agent node-id]} (task-context block)]
(let [{:keys [project agent node-id node-title content]} (task-context block)]
(and (string? node-id)
(string? node-title)
(string? content)
project
agent
(> (count (:block/title block)) 4))))
agent)))
(defn project-repo-url
[block]
(some-> (:logseq.property/project block)
(pu/get-block-property-value :logseq.property/git-repo)
blank->nil))
(some-> block
:logseq.property/project
(pu/get-block-property-value :logseq.property/git-repo)))
(defn- github-repo-ref
[repo-url]