ProcessExtractionResult is ProcessExtraction with a summary of what changed.
(response string)
| 476 | |
| 477 | // ProcessExtractionResult is ProcessExtraction with a summary of what changed. |
| 478 | func (m *Manager) ProcessExtractionResult(response string) ExtractionSummary { |
| 479 | daily, longTerm, profileUpdates, topics, projects := parseEnhancedResponse(response) |
| 480 | |
| 481 | var sum ExtractionSummary |
| 482 | |
| 483 | if daily != "" { |
| 484 | if err := m.Daily.WriteDailyNote(daily); err != nil { |
| 485 | m.logger.Warn("failed to write daily note", zap.Error(err)) |
| 486 | } else { |
| 487 | sum.DailyWritten = true |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | if longTerm != "" { |
| 492 | if n, _ := m.appendLongTermCounted(longTerm); n > 0 { |
| 493 | sum.FactsAdded = n |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | if len(profileUpdates) > 0 { |
| 498 | // Background extraction is an inference, not the user's own words — |
| 499 | // recorded as such so freshness/trust can tell them apart. |
| 500 | if m.Profile.UpdateWithSource(profileUpdates, FieldSourceExtraction) { |
| 501 | sum.ProfileUpdated = true |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | if len(topics) > 0 { |
| 506 | m.Topics.RecordWithSummary(topics) |
| 507 | sum.TopicsRecorded = len(topics) |
| 508 | } |
| 509 | |
| 510 | if len(projects) > 0 { |
| 511 | if m.Projects.Upsert(projects) { |
| 512 | sum.ProjectsUpserted = 1 |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return sum |
| 517 | } |
| 518 | |
| 519 | // RecordInteraction records a usage event. |
| 520 | func (m *Manager) RecordInteraction(event InteractionEvent) { |