codex-sdk-python 0.81.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codex_sdk/__init__.py +140 -0
- codex_sdk/abort.py +40 -0
- codex_sdk/app_server.py +918 -0
- codex_sdk/codex.py +147 -0
- codex_sdk/config_overrides.py +70 -0
- codex_sdk/events.py +112 -0
- codex_sdk/exceptions.py +55 -0
- codex_sdk/exec.py +442 -0
- codex_sdk/hooks.py +74 -0
- codex_sdk/integrations/__init__.py +1 -0
- codex_sdk/integrations/pydantic_ai.py +172 -0
- codex_sdk/integrations/pydantic_ai_model.py +381 -0
- codex_sdk/items.py +173 -0
- codex_sdk/options.py +145 -0
- codex_sdk/telemetry.py +36 -0
- codex_sdk/thread.py +606 -0
- codex_sdk_python-0.81.0.dist-info/METADATA +880 -0
- codex_sdk_python-0.81.0.dist-info/RECORD +19 -0
- codex_sdk_python-0.81.0.dist-info/WHEEL +4 -0
codex_sdk/__init__.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Codex SDK for Python
|
|
3
|
+
|
|
4
|
+
Embed the Codex agent in your Python workflows and applications.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .abort import AbortController, AbortSignal
|
|
8
|
+
from .app_server import (
|
|
9
|
+
ApprovalDecisions,
|
|
10
|
+
AppServerClient,
|
|
11
|
+
AppServerClientInfo,
|
|
12
|
+
AppServerInput,
|
|
13
|
+
AppServerNotification,
|
|
14
|
+
AppServerOptions,
|
|
15
|
+
AppServerRequest,
|
|
16
|
+
AppServerTurnSession,
|
|
17
|
+
AppServerUserInput,
|
|
18
|
+
)
|
|
19
|
+
from .codex import Codex
|
|
20
|
+
from .events import (
|
|
21
|
+
ItemCompletedEvent,
|
|
22
|
+
ItemStartedEvent,
|
|
23
|
+
ItemUpdatedEvent,
|
|
24
|
+
ThreadError,
|
|
25
|
+
ThreadErrorEvent,
|
|
26
|
+
ThreadEvent,
|
|
27
|
+
ThreadStartedEvent,
|
|
28
|
+
TurnCompletedEvent,
|
|
29
|
+
TurnFailedEvent,
|
|
30
|
+
TurnStartedEvent,
|
|
31
|
+
Usage,
|
|
32
|
+
)
|
|
33
|
+
from .exceptions import (
|
|
34
|
+
CodexAbortError,
|
|
35
|
+
CodexAppServerError,
|
|
36
|
+
CodexCLIError,
|
|
37
|
+
CodexError,
|
|
38
|
+
CodexParseError,
|
|
39
|
+
TurnFailedError,
|
|
40
|
+
)
|
|
41
|
+
from .hooks import ThreadHooks
|
|
42
|
+
from .items import (
|
|
43
|
+
AgentMessageItem,
|
|
44
|
+
CommandExecutionItem,
|
|
45
|
+
CommandExecutionStatus,
|
|
46
|
+
ErrorItem,
|
|
47
|
+
FileChangeItem,
|
|
48
|
+
McpToolCallItem,
|
|
49
|
+
McpToolCallItemError,
|
|
50
|
+
McpToolCallItemResult,
|
|
51
|
+
McpToolCallStatus,
|
|
52
|
+
PatchApplyStatus,
|
|
53
|
+
PatchChangeKind,
|
|
54
|
+
ReasoningItem,
|
|
55
|
+
ThreadItem,
|
|
56
|
+
TodoItem,
|
|
57
|
+
TodoListItem,
|
|
58
|
+
WebSearchItem,
|
|
59
|
+
)
|
|
60
|
+
from .options import (
|
|
61
|
+
ApprovalMode,
|
|
62
|
+
CodexOptions,
|
|
63
|
+
ModelReasoningEffort,
|
|
64
|
+
SandboxMode,
|
|
65
|
+
ThreadOptions,
|
|
66
|
+
TurnOptions,
|
|
67
|
+
)
|
|
68
|
+
from .thread import (
|
|
69
|
+
Input,
|
|
70
|
+
LocalImageInput,
|
|
71
|
+
RunResult,
|
|
72
|
+
RunStreamedResult,
|
|
73
|
+
TextInput,
|
|
74
|
+
Thread,
|
|
75
|
+
Turn,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
__version__ = "0.81.0"
|
|
79
|
+
|
|
80
|
+
__all__ = [
|
|
81
|
+
"AbortController",
|
|
82
|
+
"AbortSignal",
|
|
83
|
+
"Codex",
|
|
84
|
+
"AppServerClient",
|
|
85
|
+
"AppServerClientInfo",
|
|
86
|
+
"AppServerNotification",
|
|
87
|
+
"AppServerRequest",
|
|
88
|
+
"AppServerOptions",
|
|
89
|
+
"AppServerTurnSession",
|
|
90
|
+
"ApprovalDecisions",
|
|
91
|
+
"AppServerInput",
|
|
92
|
+
"AppServerUserInput",
|
|
93
|
+
"Thread",
|
|
94
|
+
"ThreadHooks",
|
|
95
|
+
"Input",
|
|
96
|
+
"TextInput",
|
|
97
|
+
"LocalImageInput",
|
|
98
|
+
"RunResult",
|
|
99
|
+
"RunStreamedResult",
|
|
100
|
+
"Turn",
|
|
101
|
+
"ThreadEvent",
|
|
102
|
+
"ThreadStartedEvent",
|
|
103
|
+
"TurnStartedEvent",
|
|
104
|
+
"TurnCompletedEvent",
|
|
105
|
+
"TurnFailedEvent",
|
|
106
|
+
"ItemStartedEvent",
|
|
107
|
+
"ItemUpdatedEvent",
|
|
108
|
+
"ItemCompletedEvent",
|
|
109
|
+
"ThreadError",
|
|
110
|
+
"ThreadErrorEvent",
|
|
111
|
+
"Usage",
|
|
112
|
+
"ThreadItem",
|
|
113
|
+
"AgentMessageItem",
|
|
114
|
+
"ReasoningItem",
|
|
115
|
+
"CommandExecutionItem",
|
|
116
|
+
"FileChangeItem",
|
|
117
|
+
"McpToolCallItem",
|
|
118
|
+
"McpToolCallItemResult",
|
|
119
|
+
"McpToolCallItemError",
|
|
120
|
+
"WebSearchItem",
|
|
121
|
+
"TodoListItem",
|
|
122
|
+
"ErrorItem",
|
|
123
|
+
"CommandExecutionStatus",
|
|
124
|
+
"PatchChangeKind",
|
|
125
|
+
"PatchApplyStatus",
|
|
126
|
+
"McpToolCallStatus",
|
|
127
|
+
"TodoItem",
|
|
128
|
+
"CodexOptions",
|
|
129
|
+
"ThreadOptions",
|
|
130
|
+
"TurnOptions",
|
|
131
|
+
"ApprovalMode",
|
|
132
|
+
"SandboxMode",
|
|
133
|
+
"ModelReasoningEffort",
|
|
134
|
+
"CodexError",
|
|
135
|
+
"CodexAbortError",
|
|
136
|
+
"CodexAppServerError",
|
|
137
|
+
"CodexCLIError",
|
|
138
|
+
"CodexParseError",
|
|
139
|
+
"TurnFailedError",
|
|
140
|
+
]
|
codex_sdk/abort.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""AbortController and AbortSignal helpers for cancelling Codex runs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Optional, Union
|
|
8
|
+
|
|
9
|
+
AbortReason = Union[str, BaseException]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class AbortSignal:
|
|
14
|
+
"""Signal object used to abort a running operation."""
|
|
15
|
+
|
|
16
|
+
_event: asyncio.Event
|
|
17
|
+
_reason: Optional[AbortReason] = None
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def aborted(self) -> bool:
|
|
21
|
+
return self._event.is_set()
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def reason(self) -> Optional[AbortReason]:
|
|
25
|
+
return self._reason
|
|
26
|
+
|
|
27
|
+
async def wait(self) -> None:
|
|
28
|
+
await self._event.wait()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AbortController:
|
|
32
|
+
"""Controller used to trigger cancellation for an AbortSignal."""
|
|
33
|
+
|
|
34
|
+
def __init__(self) -> None:
|
|
35
|
+
self._event = asyncio.Event()
|
|
36
|
+
self.signal = AbortSignal(self._event)
|
|
37
|
+
|
|
38
|
+
def abort(self, reason: Optional[AbortReason] = None) -> None:
|
|
39
|
+
self.signal._reason = reason
|
|
40
|
+
self._event.set()
|