(ctx context.Context, startTurn, endTurn int)
| 334 | _, err := s.db.ExecContext(ctx, `INSERT OR IGNORE INTO schema_meta(key, value) VALUES('schema_version', ?)`, schemaVersion) |
| 335 | if err != nil { |
| 336 | return err |
| 337 | } |
| 338 | _, err = s.db.ExecContext(ctx, `INSERT INTO session_info(session_id, created_at, updated_at, cwd, model) |
| 339 | VALUES(?, ?, ?, ?, ?) |
| 340 | ON CONFLICT(session_id) DO UPDATE SET updated_at=excluded.updated_at, cwd=excluded.cwd, model=excluded.model`, |
| 341 | s.sessionID, now, now, s.cfg.CWD, s.cfg.APIModel) |
| 342 | return err |
| 343 | } |
| 344 | |
| 345 | func (s *Store) IngestMessages(ctx context.Context, messages []map[string]any) error { |
| 346 | tx, err := s.db.BeginTx(ctx, nil) |
| 347 | if err != nil { |
| 348 | return err |
| 349 | } |
| 350 | defer tx.Rollback() |
| 351 | userTurn := 0 |
| 352 | for _, msg := range messages { |
| 353 | if isTransientMessage(msg) || isCompactionHandoffMessage(msg) { |
| 354 | continue |
| 355 | } |
| 356 | if taggedTurn := sessionUserTurn(msg); taggedTurn > 0 { |
| 357 | userTurn = taggedTurn |
| 358 | } else if isRealUserRequest(msg) { |
| 359 | userTurn++ |
| 360 | } |
| 361 | if userTurn == 0 { |
| 362 | continue |
| 363 | } |
| 364 | role := stringValue(msg["role"]) |
| 365 | contentJSON, err := json.Marshal(msg["content"]) |
| 366 | if err != nil { |
| 367 | continue |
| 368 | } |
| 369 | hash := messageHash(userTurn, role, contentJSON) |
| 370 | preview := textPreview(msg, 1200) |
| 371 | now := unixNow() |
| 372 | if _, err := tx.ExecContext(ctx, `INSERT OR IGNORE INTO messages(turn_count, user_turn_count, role, content_json, text_preview, message_hash, created_at, last_accessed_at) |
| 373 | VALUES(?, ?, ?, ?, ?, ?, ?, ?)`, userTurn, userTurn, role, string(contentJSON), preview, hash, now, now); err != nil { |
| 374 | return err |
| 375 | } |
| 376 | } |
| 377 | return tx.Commit() |
| 378 | } |
| 379 | |
| 380 | func (s *Store) IngestEvents(ctx context.Context, events []harness.Event) error { |
| 381 | if len(events) == 0 { |
| 382 | return nil |
| 383 | } |
| 384 | userTurn := s.maxUserTurn(ctx) |
| 385 | tx, err := s.db.BeginTx(ctx, nil) |
| 386 | if err != nil { |
| 387 | return err |
| 388 | } |
| 389 | defer tx.Rollback() |
| 390 | for _, event := range events { |
| 391 | if event.Type != harness.EventMessageUserAppended && event.Type != harness.EventMessageAssistantAppended { |
| 392 | continue |
| 393 | } |
no test coverage detected