MCPcopy Create free account
hub / github.com/compozy/agh / insertMemoryEventTx

Function insertMemoryEventTx

internal/memory/catalog.go:1579–1609  ·  view source on GitHub ↗
(ctx context.Context, tx *sql.Tx, record memcontract.OperationRecord, legacy bool)

Source from the content-addressed store, hash-verified

1577}
1578
1579func insertMemoryEventTx(ctx context.Context, tx *sql.Tx, record memcontract.OperationRecord, legacy bool) error {
1580 metadata := eventMetadata(record)
1581 if legacy {
1582 metadata[memoryEventMetadataLegacyIDKey] = strings.TrimSpace(record.ID)
1583 }
1584 payload, err := json.Marshal(metadata)
1585 if err != nil {
1586 return fmt.Errorf("memory: encode memory event metadata: %w", err)
1587 }
1588 if _, err := tx.ExecContext(
1589 ctx,
1590 `INSERT INTO memory_events (
1591 op, scope, agent_name, agent_tier, workspace_id, session_id, actor_kind,
1592 decision_id, target_id, metadata, ts_ms
1593 ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1594 canonicalEventOp(record),
1595 nullStringForEmpty(record.Scope.Normalize()),
1596 nullStringForEmpty(record.AgentName),
1597 nil,
1598 nullStringForEmpty(record.Workspace),
1599 nil,
1600 "system",
1601 nil,
1602 nullStringForEmpty(record.Filename),
1603 string(payload),
1604 timeToUnixMillis(record.Timestamp),
1605 ); err != nil {
1606 return fmt.Errorf("memory: migrate memory event: %w", err)
1607 }
1608 return nil
1609}
1610
1611func (c *catalog) listOperations(
1612 ctx context.Context,

Callers 1

Calls 6

eventMetadataFunction · 0.85
canonicalEventOpFunction · 0.85
nullStringForEmptyFunction · 0.85
timeToUnixMillisFunction · 0.85
ExecContextMethod · 0.65
NormalizeMethod · 0.45

Tested by

no test coverage detected