37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
package domain
|
|
|
|
import "git.cin.su/m/Assistant/contracts/interaction"
|
|
|
|
type ContextProjection struct {
|
|
Text string
|
|
Source string
|
|
UsedPersonalMemoryFallback bool
|
|
}
|
|
|
|
// BuildGen2Context is a read-side projection over canonical utterance history.
|
|
// PersonalMemory remains a compatibility fallback and is never written here.
|
|
func BuildGen2Context(history []interaction.HumanUtterance) ContextProjection {
|
|
return BuildScopedGen2Context(history, "")
|
|
}
|
|
|
|
// BuildScopedGen2Context is the Gen2 retrieval boundary for household
|
|
// context. The caller supplies already-authorized history; this defensive
|
|
// filter prevents accidental cross-principal projection when a mixed source
|
|
// is passed during degraded operation.
|
|
func BuildScopedGen2Context(history []interaction.HumanUtterance, principalID string) ContextProjection {
|
|
if principalID != "" {
|
|
scoped := make([]interaction.HumanUtterance, 0, len(history))
|
|
for _, item := range history {
|
|
if item.PrincipalID == "" || string(item.PrincipalID) == principalID {
|
|
scoped = append(scoped, item)
|
|
}
|
|
}
|
|
history = scoped
|
|
}
|
|
text := CompilePersonalMemory(history).ContextText()
|
|
if text != "" {
|
|
return ContextProjection{Text: text, Source: "retrieval:interaction-utterances"}
|
|
}
|
|
return ContextProjection{Text: text, Source: "personal-memory-v1-fallback", UsedPersonalMemoryFallback: true}
|
|
}
|