MCPcopy Create free account
hub / github.com/astercloud/aster / AppendEvent

Method AppendEvent

pkg/session/sqlite/store.go:275–328  ·  view source on GitHub ↗

AppendEvent adds an event to a session.

(ctx context.Context, sessionID string, event *session.Event)

Source from the content-addressed store, hash-verified

273
274// AppendEvent adds an event to a session.
275func (s *Service) AppendEvent(ctx context.Context, sessionID string, event *session.Event) error {
276 s.mu.Lock()
277 defer s.mu.Unlock()
278
279 // Check session exists
280 var exists bool
281 err := s.db.QueryRowContext(ctx, `SELECT 1 FROM sessions WHERE id = ?`, sessionID).Scan(&exists)
282 if errors.Is(err, sql.ErrNoRows) {
283 return session.ErrSessionNotFound
284 }
285 if err != nil {
286 return fmt.Errorf("check session: %w", err)
287 }
288
289 // Serialize fields
290 contentJSON, err := json.Marshal(event.Content)
291 if err != nil {
292 return fmt.Errorf("marshal content: %w", err)
293 }
294
295 actionsJSON, err := json.Marshal(event.Actions)
296 if err != nil {
297 return fmt.Errorf("marshal actions: %w", err)
298 }
299
300 toolIDsJSON, err := json.Marshal(event.LongRunningToolIDs)
301 if err != nil {
302 return fmt.Errorf("marshal tool ids: %w", err)
303 }
304
305 metadataJSON, err := json.Marshal(event.Metadata)
306 if err != nil {
307 return fmt.Errorf("marshal metadata: %w", err)
308 }
309
310 now := time.Now()
311 if event.ID == "" {
312 event.ID = uuid.New().String()
313 }
314
315 _, err = s.db.ExecContext(ctx,
316 `INSERT INTO events (id, session_id, invocation_id, agent_id, branch, author, content, reasoning, actions, long_running_tool_ids, metadata, created_at)
317 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
318 event.ID, sessionID, event.InvocationID, event.AgentID, event.Branch, event.Author,
319 string(contentJSON), event.Reasoning, string(actionsJSON), string(toolIDsJSON), string(metadataJSON), now,
320 )
321 if err != nil {
322 return fmt.Errorf("insert event: %w", err)
323 }
324
325 // Update session timestamp
326 _, err = s.db.ExecContext(ctx, `UPDATE sessions SET updated_at = ? WHERE id = ?`, now, sessionID)
327 return err
328}
329
330// GetEvents retrieves events for a session.
331func (s *Service) GetEvents(ctx context.Context, sessionID string, filter *session.EventFilter) ([]session.Event, error) {

Callers

nothing calls this directly

Implementers 2

InMemoryServicepkg/session/inmemory.go
Servicepkg/session/sqlite/store.go

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected