Commit 9d63384
Phase D + E: lifecycle polymorphic union + datetime timestamps
Mirrors PR #1357 Phases D + E (TypeScript SDK API review).
Phase D — Session lifecycle event polymorphic hierarchy:
* Split the flat `SessionLifecycleEvent` dataclass into a `SessionLifecycleEventBase`
+ five concrete variant dataclasses (`SessionCreatedEvent`,
`SessionDeletedEvent`, `SessionUpdatedEvent`, `SessionForegroundEvent`,
`SessionBackgroundEvent`). `SessionLifecycleEvent` is now a `Union` type alias
over the five variants; pattern-match on the variant class to branch on the
event kind. Each variant exposes `type: ClassVar[Literal["..."]]`, so
existing `event.type == "session.created"` consumer code continues to work.
* `SessionLifecycleEvent.from_dict` becomes a module-private
`_session_lifecycle_event_from_dict` factory that switches on the wire
`type` and constructs the matching variant.
Phase D / E — Timestamps as `datetime`:
* `SessionMetadata.startTime` / `modifiedTime` now `datetime` (previously
ISO-8601 `str`). `to_dict` round-trips back to ISO strings.
* `SessionLifecycleEventMetadata.startTime` / `modifiedTime` likewise.
* All `Pre/PostToolUseHookInput`, `PreMcpToolCallHookInput`,
`UserPromptSubmittedHookInput`, `SessionStartHookInput`,
`SessionEndHookInput`, `ErrorOccurredHookInput` declare
`timestamp: datetime`. `CopilotSession._handle_hooks_invoke` converts the
wire epoch-milliseconds integer into a timezone-aware `datetime` at the
dispatch boundary (same place the existing `cwd → workingDirectory` remap
lives).
Tests updated in lock-step: `test_session_e2e.py` asserts the new `datetime`
types on `SessionMetadata`.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 0ea0bc7 commit 9d63384
3 files changed
Lines changed: 123 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
812 | 812 | | |
813 | 813 | | |
814 | 814 | | |
815 | | - | |
816 | | - | |
| 815 | + | |
| 816 | + | |
817 | 817 | | |
818 | 818 | | |
819 | 819 | | |
| |||
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
838 | | - | |
839 | | - | |
| 838 | + | |
| 839 | + | |
840 | 840 | | |
841 | 841 | | |
842 | 842 | | |
| |||
845 | 845 | | |
846 | 846 | | |
847 | 847 | | |
848 | | - | |
849 | | - | |
| 848 | + | |
| 849 | + | |
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
| |||
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
858 | 870 | | |
859 | 871 | | |
860 | 872 | | |
| |||
872 | 884 | | |
873 | 885 | | |
874 | 886 | | |
875 | | - | |
876 | | - | |
| 887 | + | |
| 888 | + | |
877 | 889 | | |
878 | 890 | | |
879 | 891 | | |
880 | 892 | | |
881 | 893 | | |
882 | | - | |
883 | | - | |
| 894 | + | |
| 895 | + | |
884 | 896 | | |
885 | 897 | | |
886 | 898 | | |
887 | 899 | | |
888 | 900 | | |
889 | | - | |
890 | | - | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
891 | 908 | | |
892 | | - | |
893 | 909 | | |
894 | 910 | | |
895 | 911 | | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
906 | 976 | | |
907 | 977 | | |
908 | 978 | | |
| |||
2922 | 2992 | | |
2923 | 2993 | | |
2924 | 2994 | | |
2925 | | - | |
| 2995 | + | |
2926 | 2996 | | |
2927 | 2997 | | |
2928 | 2998 | | |
| |||
3047 | 3117 | | |
3048 | 3118 | | |
3049 | 3119 | | |
3050 | | - | |
| 3120 | + | |
3051 | 3121 | | |
3052 | 3122 | | |
3053 | 3123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
627 | 628 | | |
628 | 629 | | |
629 | 630 | | |
630 | | - | |
| 631 | + | |
631 | 632 | | |
632 | 633 | | |
633 | 634 | | |
| |||
653 | 654 | | |
654 | 655 | | |
655 | 656 | | |
656 | | - | |
| 657 | + | |
657 | 658 | | |
658 | 659 | | |
659 | 660 | | |
| |||
684 | 685 | | |
685 | 686 | | |
686 | 687 | | |
687 | | - | |
| 688 | + | |
688 | 689 | | |
689 | 690 | | |
690 | 691 | | |
| |||
709 | 710 | | |
710 | 711 | | |
711 | 712 | | |
712 | | - | |
| 713 | + | |
713 | 714 | | |
714 | 715 | | |
715 | 716 | | |
| |||
732 | 733 | | |
733 | 734 | | |
734 | 735 | | |
735 | | - | |
| 736 | + | |
736 | 737 | | |
737 | 738 | | |
738 | 739 | | |
| |||
755 | 756 | | |
756 | 757 | | |
757 | 758 | | |
758 | | - | |
| 759 | + | |
759 | 760 | | |
760 | 761 | | |
761 | 762 | | |
| |||
780 | 781 | | |
781 | 782 | | |
782 | 783 | | |
783 | | - | |
| 784 | + | |
784 | 785 | | |
785 | 786 | | |
786 | 787 | | |
| |||
2229 | 2230 | | |
2230 | 2231 | | |
2231 | 2232 | | |
2232 | | - | |
2233 | | - | |
2234 | | - | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
2235 | 2245 | | |
2236 | 2246 | | |
2237 | 2247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
309 | | - | |
310 | | - | |
| 310 | + | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| |||
365 | 366 | | |
366 | 367 | | |
367 | 368 | | |
368 | | - | |
369 | | - | |
| 369 | + | |
| 370 | + | |
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
| |||
854 | 855 | | |
855 | 856 | | |
856 | 857 | | |
857 | | - | |
858 | | - | |
| 858 | + | |
| 859 | + | |
859 | 860 | | |
860 | 861 | | |
861 | 862 | | |
| |||
0 commit comments