-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathsession_events.py
More file actions
9265 lines (8104 loc) · 371 KB
/
Copy pathsession_events.py
File metadata and controls
9265 lines (8104 loc) · 371 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
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
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
AUTO-GENERATED FILE - DO NOT EDIT
Generated from: session-events.schema.json
"""
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime, timedelta
from enum import Enum
from typing import Any, ClassVar, TypeVar, cast
from uuid import UUID
import dateutil.parser
T = TypeVar("T")
EnumT = TypeVar("EnumT", bound=Enum)
def from_str(x: Any) -> str:
assert isinstance(x, str)
return x
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def to_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_float(x: Any) -> float:
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return float(x)
def to_float(x: Any) -> float:
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return float(x)
def from_timedelta(x: Any) -> timedelta:
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return timedelta(milliseconds=float(x))
def to_timedelta_int(x: timedelta) -> int:
assert isinstance(x, timedelta)
milliseconds = x.total_seconds() * 1000.0
# Durations can carry sub-millisecond precision; round to the nearest whole ms
# using Python's default banker's rounding (round-half-to-even).
return round(milliseconds)
def to_timedelta(x: timedelta) -> float:
assert isinstance(x, timedelta)
return x.total_seconds() * 1000.0
def from_bool(x: Any) -> bool:
assert isinstance(x, bool)
return x
def from_none(x: Any) -> Any:
assert x is None
return x
def from_union(fs: list[Callable[[Any], T]], x: Any) -> T:
for f in fs:
try:
return f(x)
except Exception:
pass
assert False
def from_list(f: Callable[[Any], T], x: Any) -> list[T]:
assert isinstance(x, list)
return [f(item) for item in x]
def from_dict(f: Callable[[Any], T], x: Any) -> dict[str, T]:
assert isinstance(x, dict)
return {key: f(value) for key, value in x.items()}
def from_datetime(x: Any) -> datetime:
return dateutil.parser.parse(from_str(x))
def to_datetime(x: datetime) -> str:
return x.isoformat()
def from_uuid(x: Any) -> UUID:
return UUID(from_str(x))
def to_uuid(x: UUID) -> str:
return str(x)
def parse_enum(c: type[EnumT], x: Any) -> EnumT:
assert isinstance(x, str)
return c(x)
def to_class(c: type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
def to_enum(c: type[EnumT], x: Any) -> str:
assert isinstance(x, c)
return cast(str, x.value)
class SessionEventType(Enum):
SESSION_START = "session.start"
SESSION_RESUME = "session.resume"
SESSION_REMOTE_STEERABLE_CHANGED = "session.remote_steerable_changed"
SESSION_ERROR = "session.error"
SESSION_IDLE = "session.idle"
SESSION_TITLE_CHANGED = "session.title_changed"
SESSION_SCHEDULE_CREATED = "session.schedule_created"
SESSION_SCHEDULE_CANCELLED = "session.schedule_cancelled"
SESSION_SCHEDULE_REARMED = "session.schedule_rearmed"
SESSION_AUTOPILOT_OBJECTIVE_CHANGED = "session.autopilot_objective_changed"
SESSION_INFO = "session.info"
SESSION_WARNING = "session.warning"
SESSION_MODEL_CHANGE = "session.model_change"
SESSION_MODE_CHANGED = "session.mode_changed"
SESSION_RESPONSE_LIMITS_CHANGED = "session.response_limits_changed"
SESSION_PERMISSIONS_CHANGED = "session.permissions_changed"
SESSION_PLAN_CHANGED = "session.plan_changed"
SESSION_TODOS_CHANGED = "session.todos_changed"
SESSION_WORKSPACE_FILE_CHANGED = "session.workspace_file_changed"
SESSION_HANDOFF = "session.handoff"
SESSION_TRUNCATION = "session.truncation"
SESSION_SNAPSHOT_REWIND = "session.snapshot_rewind"
SESSION_SHUTDOWN = "session.shutdown"
SESSION_CONTEXT_CHANGED = "session.context_changed"
SESSION_USAGE_INFO = "session.usage_info"
SESSION_COMPACTION_START = "session.compaction_start"
SESSION_COMPACTION_COMPLETE = "session.compaction_complete"
SESSION_TASK_COMPLETE = "session.task_complete"
USER_MESSAGE = "user.message"
PENDING_MESSAGES_MODIFIED = "pending_messages.modified"
ASSISTANT_TURN_START = "assistant.turn_start"
ASSISTANT_INTENT = "assistant.intent"
ASSISTANT_REASONING = "assistant.reasoning"
ASSISTANT_REASONING_DELTA = "assistant.reasoning_delta"
ASSISTANT_STREAMING_DELTA = "assistant.streaming_delta"
ASSISTANT_MESSAGE = "assistant.message"
ASSISTANT_MESSAGE_START = "assistant.message_start"
ASSISTANT_MESSAGE_DELTA = "assistant.message_delta"
ASSISTANT_TURN_END = "assistant.turn_end"
ASSISTANT_IDLE = "assistant.idle"
ASSISTANT_USAGE = "assistant.usage"
MODEL_CALL_FAILURE = "model.call_failure"
ABORT = "abort"
TOOL_USER_REQUESTED = "tool.user_requested"
TOOL_EXECUTION_START = "tool.execution_start"
TOOL_EXECUTION_PARTIAL_RESULT = "tool.execution_partial_result"
TOOL_EXECUTION_PROGRESS = "tool.execution_progress"
TOOL_EXECUTION_COMPLETE = "tool.execution_complete"
SKILL_INVOKED = "skill.invoked"
SUBAGENT_STARTED = "subagent.started"
SUBAGENT_COMPLETED = "subagent.completed"
SUBAGENT_FAILED = "subagent.failed"
SUBAGENT_SELECTED = "subagent.selected"
SUBAGENT_DESELECTED = "subagent.deselected"
HOOK_START = "hook.start"
HOOK_END = "hook.end"
HOOK_PROGRESS = "hook.progress"
# Experimental: this event is part of an experimental API and may change or be removed.
SESSION_BINARY_ASSET = "session.binary_asset"
SYSTEM_MESSAGE = "system.message"
SYSTEM_NOTIFICATION = "system.notification"
PERMISSION_REQUESTED = "permission.requested"
PERMISSION_COMPLETED = "permission.completed"
USER_INPUT_REQUESTED = "user_input.requested"
USER_INPUT_COMPLETED = "user_input.completed"
ELICITATION_REQUESTED = "elicitation.requested"
ELICITATION_COMPLETED = "elicitation.completed"
SAMPLING_REQUESTED = "sampling.requested"
SAMPLING_COMPLETED = "sampling.completed"
MCP_OAUTH_REQUIRED = "mcp.oauth_required"
MCP_OAUTH_COMPLETED = "mcp.oauth_completed"
MCP_HEADERS_REFRESH_REQUIRED = "mcp.headers_refresh_required"
MCP_HEADERS_REFRESH_COMPLETED = "mcp.headers_refresh_completed"
SESSION_CUSTOM_NOTIFICATION = "session.custom_notification"
EXTERNAL_TOOL_REQUESTED = "external_tool.requested"
EXTERNAL_TOOL_COMPLETED = "external_tool.completed"
COMMAND_QUEUED = "command.queued"
COMMAND_EXECUTE = "command.execute"
COMMAND_COMPLETED = "command.completed"
AUTO_MODE_SWITCH_REQUESTED = "auto_mode_switch.requested"
AUTO_MODE_SWITCH_COMPLETED = "auto_mode_switch.completed"
COMMANDS_CHANGED = "commands.changed"
CAPABILITIES_CHANGED = "capabilities.changed"
EXIT_PLAN_MODE_REQUESTED = "exit_plan_mode.requested"
EXIT_PLAN_MODE_COMPLETED = "exit_plan_mode.completed"
SESSION_TOOLS_UPDATED = "session.tools_updated"
SESSION_BACKGROUND_TASKS_CHANGED = "session.background_tasks_changed"
SESSION_SKILLS_LOADED = "session.skills_loaded"
SESSION_CUSTOM_AGENTS_UPDATED = "session.custom_agents_updated"
SESSION_MCP_SERVERS_LOADED = "session.mcp_servers_loaded"
SESSION_MCP_SERVER_STATUS_CHANGED = "session.mcp_server_status_changed"
SESSION_EXTENSIONS_LOADED = "session.extensions_loaded"
# Experimental: this event is part of an experimental API and may change or be removed.
SESSION_CANVAS_OPENED = "session.canvas.opened"
# Experimental: this event is part of an experimental API and may change or be removed.
SESSION_CANVAS_REGISTRY_CHANGED = "session.canvas.registry_changed"
# Experimental: this event is part of an experimental API and may change or be removed.
SESSION_CANVAS_CLOSED = "session.canvas.closed"
# Experimental: this event is part of an experimental API and may change or be removed.
SESSION_CANVAS_UNAVAILABLE = "session.canvas.unavailable"
# Experimental: this event is part of an experimental API and may change or be removed.
SESSION_CANVAS_RECORDED = "session.canvas.recorded"
# Experimental: this event is part of an experimental API and may change or be removed.
SESSION_CANVAS_REMOVED = "session.canvas.removed"
SESSION_EXTENSIONS_ATTACHMENTS_PUSHED = "session.extensions.attachments_pushed"
MCP_APP_TOOL_CALL_COMPLETE = "mcp_app.tool_call_complete"
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> "SessionEventType":
return cls.UNKNOWN
@dataclass
class RawSessionEventData:
raw: Any
@staticmethod
def from_dict(obj: Any) -> "RawSessionEventData":
return RawSessionEventData(obj)
def to_dict(self) -> Any:
return self.raw
def _compat_to_python_key(name: str) -> str:
normalized = name.replace(".", "_")
result: list[str] = []
for index, char in enumerate(normalized):
if char.isupper() and index > 0 and (not normalized[index - 1].isupper() or (index + 1 < len(normalized) and normalized[index + 1].islower())):
result.append("_")
result.append(char.lower())
return "".join(result)
def _compat_to_json_key(name: str) -> str:
parts = name.split("_")
if not parts:
return name
return parts[0] + "".join(part[:1].upper() + part[1:] for part in parts[1:])
def _compat_to_json_value(value: Any) -> Any:
if hasattr(value, "to_dict"):
return cast(Any, value).to_dict()
if isinstance(value, Enum):
return value.value
if isinstance(value, datetime):
return value.isoformat()
if isinstance(value, timedelta):
return value.total_seconds() * 1000.0
if isinstance(value, UUID):
return str(value)
if isinstance(value, list):
return [_compat_to_json_value(item) for item in value]
if isinstance(value, dict):
return {key: _compat_to_json_value(item) for key, item in value.items()}
return value
def _compat_from_json_value(value: Any) -> Any:
return value
class Data:
"""Backward-compatible shim for manually constructed event payloads."""
def __init__(self, **kwargs: Any):
self._values = {key: _compat_from_json_value(value) for key, value in kwargs.items()}
for key, value in self._values.items():
setattr(self, key, value)
@staticmethod
def from_dict(obj: Any) -> "Data":
assert isinstance(obj, dict)
return Data(**{_compat_to_python_key(key): _compat_from_json_value(value) for key, value in obj.items()})
def to_dict(self) -> dict:
return {_compat_to_json_key(key): _compat_to_json_value(value) for key, value in self._values.items() if value is not None}
# Deprecated: this type is deprecated and will be removed in a future version.
@dataclass
class ToolExecutionCompleteContentTerminal:
"Deprecated for shell command exit metadata. Use ToolExecutionCompleteContentShellExit instead."
text: str
type: ClassVar[str] = "terminal"
cwd: str | None = None
exit_code: int | None = None
@staticmethod
def from_dict(obj: Any) -> "ToolExecutionCompleteContentTerminal":
assert isinstance(obj, dict)
text = from_str(obj.get("text"))
cwd = from_union([from_none, from_str], obj.get("cwd"))
exit_code = from_union([from_none, from_int], obj.get("exitCode"))
return ToolExecutionCompleteContentTerminal(
text=text,
cwd=cwd,
exit_code=exit_code,
)
def to_dict(self) -> dict:
result: dict = {}
result["text"] = from_str(self.text)
result["type"] = self.type
if self.cwd is not None:
result["cwd"] = from_union([from_none, from_str], self.cwd)
if self.exit_code is not None:
result["exitCode"] = from_union([from_none, to_int], self.exit_code)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class AssistantMessageServerTools:
"Neutral provider-tagged server-side tool-use payload (tool search, advisor) for verbatim round-tripping"
provider: str
advisor_model: str | None = None
function_call_namespaces: dict[str, str] | None = None
items: list[Any] | None = None
raw_content_blocks: list[Any] | None = None
@staticmethod
def from_dict(obj: Any) -> "AssistantMessageServerTools":
assert isinstance(obj, dict)
provider = from_str(obj.get("provider"))
advisor_model = from_union([from_none, from_str], obj.get("advisorModel"))
function_call_namespaces = from_union([from_none, lambda x: from_dict(from_str, x)], obj.get("functionCallNamespaces"))
items = from_union([from_none, lambda x: from_list(lambda x: x, x)], obj.get("items"))
raw_content_blocks = from_union([from_none, lambda x: from_list(lambda x: x, x)], obj.get("rawContentBlocks"))
return AssistantMessageServerTools(
provider=provider,
advisor_model=advisor_model,
function_call_namespaces=function_call_namespaces,
items=items,
raw_content_blocks=raw_content_blocks,
)
def to_dict(self) -> dict:
result: dict = {}
result["provider"] = from_str(self.provider)
if self.advisor_model is not None:
result["advisorModel"] = from_union([from_none, from_str], self.advisor_model)
if self.function_call_namespaces is not None:
result["functionCallNamespaces"] = from_union([from_none, lambda x: from_dict(from_str, x)], self.function_call_namespaces)
if self.items is not None:
result["items"] = from_union([from_none, lambda x: from_list(lambda x: x, x)], self.items)
if self.raw_content_blocks is not None:
result["rawContentBlocks"] = from_union([from_none, lambda x: from_list(lambda x: x, x)], self.raw_content_blocks)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class BinaryAssetReference:
"A reference to binary data persisted once on a session.binary_asset event and shared by id"
asset_id: str
byte_length: int
mime_type: str
type: BinaryAssetReferenceType
description: str | None = None
metadata: dict[str, Any] | None = None
@staticmethod
def from_dict(obj: Any) -> "BinaryAssetReference":
assert isinstance(obj, dict)
asset_id = from_str(obj.get("assetId"))
byte_length = from_int(obj.get("byteLength"))
mime_type = from_str(obj.get("mimeType"))
type = parse_enum(BinaryAssetReferenceType, obj.get("type"))
description = from_union([from_none, from_str], obj.get("description"))
metadata = from_union([from_none, lambda x: from_dict(lambda x: x, x)], obj.get("metadata"))
return BinaryAssetReference(
asset_id=asset_id,
byte_length=byte_length,
mime_type=mime_type,
type=type,
description=description,
metadata=metadata,
)
def to_dict(self) -> dict:
result: dict = {}
result["assetId"] = from_str(self.asset_id)
result["byteLength"] = to_int(self.byte_length)
result["mimeType"] = from_str(self.mime_type)
result["type"] = to_enum(BinaryAssetReferenceType, self.type)
if self.description is not None:
result["description"] = from_union([from_none, from_str], self.description)
if self.metadata is not None:
result["metadata"] = from_union([from_none, lambda x: from_dict(lambda x: x, x)], self.metadata)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CanvasRegistryChangedCanvas:
"Schema for the `CanvasRegistryChangedCanvas` type."
canvas_id: str
description: str
display_name: str
extension_id: str
actions: list[CanvasRegistryChangedCanvasAction] | None = None
extension_name: str | None = None
input_schema: Any = None
@staticmethod
def from_dict(obj: Any) -> "CanvasRegistryChangedCanvas":
assert isinstance(obj, dict)
canvas_id = from_str(obj.get("canvasId"))
description = from_str(obj.get("description"))
display_name = from_str(obj.get("displayName"))
extension_id = from_str(obj.get("extensionId"))
actions = from_union([from_none, lambda x: from_list(CanvasRegistryChangedCanvasAction.from_dict, x)], obj.get("actions"))
extension_name = from_union([from_none, from_str], obj.get("extensionName"))
input_schema = obj.get("inputSchema")
return CanvasRegistryChangedCanvas(
canvas_id=canvas_id,
description=description,
display_name=display_name,
extension_id=extension_id,
actions=actions,
extension_name=extension_name,
input_schema=input_schema,
)
def to_dict(self) -> dict:
result: dict = {}
result["canvasId"] = from_str(self.canvas_id)
result["description"] = from_str(self.description)
result["displayName"] = from_str(self.display_name)
result["extensionId"] = from_str(self.extension_id)
if self.actions is not None:
result["actions"] = from_union([from_none, lambda x: from_list(lambda x: to_class(CanvasRegistryChangedCanvasAction, x), x)], self.actions)
if self.extension_name is not None:
result["extensionName"] = from_union([from_none, from_str], self.extension_name)
if self.input_schema is not None:
result["inputSchema"] = self.input_schema
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CanvasRegistryChangedCanvasAction:
"Schema for the `CanvasRegistryChangedCanvasAction` type."
name: str
description: str | None = None
input_schema: Any = None
@staticmethod
def from_dict(obj: Any) -> "CanvasRegistryChangedCanvasAction":
assert isinstance(obj, dict)
name = from_str(obj.get("name"))
description = from_union([from_none, from_str], obj.get("description"))
input_schema = obj.get("inputSchema")
return CanvasRegistryChangedCanvasAction(
name=name,
description=description,
input_schema=input_schema,
)
def to_dict(self) -> dict:
result: dict = {}
result["name"] = from_str(self.name)
if self.description is not None:
result["description"] = from_union([from_none, from_str], self.description)
if self.input_schema is not None:
result["inputSchema"] = self.input_schema
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CitableSource:
"A source supplied by a tool that should be made available to the model as citable content."
content: str
id: str
path: str | None = None
title: str | None = None
url: str | None = None
@staticmethod
def from_dict(obj: Any) -> "CitableSource":
assert isinstance(obj, dict)
content = from_str(obj.get("content"))
id = from_str(obj.get("id"))
path = from_union([from_none, from_str], obj.get("path"))
title = from_union([from_none, from_str], obj.get("title"))
url = from_union([from_none, from_str], obj.get("url"))
return CitableSource(
content=content,
id=id,
path=path,
title=title,
url=url,
)
def to_dict(self) -> dict:
result: dict = {}
result["content"] = from_str(self.content)
result["id"] = from_str(self.id)
if self.path is not None:
result["path"] = from_union([from_none, from_str], self.path)
if self.title is not None:
result["title"] = from_union([from_none, from_str], self.title)
if self.url is not None:
result["url"] = from_union([from_none, from_str], self.url)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CitationLocationBlock:
"A content-block range within a structured source document."
end_block: int
start_block: int
type: ClassVar[str] = "block"
@staticmethod
def from_dict(obj: Any) -> "CitationLocationBlock":
assert isinstance(obj, dict)
end_block = from_int(obj.get("endBlock"))
start_block = from_int(obj.get("startBlock"))
return CitationLocationBlock(
end_block=end_block,
start_block=start_block,
)
def to_dict(self) -> dict:
result: dict = {}
result["endBlock"] = to_int(self.end_block)
result["startBlock"] = to_int(self.start_block)
result["type"] = self.type
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CitationLocationChar:
"A character range within the source's text content."
end_index: int
start_index: int
type: ClassVar[str] = "char"
@staticmethod
def from_dict(obj: Any) -> "CitationLocationChar":
assert isinstance(obj, dict)
end_index = from_int(obj.get("endIndex"))
start_index = from_int(obj.get("startIndex"))
return CitationLocationChar(
end_index=end_index,
start_index=start_index,
)
def to_dict(self) -> dict:
result: dict = {}
result["endIndex"] = to_int(self.end_index)
result["startIndex"] = to_int(self.start_index)
result["type"] = self.type
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CitationLocationPage:
"A page range within a paginated source document."
end_page: int
start_page: int
type: ClassVar[str] = "page"
@staticmethod
def from_dict(obj: Any) -> "CitationLocationPage":
assert isinstance(obj, dict)
end_page = from_int(obj.get("endPage"))
start_page = from_int(obj.get("startPage"))
return CitationLocationPage(
end_page=end_page,
start_page=start_page,
)
def to_dict(self) -> dict:
result: dict = {}
result["endPage"] = to_int(self.end_page)
result["startPage"] = to_int(self.start_page)
result["type"] = self.type
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CitationReference:
"A single citation occurrence linking a span of generated text to a supporting source."
source_id: str
cited_text: str | None = None
location: CitationLocation | None = None
provider_metadata: Any = None
@staticmethod
def from_dict(obj: Any) -> "CitationReference":
assert isinstance(obj, dict)
source_id = from_str(obj.get("sourceId"))
cited_text = from_union([from_none, from_str], obj.get("citedText"))
location = from_union([from_none, _load_CitationLocation], obj.get("location"))
provider_metadata = obj.get("providerMetadata")
return CitationReference(
source_id=source_id,
cited_text=cited_text,
location=location,
provider_metadata=provider_metadata,
)
def to_dict(self) -> dict:
result: dict = {}
result["sourceId"] = from_str(self.source_id)
if self.cited_text is not None:
result["citedText"] = from_union([from_none, from_str], self.cited_text)
if self.location is not None:
result["location"] = from_union([from_none, lambda x: x.to_dict()], self.location)
if self.provider_metadata is not None:
result["providerMetadata"] = self.provider_metadata
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CitationSource:
"A source that backs one or more cited spans in the assistant's response."
id: str
provider: CitationProvider
path: str | None = None
title: str | None = None
url: str | None = None
@staticmethod
def from_dict(obj: Any) -> "CitationSource":
assert isinstance(obj, dict)
id = from_str(obj.get("id"))
provider = parse_enum(CitationProvider, obj.get("provider"))
path = from_union([from_none, from_str], obj.get("path"))
title = from_union([from_none, from_str], obj.get("title"))
url = from_union([from_none, from_str], obj.get("url"))
return CitationSource(
id=id,
provider=provider,
path=path,
title=title,
url=url,
)
def to_dict(self) -> dict:
result: dict = {}
result["id"] = from_str(self.id)
result["provider"] = to_enum(CitationProvider, self.provider)
if self.path is not None:
result["path"] = from_union([from_none, from_str], self.path)
if self.title is not None:
result["title"] = from_union([from_none, from_str], self.title)
if self.url is not None:
result["url"] = from_union([from_none, from_str], self.url)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class CitationSpan:
"A contiguous span of generated assistant text and the source references that support it."
end_index: int
references: list[CitationReference]
start_index: int
@staticmethod
def from_dict(obj: Any) -> "CitationSpan":
assert isinstance(obj, dict)
end_index = from_int(obj.get("endIndex"))
references = from_list(CitationReference.from_dict, obj.get("references"))
start_index = from_int(obj.get("startIndex"))
return CitationSpan(
end_index=end_index,
references=references,
start_index=start_index,
)
def to_dict(self) -> dict:
result: dict = {}
result["endIndex"] = to_int(self.end_index)
result["references"] = from_list(lambda x: to_class(CitationReference, x), self.references)
result["startIndex"] = to_int(self.start_index)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class Citations:
"Provider-agnostic citations linking spans of the assistant's response to their supporting sources."
sources: list[CitationSource]
spans: list[CitationSpan]
@staticmethod
def from_dict(obj: Any) -> "Citations":
assert isinstance(obj, dict)
sources = from_list(CitationSource.from_dict, obj.get("sources"))
spans = from_list(CitationSpan.from_dict, obj.get("spans"))
return Citations(
sources=sources,
spans=spans,
)
def to_dict(self) -> dict:
result: dict = {}
result["sources"] = from_list(lambda x: to_class(CitationSource, x), self.sources)
result["spans"] = from_list(lambda x: to_class(CitationSpan, x), self.spans)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class OmittedBinaryResult:
"A binary result whose data was omitted from persistence due to the inline size limit"
byte_length: int
mime_type: str
omitted_reason: OmittedBinaryOmittedReason
type: OmittedBinaryType
description: str | None = None
metadata: dict[str, Any] | None = None
@staticmethod
def from_dict(obj: Any) -> "OmittedBinaryResult":
assert isinstance(obj, dict)
byte_length = from_int(obj.get("byteLength"))
mime_type = from_str(obj.get("mimeType"))
omitted_reason = parse_enum(OmittedBinaryOmittedReason, obj.get("omittedReason"))
type = parse_enum(OmittedBinaryType, obj.get("type"))
description = from_union([from_none, from_str], obj.get("description"))
metadata = from_union([from_none, lambda x: from_dict(lambda x: x, x)], obj.get("metadata"))
return OmittedBinaryResult(
byte_length=byte_length,
mime_type=mime_type,
omitted_reason=omitted_reason,
type=type,
description=description,
metadata=metadata,
)
def to_dict(self) -> dict:
result: dict = {}
result["byteLength"] = to_int(self.byte_length)
result["mimeType"] = from_str(self.mime_type)
result["omittedReason"] = to_enum(OmittedBinaryOmittedReason, self.omitted_reason)
result["type"] = to_enum(OmittedBinaryType, self.type)
if self.description is not None:
result["description"] = from_union([from_none, from_str], self.description)
if self.metadata is not None:
result["metadata"] = from_union([from_none, lambda x: from_dict(lambda x: x, x)], self.metadata)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class SessionCanvasClosedData:
"Schema for the `CanvasClosedData` type."
canvas_id: str
extension_id: str
instance_id: str
@staticmethod
def from_dict(obj: Any) -> "SessionCanvasClosedData":
assert isinstance(obj, dict)
canvas_id = from_str(obj.get("canvasId"))
extension_id = from_str(obj.get("extensionId"))
instance_id = from_str(obj.get("instanceId"))
return SessionCanvasClosedData(
canvas_id=canvas_id,
extension_id=extension_id,
instance_id=instance_id,
)
def to_dict(self) -> dict:
result: dict = {}
result["canvasId"] = from_str(self.canvas_id)
result["extensionId"] = from_str(self.extension_id)
result["instanceId"] = from_str(self.instance_id)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class SessionCanvasOpenedData:
"Schema for the `CanvasOpenedData` type."
canvas_id: str
extension_id: str
instance_id: str
extension_name: str | None = None
input: Any = None
status: str | None = None
title: str | None = None
url: str | None = None
@staticmethod
def from_dict(obj: Any) -> "SessionCanvasOpenedData":
assert isinstance(obj, dict)
canvas_id = from_str(obj.get("canvasId"))
extension_id = from_str(obj.get("extensionId"))
instance_id = from_str(obj.get("instanceId"))
extension_name = from_union([from_none, from_str], obj.get("extensionName"))
input = obj.get("input")
status = from_union([from_none, from_str], obj.get("status"))
title = from_union([from_none, from_str], obj.get("title"))
url = from_union([from_none, from_str], obj.get("url"))
return SessionCanvasOpenedData(
canvas_id=canvas_id,
extension_id=extension_id,
instance_id=instance_id,
extension_name=extension_name,
input=input,
status=status,
title=title,
url=url,
)
def to_dict(self) -> dict:
result: dict = {}
result["canvasId"] = from_str(self.canvas_id)
result["extensionId"] = from_str(self.extension_id)
result["instanceId"] = from_str(self.instance_id)
if self.extension_name is not None:
result["extensionName"] = from_union([from_none, from_str], self.extension_name)
if self.input is not None:
result["input"] = self.input
if self.status is not None:
result["status"] = from_union([from_none, from_str], self.status)
if self.title is not None:
result["title"] = from_union([from_none, from_str], self.title)
if self.url is not None:
result["url"] = from_union([from_none, from_str], self.url)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class SessionCanvasRecordedData:
"Durable record that a canvas instance is open, used to restore open canvases on cold session resume. Intentionally omits the transient url and availability."
canvas_id: str
extension_id: str
instance_id: str
input: Any = None
title: str | None = None
@staticmethod
def from_dict(obj: Any) -> "SessionCanvasRecordedData":
assert isinstance(obj, dict)
canvas_id = from_str(obj.get("canvasId"))
extension_id = from_str(obj.get("extensionId"))
instance_id = from_str(obj.get("instanceId"))
input = obj.get("input")
title = from_union([from_none, from_str], obj.get("title"))
return SessionCanvasRecordedData(
canvas_id=canvas_id,
extension_id=extension_id,
instance_id=instance_id,
input=input,
title=title,
)
def to_dict(self) -> dict:
result: dict = {}
result["canvasId"] = from_str(self.canvas_id)
result["extensionId"] = from_str(self.extension_id)
result["instanceId"] = from_str(self.instance_id)
if self.input is not None:
result["input"] = self.input
if self.title is not None:
result["title"] = from_union([from_none, from_str], self.title)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class SessionCanvasRegistryChangedData:
"Schema for the `CanvasRegistryChangedData` type."
canvases: list[CanvasRegistryChangedCanvas]
@staticmethod
def from_dict(obj: Any) -> "SessionCanvasRegistryChangedData":
assert isinstance(obj, dict)
canvases = from_list(CanvasRegistryChangedCanvas.from_dict, obj.get("canvases"))
return SessionCanvasRegistryChangedData(
canvases=canvases,
)
def to_dict(self) -> dict:
result: dict = {}
result["canvases"] = from_list(lambda x: to_class(CanvasRegistryChangedCanvas, x), self.canvases)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class SessionCanvasRemovedData:
"Durable record that a canvas instance was closed, superseding a prior instance_recorded during resume replay."
canvas_id: str
extension_id: str
instance_id: str
@staticmethod
def from_dict(obj: Any) -> "SessionCanvasRemovedData":
assert isinstance(obj, dict)
canvas_id = from_str(obj.get("canvasId"))
extension_id = from_str(obj.get("extensionId"))
instance_id = from_str(obj.get("instanceId"))
return SessionCanvasRemovedData(
canvas_id=canvas_id,
extension_id=extension_id,
instance_id=instance_id,
)
def to_dict(self) -> dict:
result: dict = {}
result["canvasId"] = from_str(self.canvas_id)
result["extensionId"] = from_str(self.extension_id)
result["instanceId"] = from_str(self.instance_id)
return result
# Experimental: this type is part of an experimental API and may change or be removed.
@dataclass
class SessionCanvasUnavailableData:
"Transient signal that an open canvas instance's provider has dropped (for example the extension is reloading mid-session). The host should keep the panel mounted and surface a reconnecting affordance rather than tearing it down; a subsequent `session.canvas.opened` for the same instanceId clears the affordance once the provider reconnects with a fresh url. Ephemeral and never persisted, so it is never replayed on cold resume."
canvas_id: str
extension_id: str
instance_id: str
@staticmethod
def from_dict(obj: Any) -> "SessionCanvasUnavailableData":
assert isinstance(obj, dict)
canvas_id = from_str(obj.get("canvasId"))
extension_id = from_str(obj.get("extensionId"))
instance_id = from_str(obj.get("instanceId"))
return SessionCanvasUnavailableData(
canvas_id=canvas_id,
extension_id=extension_id,
instance_id=instance_id,
)
def to_dict(self) -> dict:
result: dict = {}
result["canvasId"] = from_str(self.canvas_id)
result["extensionId"] = from_str(self.extension_id)
result["instanceId"] = from_str(self.instance_id)
return result
@dataclass
class AbortData:
"Turn abort information including the reason for termination"
reason: AbortReason
@staticmethod
def from_dict(obj: Any) -> "AbortData":
assert isinstance(obj, dict)
reason = parse_enum(AbortReason, obj.get("reason"))
return AbortData(
reason=reason,
)
def to_dict(self) -> dict:
result: dict = {}
result["reason"] = to_enum(AbortReason, self.reason)
return result
@dataclass
class AssistantIdleData:
"Payload emitted whenever the main agent's processing loop goes idle, including while related background work (running agents or in-flight attached shell commands) is still pending and the session-level idle event is therefore deferred"
aborted: bool | None = None