Skip to content

Commit 118c22d

Browse files
committed
fix: handle null content in relation-type search results
BM CLI returns relation-type results with no content field. Plugin crashed on r.content.length when content was undefined. Added null coalescing (r.content ?? "") in search.ts and memory-provider.ts.
1 parent 70bf207 commit 118c22d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tools/memory-provider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async function searchActiveTasks(
8181
for (const r of results) {
8282
const score = r.score ? ` (${r.score.toFixed(2)})` : ""
8383
const preview =
84-
r.content.length > 200 ? `${r.content.slice(0, 200)}…` : r.content
84+
(r.content ?? "").length > 200 ? `${(r.content ?? "").slice(0, 200)}…` : (r.content ?? "")
8585
matches.push(
8686
`- **${r.title}**${score}${r.file_path}\n > ${preview.replace(/\n/g, "\n > ")}`,
8787
)
@@ -195,9 +195,9 @@ export function registerMemoryProvider(
195195
.map((r) => {
196196
const score = r.score ? ` (${r.score.toFixed(2)})` : ""
197197
const preview =
198-
r.content.length > 200
199-
? `${r.content.slice(0, 200)}…`
200-
: r.content
198+
(r.content ?? "").length > 200
199+
? `${(r.content ?? "").slice(0, 200)}…`
200+
: (r.content ?? "")
201201
const source = r.file_path || r.permalink
202202
return `- ${source}${score}\n > ${preview.replace(/\n/g, "\n > ")}`
203203
})

tools/search.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ export function registerSearchTool(
4444
const text = results
4545
.map((r, i) => {
4646
const score = r.score ? ` (${(r.score * 100).toFixed(0)}%)` : ""
47+
const content = r.content ?? ""
4748
const preview =
48-
r.content.length > 200
49-
? `${r.content.slice(0, 200)}...`
50-
: r.content
49+
content.length > 200
50+
? `${content.slice(0, 200)}...`
51+
: content
5152
return `${i + 1}. **${r.title}**${score}\n ${preview}`
5253
})
5354
.join("\n\n")

0 commit comments

Comments
 (0)