Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
465a90b25d | ||
|
|
95d6ad2d6a | ||
|
|
1e554f6758 | ||
|
|
1c7d512710 | ||
|
|
8c6a7bebbd | ||
|
|
36774b37ae |
@@ -214,7 +214,7 @@ func (r *ContinuityRepository) AttentionByOwner(ctx context.Context, owner ident
|
||||
}
|
||||
|
||||
func (r *ContinuityRepository) ResponseCandidates(ctx context.Context, owner identity.PrincipalID, limit int) ([]continuitydomain.ResponseCandidate, error) {
|
||||
if owner == "" || limit < 1 || limit > 10 {
|
||||
if owner == "" || limit < 1 || limit > 50 {
|
||||
return nil, fmt.Errorf("invalid response candidate query")
|
||||
}
|
||||
rows, err := r.pool.Query(ctx, `SELECT
|
||||
@@ -227,7 +227,7 @@ func (r *ContinuityRepository) ResponseCandidates(ctx context.Context, owner ide
|
||||
WHERE p.owner_principal_id=$1
|
||||
AND (a.attention_item_id IS NULL OR a.state IN ($3,$4,$5))
|
||||
AND p.state IN ($6,$7)
|
||||
ORDER BY COALESCE(a.delivered_at_unix_millis,0) DESC, p.trigger_at_unix_millis DESC, p.prospective_item_id DESC
|
||||
ORDER BY p.recorded_at DESC, COALESCE(a.delivered_at_unix_millis,0) DESC, p.prospective_item_id DESC
|
||||
LIMIT $8`,
|
||||
owner, continuity.AttentionSourceProspectiveReminder, continuity.AttentionDelivered, continuity.AttentionPending,
|
||||
continuity.AttentionFailed, continuity.ProspectiveDelivered, continuity.ProspectiveArmed, limit)
|
||||
|
||||
@@ -42,7 +42,7 @@ func registerCreatorResponseRoute(mux *http.ServeMux, identityClient creatorIden
|
||||
http.Error(w, "human response unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
candidates, err := repository.ResponseCandidates(r.Context(), session.PrincipalID, 3)
|
||||
candidates, err := repository.ResponseCandidates(r.Context(), session.PrincipalID, 20)
|
||||
if err != nil {
|
||||
http.Error(w, "response candidates unavailable", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -153,6 +153,9 @@ func candidateSummary(candidates []ResponseCandidate) string {
|
||||
parts := make([]string, 0, len(candidates))
|
||||
for _, candidate := range candidates {
|
||||
text := strings.TrimSpace(candidate.Attention.Summary)
|
||||
if text == "" {
|
||||
text = strings.TrimSpace(candidate.Prospective.Summary)
|
||||
}
|
||||
if text == "" {
|
||||
text = "ожидание"
|
||||
}
|
||||
@@ -168,7 +171,11 @@ func matchingCandidates(message string, candidates []ResponseCandidate) []Respon
|
||||
lower := strings.ToLower(message)
|
||||
var matched []ResponseCandidate
|
||||
for _, candidate := range candidates {
|
||||
if summaryMatches(lower, candidate.Attention.Summary) {
|
||||
summary := candidate.Attention.Summary
|
||||
if summary == "" {
|
||||
summary = candidate.Prospective.Summary
|
||||
}
|
||||
if summaryMatches(lower, summary) {
|
||||
matched = append(matched, candidate)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,29 @@ func TestInterpretHumanResponseCancelsArmedProspectiveBeforeAttention(t *testing
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterpretHumanResponseResolvesArmedProspectiveByNaturalSummaryReference(t *testing.T) {
|
||||
result := interpretResponseForTest(t, "Отмени встретить курьера", []ResponseCandidate{
|
||||
{Prospective: continuity.ProspectiveItem{ID: "p1", OwnerPrincipalID: "principal-1", ScopeID: "scope-1", Summary: "позвонить врачу", State: continuity.ProspectiveArmed, Revision: 1}},
|
||||
{Prospective: continuity.ProspectiveItem{ID: "p2", OwnerPrincipalID: "principal-1", ScopeID: "scope-1", Summary: "встретить курьера", State: continuity.ProspectiveArmed, Revision: 1}},
|
||||
})
|
||||
if !result.Handled || result.Response.TargetKind != continuity.ResponseTargetProspectiveItem || result.Response.TargetProspectiveID != "p2" || result.Response.Outcome != continuity.ResponseOutcomeCancelled {
|
||||
t.Fatalf("unexpected prospective natural target response: %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterpretHumanResponseResolvesSummaryReferenceBeyondFirstThreeCandidates(t *testing.T) {
|
||||
candidates := []ResponseCandidate{
|
||||
responseCandidate("a1", "p1", "первое ожидание"),
|
||||
responseCandidate("a2", "p2", "второе ожидание"),
|
||||
responseCandidate("a3", "p3", "третье ожидание"),
|
||||
{Prospective: continuity.ProspectiveItem{ID: "p4", OwnerPrincipalID: "principal-1", ScopeID: "scope-1", Summary: "встретить курьера", State: continuity.ProspectiveArmed, Revision: 1}},
|
||||
}
|
||||
result := interpretResponseForTest(t, "Отмени встретить курьера", candidates)
|
||||
if !result.Handled || result.Response.ResolutionState != continuity.ResponseResolved || result.Response.TargetProspectiveID != "p4" {
|
||||
t.Fatalf("expected target resolution beyond first three candidates, got %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterpretHumanResponseAmbiguousTargetAsksClarificationWithoutResolvedMutation(t *testing.T) {
|
||||
result := interpretResponseForTest(t, "Готово", []ResponseCandidate{responseCandidate("a1", "p1", "первое"), responseCandidate("a2", "p2", "второе")})
|
||||
if !result.Handled || result.Response.ResolutionState != continuity.ResponseAmbiguous || result.Response.Outcome != continuity.ResponseOutcomeClarificationNeeded || !strings.Contains(result.Reply, "несколько") {
|
||||
|
||||
Reference in New Issue
Block a user