feat(kbdb_upsert_block): add create_only flag (#2 stub support)
leo 反饋 2026-05-17:「至少建一個 placeholder 給未來累積」 但 upsert 預設 PATCH 既有會把完整 wiki 覆寫成 stub。 新 input field:create_only (bool, default false) - false (預設):既有 → PATCH (傳統 upsert 行為) - true:既有 → return action='exists' 不動,避免 stub 覆寫 full wiki 用於 wiki_synthesis V3.1 referenced_entities → ensure_stub_wiki_page 場景。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,8 @@ type Input struct {
|
|||||||
UserID string `json:"user_id"` // optional(建立時用 + lookup filter)
|
UserID string `json:"user_id"` // optional(建立時用 + lookup filter)
|
||||||
Source string `json:"source"` // optional
|
Source string `json:"source"` // optional
|
||||||
TagsJSON string `json:"tags_json"` // optional(完整覆寫)
|
TagsJSON string `json:"tags_json"` // optional(完整覆寫)
|
||||||
|
CreateOnly bool `json:"create_only"` // 2026-05-17 加:若 true + 已存在 → 不 PATCH,回 action="exists"
|
||||||
|
// 用於 stub creation 場景(避免 stub 覆寫已存在的 full wiki)
|
||||||
}
|
}
|
||||||
|
|
||||||
var dummy [1]byte
|
var dummy [1]byte
|
||||||
@@ -181,6 +183,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if existing != nil {
|
if existing != nil {
|
||||||
|
// CreateOnly 模式:已存在 → 不動,回 action="exists"(給 stub creation 用,
|
||||||
|
// 避免後續 raw 提到同 entity 時把完整 wiki 覆寫成 stub)
|
||||||
|
if input.CreateOnly {
|
||||||
|
writeResult("exists", existing)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// PATCH 路徑
|
// PATCH 路徑
|
||||||
existingID, _ := existing["id"].(string)
|
existingID, _ := existing["id"].(string)
|
||||||
if existingID == "" {
|
if existingID == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user