Skip to content

desktop/src-tauri/crates/core/src/domain.rs

Comment 1, line 1

desktop/src-tauri/crates/core/src/domain.rs:1

//! Domain types: normalized records, tokens, lifecycle, model identity, time and source ownership.

Comment 2, line 2

desktop/src-tauri/crates/core/src/domain.rs:2

//! Field meanings follow docs/design/desktop-usage/data-contract.md.

Comment 3, line 7

desktop/src-tauri/crates/core/src/domain.rs:7

/// Maximum value for one token field (2^62). Reject larger values with an error;

Comment 4, line 8

desktop/src-tauri/crates/core/src/domain.rs:8

/// preserve integer precision and check aggregate additions for overflow.

Comment 5, line 11

desktop/src-tauri/crates/core/src/domain.rs:11

/// Reject timestamps before 2000-01-01T00:00:00Z to catch mistaken seconds/milliseconds.

Comment 6, line 14

desktop/src-tauri/crates/core/src/domain.rs:14

/// Field quality: reported means the source reports a value, without establishing the final bill.

Comment 7, line 47

desktop/src-tauri/crates/core/src/domain.rs:47

/// Record kinds; statistical behavior follows the data rules for requests, messages and cumulative values.

Comment 8, line 51

desktop/src-tauri/crates/core/src/domain.rs:51

/// One observed model call/attempt; the basic request-count unit.

Comment 9, line 53

desktop/src-tauri/crates/core/src/domain.rs:53

/// HTTP/WebSocket reconnect or retry; count separately without increasing model_call directly.

Comment 10, line 55

desktop/src-tauri/crates/core/src/domain.rs:55

/// A usage observation; its relationship to calls may be one-to-many or many-to-one.

Comment 11, line 57

desktop/src-tauri/crates/core/src/domain.rs:57

/// Session/process cumulative snapshot; take differences by identity/reset boundaries rather than sum rows.

Comment 12, line 59

desktop/src-tauri/crates/core/src/domain.rs:59

/// Native day/session or other aggregate, retaining its original scope.

Comment 13, line 61

desktop/src-tauri/crates/core/src/domain.rs:61

/// Quota, credits, subscription window or balance, displayed separately.

Comment 14, line 92

desktop/src-tauri/crates/core/src/domain.rs:92

/// Streaming partial values, final values or corrections.

Comment 15, line 120

desktop/src-tauri/crates/core/src/domain.rs:120

/// Primary, subagent, auxiliary or unknown call category.

Comment 16, line 153

desktop/src-tauri/crates/core/src/domain.rs:153

/// Model attribution; keep unknown without structured information available by the call time.

Comment 17, line 157

desktop/src-tauri/crates/core/src/domain.rs:157

/// Model field on the request itself.

Comment 18, line 159

desktop/src-tauri/crates/core/src/domain.rs:159

/// Structured model change/turn context available by the call time.

Comment 19, line 161

desktop/src-tauri/crates/core/src/domain.rs:161

/// Source mapping, such as turn_context ownership.

Comment 20, line 189

desktop/src-tauri/crates/core/src/domain.rs:189

/// Time basis: assign midnight-crossing calls by native completion; identify start-only timestamps.

Comment 21, line 197

desktop/src-tauri/crates/core/src/domain.rs:197

/// Native timezone/time configuration has not been verified.

Comment 22, line 226

desktop/src-tauri/crates/core/src/domain.rs:226

/// Version selection follows architecture.md compatibility rules:

Comment 23, line 227

desktop/src-tauri/crates/core/src/domain.rs:227

/// dispatch known versions through the registry; unknown/missing versions try the latest built-in reader

Comment 24, line 228

desktop/src-tauri/crates/core/src/domain.rs:228

/// for that Agent. Record compatibility separately from token-field quality.

Comment 25, line 255

desktop/src-tauri/crates/core/src/domain.rs:255

/// Basis for identifying this device as the source.

Comment 26, line 294

desktop/src-tauri/crates/core/src/domain.rs:294

/// Ownership verification; records with unverified ownership do not enter totals.

Comment 27, line 324

desktop/src-tauri/crates/core/src/domain.rs:324

/// Token fields; missing values are None (stored as NULL), without replacement zeros.

Comment 28, line 334

desktop/src-tauri/crates/core/src/domain.rs:334

/// Original source total, compared with normalized totals; disagreements produce diagnostics.

Comment 29, line 339

desktop/src-tauri/crates/core/src/domain.rs:339

/// Validate every field as nonnegative and within the limit; reject an out-of-range record.

Comment 30, line 369

desktop/src-tauri/crates/core/src/domain.rs:369

/// Per-field quality matching TokenUsage; unknown fields must have no value.

Comment 31, line 445

desktop/src-tauri/crates/core/src/domain.rs:445

/// Event quality category, used when grouping daily aggregates.

Comment 32, line 449

desktop/src-tauri/crates/core/src/domain.rs:449

/// Both input and output totals are known.

Comment 33, line 451

desktop/src-tauri/crates/core/src/domain.rs:451

/// Some token fields are known.

Comment 34, line 453

desktop/src-tauri/crates/core/src/domain.rs:453

/// At least one field is estimated.

Comment 35, line 455

desktop/src-tauri/crates/core/src/domain.rs:455

/// No token field is known.

Comment 36, line 507

desktop/src-tauri/crates/core/src/domain.rs:507

/// Cost in integer smallest units with a currency; avoid floating-point accumulation.

Comment 37, line 533

desktop/src-tauri/crates/core/src/domain.rs:533

/// Normalized ingest event: model_call, transport_attempt or usage_observation.

Comment 38, line 537

desktop/src-tauri/crates/core/src/domain.rs:537

/// Stable native key: response/request ID, session UUID plus sequence, or file identity plus position.

Comment 39, line 542

desktop/src-tauri/crates/core/src/domain.rs:542

/// Reader selection: known_version/latest_fallback; None identifies undifferentiated historical data.

Comment 40, line 543

desktop/src-tauri/crates/core/src/domain.rs:543

/// Compatibility describes parsing, rather than event content, and is excluded from the content hash.

Comment 41, line 552

desktop/src-tauri/crates/core/src/domain.rs:552

/// Integer UTC milliseconds.

Comment 42, line 566

desktop/src-tauri/crates/core/src/domain.rs:566

/// Prefer source revision ordering when available; otherwise resolve by lifecycle.

Comment 43, line 577

desktop/src-tauri/crates/core/src/domain.rs:577

/// Before storage, validate bounded nonnegative tokens and plausible millisecond timestamps.