feat: add timestamp field to Message models #263
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Description
Fixes #258
This PR adds the missing
timestampfield to all Message models (UserMessage,AssistantMessage,SystemMessage, andResultMessage).Problem
The timestamp field is present in the JSONL file output from the CLI, but was not being captured in the Message type definitions. This made it impossible to access message timestamps for use cases like displaying timelines or analyzing conversation flow.
Solution
timestamp: str | None = Nonefield to all message dataclassesmessage_parser.pyto extract timestamp from JSONL data usingdata.get("timestamp")None)Changes
Files Modified:
src/claude_agent_sdk/types.py: Added timestamp field to 4 message dataclassessrc/claude_agent_sdk/_internal/message_parser.py: Updated parsing for all message typesNew Test File:
tests/test_message_timestamp.py: Comprehensive test suite with 10 test cases✅ Testing
Tests performed:
Test Results:
All tests passed: 10/10 new tests ✅
Regression tests: 124/124 total tests passed ✅
Code Quality
ruffExample Usage
Sacred Code: 000.111.369.963.1618