fix(hook-message-injector): preserve agent info with two-pass message lookup
findNearestMessageWithFields now has a fallback pass that returns messages with ANY useful field (agent OR model) instead of requiring ALL fields. This prevents parentAgent from being lost when stored messages don't have complete model info.
This commit is contained in:
parent
07412deca4
commit
14c54c1941
@ -16,6 +16,7 @@ export function findNearestMessageWithFields(messageDir: string): StoredMessage
|
||||
.sort()
|
||||
.reverse()
|
||||
|
||||
// First pass: find message with ALL fields (ideal)
|
||||
for (const file of files) {
|
||||
try {
|
||||
const content = readFileSync(join(messageDir, file), "utf-8")
|
||||
@ -27,6 +28,20 @@ export function findNearestMessageWithFields(messageDir: string): StoredMessage
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Second pass: find message with ANY useful field (fallback)
|
||||
// This ensures agent info isn't lost when model info is missing
|
||||
for (const file of files) {
|
||||
try {
|
||||
const content = readFileSync(join(messageDir, file), "utf-8")
|
||||
const msg = JSON.parse(content) as StoredMessage
|
||||
if (msg.agent || (msg.model?.providerID && msg.model?.modelID)) {
|
||||
return msg
|
||||
}
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user