codexed 0.0.7__tar.gz → 0.0.9__tar.gz
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.
- {codexed-0.0.7 → codexed-0.0.9}/PKG-INFO +1 -1
- {codexed-0.0.7 → codexed-0.0.9}/pyproject.toml +1 -1
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/__init__.py +2 -6
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/client.py +42 -18
- codexed-0.0.9/src/codexed/helpers.py +7 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/__init__.py +2 -8
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/codex_types.py +3 -3
- codexed-0.0.9/src/codexed/models/mcp_server.py +51 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/request_params.py +0 -6
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/response_item.py +20 -24
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/thread_item.py +4 -6
- codexed-0.0.7/src/codexed/example.py +0 -160
- codexed-0.0.7/src/codexed/helpers.py +0 -53
- codexed-0.0.7/src/codexed/models/mcp_server.py +0 -26
- {codexed-0.0.7 → codexed-0.0.9}/LICENSE +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/README.md +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/README.md +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/exceptions.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/log.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/base.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/command_action.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/event_data.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/events.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/misc.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/responses.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/thread_status.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/token_usage.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/tool_config.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/user_input.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/models/web_search.py +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/py.typed +0 -0
- {codexed-0.0.7 → codexed-0.0.9}/src/codexed/request_handlers.py +0 -0
|
@@ -83,19 +83,17 @@ from codexed.models.codex_types import (
|
|
|
83
83
|
AskForApproval,
|
|
84
84
|
CollabAgentStatus,
|
|
85
85
|
CollabAgentTool,
|
|
86
|
-
CollabAgentToolCallStatus,
|
|
87
86
|
CollaborationMode,
|
|
88
87
|
CollaborationModeSettings,
|
|
89
88
|
CommandExecutionStatus,
|
|
90
89
|
DangerFullAccessSandboxPolicy,
|
|
91
|
-
DynamicToolCallStatus,
|
|
92
90
|
ExternalSandboxPolicy,
|
|
93
91
|
ApprovalDecision,
|
|
94
92
|
InputModality,
|
|
95
93
|
ItemStatus,
|
|
96
94
|
ItemType,
|
|
97
95
|
McpAuthStatusValue,
|
|
98
|
-
|
|
96
|
+
ToolCallStatus,
|
|
99
97
|
MessagePhase,
|
|
100
98
|
ModeKind,
|
|
101
99
|
ModelProvider,
|
|
@@ -184,7 +182,6 @@ __all__ = [
|
|
|
184
182
|
"CodexRequestError",
|
|
185
183
|
"CollabAgentStatus",
|
|
186
184
|
"CollabAgentTool",
|
|
187
|
-
"CollabAgentToolCallStatus",
|
|
188
185
|
"CollaborationMode",
|
|
189
186
|
"CollaborationModeSettings",
|
|
190
187
|
"CommandExecResponse",
|
|
@@ -195,7 +192,6 @@ __all__ = [
|
|
|
195
192
|
"ConfigWarningEvent",
|
|
196
193
|
"DangerFullAccessSandboxPolicy",
|
|
197
194
|
"DynamicToolCallHandler",
|
|
198
|
-
"DynamicToolCallStatus",
|
|
199
195
|
"EventData",
|
|
200
196
|
"EventType",
|
|
201
197
|
"ExperimentalFeature",
|
|
@@ -213,7 +209,6 @@ __all__ = [
|
|
|
213
209
|
"McpAuthStatusValue",
|
|
214
210
|
"McpElicitationHandler",
|
|
215
211
|
"McpServerConfig",
|
|
216
|
-
"McpToolCallStatus",
|
|
217
212
|
"MessagePhase",
|
|
218
213
|
"MethodNotFoundError",
|
|
219
214
|
"ModeKind",
|
|
@@ -269,6 +264,7 @@ __all__ = [
|
|
|
269
264
|
"ThreadUnarchivedData",
|
|
270
265
|
"ThreadUnarchivedEvent",
|
|
271
266
|
"TokenUsageBreakdown",
|
|
267
|
+
"ToolCallStatus",
|
|
272
268
|
"ToolConfig",
|
|
273
269
|
"TransportClosedError",
|
|
274
270
|
"TurnCompletedData",
|
|
@@ -15,14 +15,13 @@ from pydantic import BaseModel, TypeAdapter
|
|
|
15
15
|
|
|
16
16
|
from codexed.exceptions import (
|
|
17
17
|
CodexProcessError,
|
|
18
|
+
CodexRequestError,
|
|
18
19
|
TransportClosedError,
|
|
19
20
|
TurnFailedError,
|
|
20
21
|
map_jsonrpc_error,
|
|
21
22
|
)
|
|
22
|
-
from codexed.helpers import kebab_to_camel
|
|
23
|
+
from codexed.helpers import kebab_to_camel
|
|
23
24
|
from codexed.models import (
|
|
24
|
-
AgentMessageDeltaData,
|
|
25
|
-
AgentMessageDeltaEvent,
|
|
26
25
|
AppsListParams,
|
|
27
26
|
AppsListResponse,
|
|
28
27
|
CancelLoginAccountParams,
|
|
@@ -96,6 +95,7 @@ from codexed.models import (
|
|
|
96
95
|
ThreadUnarchiveResponse,
|
|
97
96
|
ThreadUnsubscribeParams,
|
|
98
97
|
ThreadUnsubscribeResponse,
|
|
98
|
+
TurnCompletedData,
|
|
99
99
|
TurnCompletedEvent,
|
|
100
100
|
TurnErrorData,
|
|
101
101
|
TurnErrorEvent,
|
|
@@ -147,6 +147,7 @@ if TYPE_CHECKING:
|
|
|
147
147
|
ThreadSourceKind,
|
|
148
148
|
ThreadTokenUsage,
|
|
149
149
|
ToolConfig,
|
|
150
|
+
Turn,
|
|
150
151
|
UserInput,
|
|
151
152
|
)
|
|
152
153
|
from codexed.models.request_params import HazelnutScope, LoginType, ProductSurface
|
|
@@ -334,6 +335,7 @@ class Session:
|
|
|
334
335
|
tools: list[ToolConfig] | None = None,
|
|
335
336
|
code_mode: bool | None = None,
|
|
336
337
|
personality: Personality | None = None,
|
|
338
|
+
turn_id: str | None = None,
|
|
337
339
|
) -> Session:
|
|
338
340
|
"""Fork this thread. See :meth:`CodexClient.thread_fork`."""
|
|
339
341
|
return await self._client.thread_fork(
|
|
@@ -350,6 +352,7 @@ class Session:
|
|
|
350
352
|
tools=tools,
|
|
351
353
|
code_mode=code_mode,
|
|
352
354
|
personality=personality,
|
|
355
|
+
turn_id=turn_id,
|
|
353
356
|
)
|
|
354
357
|
|
|
355
358
|
def __repr__(self) -> str:
|
|
@@ -439,7 +442,7 @@ class CodexClient:
|
|
|
439
442
|
cmd.extend(["--profile", self._profile])
|
|
440
443
|
# Add MCP server configurations via --config flags
|
|
441
444
|
for server_name, server_config in self._mcp_servers.items():
|
|
442
|
-
config_str =
|
|
445
|
+
config_str = server_config.to_config_toml(server_name)
|
|
443
446
|
cmd.extend(["--config", config_str])
|
|
444
447
|
|
|
445
448
|
logger.info("Starting Codex app-server: %s", " ".join(cmd))
|
|
@@ -653,6 +656,7 @@ class CodexClient:
|
|
|
653
656
|
code_mode: bool | None = None,
|
|
654
657
|
personality: Personality | None = None,
|
|
655
658
|
mcp_servers: Mapping[str, McpServerConfig] | None = None,
|
|
659
|
+
turn_id: str | None = None,
|
|
656
660
|
) -> Session:
|
|
657
661
|
"""Fork an existing thread into a new thread with copied history.
|
|
658
662
|
|
|
@@ -671,6 +675,7 @@ class CodexClient:
|
|
|
671
675
|
code_mode: Enable experimental code mode feature flag
|
|
672
676
|
personality: Personality for forked thread
|
|
673
677
|
mcp_servers: Per-thread MCP server configurations
|
|
678
|
+
turn_id: If provided, rollback the forked thread to this turn
|
|
674
679
|
|
|
675
680
|
Returns:
|
|
676
681
|
Session wrapping the new forked thread
|
|
@@ -691,7 +696,10 @@ class CodexClient:
|
|
|
691
696
|
result = await self._send_request("thread/fork", params)
|
|
692
697
|
response = ThreadResponse.model_validate(result)
|
|
693
698
|
self._active_threads.add(response.thread.id)
|
|
694
|
-
|
|
699
|
+
session = Session(self, response)
|
|
700
|
+
if turn_id is not None:
|
|
701
|
+
await session.rollback_to_turn(turn_id)
|
|
702
|
+
return session
|
|
695
703
|
|
|
696
704
|
async def thread_list(
|
|
697
705
|
self,
|
|
@@ -1015,8 +1023,7 @@ class CodexClient:
|
|
|
1015
1023
|
)
|
|
1016
1024
|
print(f"Found {result.total} files: {result.files}")
|
|
1017
1025
|
"""
|
|
1018
|
-
|
|
1019
|
-
response_text = ""
|
|
1026
|
+
turn: Turn | None = None
|
|
1020
1027
|
async for event in self.turn_stream(
|
|
1021
1028
|
thread_id,
|
|
1022
1029
|
user_input,
|
|
@@ -1031,12 +1038,18 @@ class CodexClient:
|
|
|
1031
1038
|
collaboration_mode=collaboration_mode,
|
|
1032
1039
|
):
|
|
1033
1040
|
match event:
|
|
1034
|
-
case
|
|
1035
|
-
|
|
1041
|
+
case TurnCompletedEvent(data=TurnCompletedData(turn=t)):
|
|
1042
|
+
turn = t
|
|
1036
1043
|
case TurnErrorEvent(data=TurnErrorData(error=error)):
|
|
1037
1044
|
raise TurnFailedError(error, turn_id="unknown")
|
|
1038
1045
|
|
|
1039
|
-
|
|
1046
|
+
if turn is None:
|
|
1047
|
+
msg = "Turn completed without a TurnCompletedEvent"
|
|
1048
|
+
raise CodexRequestError(code=-1, message=msg)
|
|
1049
|
+
response_text = turn.final_response
|
|
1050
|
+
if response_text is None:
|
|
1051
|
+
msg = "Turn completed without a final response"
|
|
1052
|
+
raise CodexRequestError(code=-1, message=msg)
|
|
1040
1053
|
return result_type.model_validate_json(response_text)
|
|
1041
1054
|
|
|
1042
1055
|
# ========================================================================
|
|
@@ -1144,11 +1157,7 @@ class CodexClient:
|
|
|
1144
1157
|
# Model methods
|
|
1145
1158
|
# ========================================================================
|
|
1146
1159
|
|
|
1147
|
-
async def model_list(
|
|
1148
|
-
self,
|
|
1149
|
-
*,
|
|
1150
|
-
include_hidden: bool | None = None,
|
|
1151
|
-
) -> list[ModelData]:
|
|
1160
|
+
async def model_list(self, *, include_hidden: bool | None = None) -> list[ModelData]:
|
|
1152
1161
|
"""List available models with reasoning effort options.
|
|
1153
1162
|
|
|
1154
1163
|
Args:
|
|
@@ -1254,18 +1263,33 @@ class CodexClient:
|
|
|
1254
1263
|
result = await self._send_request("fs/getMetadata", params)
|
|
1255
1264
|
return FsGetMetadataResponse.model_validate(result)
|
|
1256
1265
|
|
|
1257
|
-
async def fs_read_directory(
|
|
1258
|
-
|
|
1266
|
+
async def fs_read_directory(
|
|
1267
|
+
self,
|
|
1268
|
+
path: str,
|
|
1269
|
+
*,
|
|
1270
|
+
recursive: bool = False,
|
|
1271
|
+
) -> list[FsReadDirectoryEntry]:
|
|
1272
|
+
"""List child entries for a directory.
|
|
1259
1273
|
|
|
1260
1274
|
Args:
|
|
1261
1275
|
path: Absolute directory path to read.
|
|
1276
|
+
recursive: If True, recursively list all descendant entries.
|
|
1262
1277
|
|
|
1263
1278
|
Returns:
|
|
1264
1279
|
List of directory entries with fileName, isDirectory, isFile.
|
|
1265
1280
|
"""
|
|
1266
1281
|
params = FsReadDirectoryParams(path=path)
|
|
1267
1282
|
result = await self._send_request("fs/readDirectory", params)
|
|
1268
|
-
|
|
1283
|
+
entries = FsReadDirectoryResponse.model_validate(result).entries
|
|
1284
|
+
if not recursive:
|
|
1285
|
+
return entries
|
|
1286
|
+
all_entries = list(entries)
|
|
1287
|
+
for entry in entries:
|
|
1288
|
+
if entry.is_directory:
|
|
1289
|
+
sub_path = f"{path.rstrip('/')}/{entry.file_name}"
|
|
1290
|
+
sub_entries = await self.fs_read_directory(sub_path, recursive=True)
|
|
1291
|
+
all_entries.extend(sub_entries)
|
|
1292
|
+
return all_entries
|
|
1269
1293
|
|
|
1270
1294
|
async def fs_remove(
|
|
1271
1295
|
self,
|
|
@@ -14,12 +14,10 @@ from codexed.models.codex_types import (
|
|
|
14
14
|
AskForApproval,
|
|
15
15
|
CollabAgentStatus,
|
|
16
16
|
CollabAgentTool,
|
|
17
|
-
CollabAgentToolCallStatus,
|
|
18
17
|
CollaborationMode,
|
|
19
18
|
CollaborationModeSettings,
|
|
20
19
|
CommandExecutionStatus,
|
|
21
20
|
DangerFullAccessSandboxPolicy,
|
|
22
|
-
DynamicToolCallStatus,
|
|
23
21
|
ElicitationAction,
|
|
24
22
|
ExperimentalFeatureStage,
|
|
25
23
|
ExternalAgentConfigMigrationItemType,
|
|
@@ -30,7 +28,7 @@ from codexed.models.codex_types import (
|
|
|
30
28
|
ItemStatus,
|
|
31
29
|
ItemType,
|
|
32
30
|
McpAuthStatusValue,
|
|
33
|
-
|
|
31
|
+
ToolCallStatus,
|
|
34
32
|
MergeStrategy,
|
|
35
33
|
MessagePhase,
|
|
36
34
|
ModeKind,
|
|
@@ -240,7 +238,6 @@ from codexed.models.request_params import (
|
|
|
240
238
|
ListMcpServerStatusParams,
|
|
241
239
|
LoginAccountParams,
|
|
242
240
|
LoginType,
|
|
243
|
-
McpElicitationAction,
|
|
244
241
|
McpElicitationFormParams,
|
|
245
242
|
McpElicitationUrlParams,
|
|
246
243
|
McpServerElicitationRequestParams,
|
|
@@ -449,7 +446,6 @@ __all__ = [
|
|
|
449
446
|
"CollabAgentState",
|
|
450
447
|
"CollabAgentStatus",
|
|
451
448
|
"CollabAgentTool",
|
|
452
|
-
"CollabAgentToolCallStatus",
|
|
453
449
|
"CollabToolsConfig",
|
|
454
450
|
"CollaborationMode",
|
|
455
451
|
"CollaborationModeListParams",
|
|
@@ -498,7 +494,6 @@ __all__ = [
|
|
|
498
494
|
"DynamicToolCallOutputContentItem",
|
|
499
495
|
"DynamicToolCallParams",
|
|
500
496
|
"DynamicToolCallResponse",
|
|
501
|
-
"DynamicToolCallStatus",
|
|
502
497
|
"ElicitationAction",
|
|
503
498
|
"ErrorEvent",
|
|
504
499
|
"ErrorEventData",
|
|
@@ -574,7 +569,6 @@ __all__ = [
|
|
|
574
569
|
"LoginChatGptCompleteEvent",
|
|
575
570
|
"LoginType",
|
|
576
571
|
"McpAuthStatusValue",
|
|
577
|
-
"McpElicitationAction",
|
|
578
572
|
"McpElicitationFormParams",
|
|
579
573
|
"McpElicitationUrlParams",
|
|
580
574
|
"McpResource",
|
|
@@ -594,7 +588,6 @@ __all__ = [
|
|
|
594
588
|
"McpToolCallProgressData",
|
|
595
589
|
"McpToolCallProgressEvent",
|
|
596
590
|
"McpToolCallResult",
|
|
597
|
-
"McpToolCallStatus",
|
|
598
591
|
"MergeStrategy",
|
|
599
592
|
"MessagePhase",
|
|
600
593
|
"MessageResponseItem",
|
|
@@ -743,6 +736,7 @@ __all__ = [
|
|
|
743
736
|
"ThreadUnsubscribeParams",
|
|
744
737
|
"ThreadUnsubscribeResponse",
|
|
745
738
|
"TokenUsageBreakdown",
|
|
739
|
+
"ToolCallStatus",
|
|
746
740
|
"ToolConfig",
|
|
747
741
|
"ToolRequestUserInputAnswer",
|
|
748
742
|
"ToolRequestUserInputOption",
|
|
@@ -27,6 +27,8 @@ ItemType = Literal[
|
|
|
27
27
|
"mcp_tool_call",
|
|
28
28
|
]
|
|
29
29
|
ItemStatus = Literal["pending", "running", "completed", "error"]
|
|
30
|
+
McpElicitationAction = Literal["accept", "decline", "cancel"]
|
|
31
|
+
"""Action taken by the user on an elicitation request."""
|
|
30
32
|
|
|
31
33
|
# New type aliases
|
|
32
34
|
SessionSource = Literal["cli", "vscode", "exec", "appServer", "unknown"]
|
|
@@ -46,10 +48,8 @@ ThreadSourceKind = Literal[
|
|
|
46
48
|
MessagePhase = Literal["commentary", "final_answer"]
|
|
47
49
|
PatchApplyStatus = Literal["inProgress", "completed", "failed", "declined"]
|
|
48
50
|
CommandExecutionStatus = Literal["inProgress", "completed", "failed", "declined"]
|
|
49
|
-
|
|
50
|
-
DynamicToolCallStatus = Literal["inProgress", "completed", "failed"]
|
|
51
|
+
ToolCallStatus = Literal["inProgress", "completed", "failed"]
|
|
51
52
|
CollabAgentTool = Literal["spawnAgent", "sendInput", "resumeAgent", "wait", "closeAgent"]
|
|
52
|
-
CollabAgentToolCallStatus = Literal["inProgress", "completed", "failed"]
|
|
53
53
|
CollabAgentStatus = Literal[
|
|
54
54
|
"pendingInit", "running", "completed", "errored", "shutdown", "notFound"
|
|
55
55
|
]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""MCP server configuration models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class StdioMcpServer(BaseModel):
|
|
9
|
+
"""MCP server running as a subprocess via stdio transport."""
|
|
10
|
+
|
|
11
|
+
command: str
|
|
12
|
+
args: list[str] = []
|
|
13
|
+
env: dict[str, str] | None = None
|
|
14
|
+
enabled: bool = True
|
|
15
|
+
|
|
16
|
+
def to_config_toml(self, name: str) -> str:
|
|
17
|
+
parts = [f'command = "{self.command}"']
|
|
18
|
+
if self.args:
|
|
19
|
+
args_str = ", ".join(f'"{arg}"' for arg in self.args)
|
|
20
|
+
parts.append(f"args = [{args_str}]")
|
|
21
|
+
if self.env:
|
|
22
|
+
# env as inline table
|
|
23
|
+
env_items = ", ".join(f'{k} = "{v}"' for k, v in self.env.items())
|
|
24
|
+
parts.append(f"env = {{{env_items}}}")
|
|
25
|
+
if not self.enabled:
|
|
26
|
+
parts.append("enabled = false")
|
|
27
|
+
return f"mcp_servers.{name}={{{', '.join(parts)}}}"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class HttpMcpServer(BaseModel):
|
|
31
|
+
"""MCP server accessible via HTTP/SSE transport."""
|
|
32
|
+
|
|
33
|
+
url: str
|
|
34
|
+
bearer_token_env_var: str | None = None
|
|
35
|
+
http_headers: dict[str, str] | None = None
|
|
36
|
+
enabled: bool = True
|
|
37
|
+
|
|
38
|
+
def to_config_toml(self, name: str) -> str:
|
|
39
|
+
parts = [f'url = "{self.url}"']
|
|
40
|
+
if self.bearer_token_env_var:
|
|
41
|
+
parts.append(f'bearer_token_env_var = "{self.bearer_token_env_var}"')
|
|
42
|
+
if self.http_headers:
|
|
43
|
+
# headers as inline table
|
|
44
|
+
headers_items = ", ".join(f'{k} = "{v}"' for k, v in self.http_headers.items())
|
|
45
|
+
parts.append(f"http_headers = {{{headers_items}}}")
|
|
46
|
+
if not self.enabled:
|
|
47
|
+
parts.append("enabled = false")
|
|
48
|
+
return f"mcp_servers.{name}={{{', '.join(parts)}}}"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
McpServerConfig = StdioMcpServer | HttpMcpServer
|
|
@@ -504,12 +504,6 @@ class DynamicToolCallParams(CodexBaseModel):
|
|
|
504
504
|
arguments: Any
|
|
505
505
|
|
|
506
506
|
|
|
507
|
-
# --- MCP Elicitation ---
|
|
508
|
-
|
|
509
|
-
McpElicitationAction = Literal["accept", "decline", "cancel"]
|
|
510
|
-
"""Action taken by the user on an elicitation request."""
|
|
511
|
-
|
|
512
|
-
|
|
513
507
|
class _McpElicitationBase(CodexBaseModel):
|
|
514
508
|
"""Common fields for MCP elicitation requests."""
|
|
515
509
|
|
|
@@ -8,7 +8,7 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
from typing import Annotated, Literal
|
|
10
10
|
|
|
11
|
-
from pydantic import Discriminator, Field
|
|
11
|
+
from pydantic import Discriminator, Field
|
|
12
12
|
|
|
13
13
|
from codexed.models.base import CodexBaseModel
|
|
14
14
|
|
|
@@ -38,9 +38,7 @@ class OutputTextContent(CodexBaseModel):
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
ContentItem = Annotated[
|
|
41
|
-
|
|
42
|
-
| Annotated[InputImageContent, Tag("input_image")]
|
|
43
|
-
| Annotated[OutputTextContent, Tag("output_text")],
|
|
41
|
+
InputTextContent | InputImageContent | OutputTextContent,
|
|
44
42
|
Discriminator("type"),
|
|
45
43
|
]
|
|
46
44
|
|
|
@@ -63,8 +61,7 @@ class ReasoningPlainTextContent(CodexBaseModel):
|
|
|
63
61
|
|
|
64
62
|
|
|
65
63
|
ReasoningItemContent = Annotated[
|
|
66
|
-
|
|
67
|
-
| Annotated[ReasoningPlainTextContent, Tag("text")],
|
|
64
|
+
ReasoningTextContent | ReasoningPlainTextContent,
|
|
68
65
|
Discriminator("type"),
|
|
69
66
|
]
|
|
70
67
|
|
|
@@ -95,8 +92,7 @@ class FunctionCallOutputImageItem(CodexBaseModel):
|
|
|
95
92
|
|
|
96
93
|
|
|
97
94
|
FunctionCallOutputContentItem = Annotated[
|
|
98
|
-
|
|
99
|
-
| Annotated[FunctionCallOutputImageItem, Tag("input_image")],
|
|
95
|
+
FunctionCallOutputTextItem | FunctionCallOutputImageItem,
|
|
100
96
|
Discriminator("type"),
|
|
101
97
|
]
|
|
102
98
|
|
|
@@ -158,10 +154,10 @@ class WebSearchActionOther(CodexBaseModel):
|
|
|
158
154
|
|
|
159
155
|
|
|
160
156
|
WebSearchAction = Annotated[
|
|
161
|
-
|
|
162
|
-
|
|
|
163
|
-
|
|
|
164
|
-
|
|
|
157
|
+
WebSearchActionSearch
|
|
158
|
+
| WebSearchActionOpenPage
|
|
159
|
+
| WebSearchActionFindInPage
|
|
160
|
+
| WebSearchActionOther,
|
|
165
161
|
Discriminator("type"),
|
|
166
162
|
]
|
|
167
163
|
|
|
@@ -283,17 +279,17 @@ class OtherResponseItem(CodexBaseModel):
|
|
|
283
279
|
|
|
284
280
|
|
|
285
281
|
ResponseItem = Annotated[
|
|
286
|
-
|
|
287
|
-
|
|
|
288
|
-
|
|
|
289
|
-
|
|
|
290
|
-
|
|
|
291
|
-
|
|
|
292
|
-
|
|
|
293
|
-
|
|
|
294
|
-
|
|
|
295
|
-
|
|
|
296
|
-
|
|
|
297
|
-
|
|
|
282
|
+
MessageResponseItem
|
|
283
|
+
| ReasoningResponseItem
|
|
284
|
+
| LocalShellCallResponseItem
|
|
285
|
+
| FunctionCallResponseItem
|
|
286
|
+
| FunctionCallOutputResponseItem
|
|
287
|
+
| CustomToolCallResponseItem
|
|
288
|
+
| CustomToolCallOutputResponseItem
|
|
289
|
+
| WebSearchCallResponseItem
|
|
290
|
+
| ImageGenerationCallResponseItem
|
|
291
|
+
| GhostSnapshotResponseItem
|
|
292
|
+
| CompactionResponseItem
|
|
293
|
+
| OtherResponseItem,
|
|
298
294
|
Discriminator("type"),
|
|
299
295
|
]
|
|
@@ -9,12 +9,10 @@ from codexed.models.base import CodexBaseModel
|
|
|
9
9
|
from codexed.models.codex_types import ( # noqa: TC001
|
|
10
10
|
CollabAgentStatus,
|
|
11
11
|
CollabAgentTool,
|
|
12
|
-
CollabAgentToolCallStatus,
|
|
13
12
|
CommandExecutionStatus,
|
|
14
|
-
DynamicToolCallStatus,
|
|
15
|
-
McpToolCallStatus,
|
|
16
13
|
MessagePhase,
|
|
17
14
|
PatchApplyStatus,
|
|
15
|
+
ToolCallStatus,
|
|
18
16
|
)
|
|
19
17
|
from codexed.models.command_action import CommandAction # noqa: TC001
|
|
20
18
|
from codexed.models.user_input import UserInput # noqa: TC001
|
|
@@ -160,7 +158,7 @@ class ThreadItemMcpToolCall(BaseThreadItem):
|
|
|
160
158
|
type: Literal["mcpToolCall"] = "mcpToolCall"
|
|
161
159
|
server: str
|
|
162
160
|
tool: str
|
|
163
|
-
status:
|
|
161
|
+
status: ToolCallStatus
|
|
164
162
|
arguments: dict[str, Any] | None = None
|
|
165
163
|
result: McpToolCallResult | None = None
|
|
166
164
|
error: McpToolCallError | None = None
|
|
@@ -182,7 +180,7 @@ class ThreadItemDynamicToolCall(BaseThreadItem):
|
|
|
182
180
|
type: Literal["dynamicToolCall"] = "dynamicToolCall"
|
|
183
181
|
tool: str
|
|
184
182
|
arguments: dict[str, Any] | None = None
|
|
185
|
-
status:
|
|
183
|
+
status: ToolCallStatus
|
|
186
184
|
content_items: list[DynamicToolCallOutputContentItem] | None = None
|
|
187
185
|
success: bool | None = None
|
|
188
186
|
duration_ms: int | None = None
|
|
@@ -248,7 +246,7 @@ class ThreadItemCollabAgentToolCall(BaseThreadItem):
|
|
|
248
246
|
|
|
249
247
|
type: Literal["collabAgentToolCall"] = "collabAgentToolCall"
|
|
250
248
|
tool: CollabAgentTool
|
|
251
|
-
status:
|
|
249
|
+
status: ToolCallStatus
|
|
252
250
|
sender_thread_id: str
|
|
253
251
|
receiver_thread_ids: list[str] = Field(default_factory=list)
|
|
254
252
|
prompt: str | None = None
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"""Example usage of the Codex adapter."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import asyncio
|
|
6
|
-
import sys
|
|
7
|
-
from typing import TYPE_CHECKING, Any
|
|
8
|
-
|
|
9
|
-
from codexed import CodexClient
|
|
10
|
-
from codexed.models.events import (
|
|
11
|
-
AgentMessageDeltaEvent,
|
|
12
|
-
CommandExecutionOutputDeltaEvent,
|
|
13
|
-
TurnCompletedEvent,
|
|
14
|
-
TurnErrorEvent,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if TYPE_CHECKING:
|
|
19
|
-
from collections.abc import Callable
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async def simple_chat() -> None:
|
|
23
|
-
"""Simple single-turn chat example."""
|
|
24
|
-
print("=== Simple Chat Example ===\n")
|
|
25
|
-
|
|
26
|
-
async with CodexClient() as client:
|
|
27
|
-
# Start a thread
|
|
28
|
-
session = await client.thread_start(cwd=".")
|
|
29
|
-
print(f"Started thread: {session.thread_id}\n")
|
|
30
|
-
|
|
31
|
-
# Send a message
|
|
32
|
-
message = "List the Python files in the current directory"
|
|
33
|
-
print(f"> {message}\n")
|
|
34
|
-
|
|
35
|
-
async for event in session.turn_stream(message):
|
|
36
|
-
# Print agent messages
|
|
37
|
-
match event:
|
|
38
|
-
case AgentMessageDeltaEvent():
|
|
39
|
-
print(event.data.delta, end="", flush=True)
|
|
40
|
-
case CommandExecutionOutputDeltaEvent():
|
|
41
|
-
print(f"\n[Command output]\n{event.data.delta}", flush=True)
|
|
42
|
-
case TurnCompletedEvent():
|
|
43
|
-
print("\n\n[Turn completed]")
|
|
44
|
-
break
|
|
45
|
-
case TurnErrorEvent(data=data):
|
|
46
|
-
print(f"\n\n[Error: {data.error}]", file=sys.stderr)
|
|
47
|
-
break
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
async def multi_turn_chat() -> None:
|
|
51
|
-
"""Multi-turn conversation example."""
|
|
52
|
-
print("=== Multi-Turn Chat Example ===\n")
|
|
53
|
-
|
|
54
|
-
async with CodexClient() as client:
|
|
55
|
-
session = await client.thread_start(cwd=".", model="gpt-5-codex")
|
|
56
|
-
|
|
57
|
-
messages = [
|
|
58
|
-
"What is the main purpose of this codebase?",
|
|
59
|
-
"Show me the entry point file",
|
|
60
|
-
"What dependencies does it use?",
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
for i, message in enumerate(messages, 1):
|
|
64
|
-
print(f"\n--- Turn {i} ---")
|
|
65
|
-
print(f"> {message}\n")
|
|
66
|
-
|
|
67
|
-
async for event in session.turn_stream(message):
|
|
68
|
-
match event:
|
|
69
|
-
case AgentMessageDeltaEvent(data=data):
|
|
70
|
-
print(data.delta, end="", flush=True)
|
|
71
|
-
case TurnCompletedEvent():
|
|
72
|
-
print("\n")
|
|
73
|
-
break
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
async def model_override_example() -> None:
|
|
77
|
-
"""Example showing per-turn model override."""
|
|
78
|
-
print("=== Model Override Example ===\n")
|
|
79
|
-
|
|
80
|
-
async with CodexClient() as client:
|
|
81
|
-
session = await client.thread_start(model="gpt-5-codex")
|
|
82
|
-
|
|
83
|
-
# First turn with default model
|
|
84
|
-
print("Turn 1 (default model: gpt-5-codex)")
|
|
85
|
-
print("> Write a hello world function\n")
|
|
86
|
-
|
|
87
|
-
async for event in session.turn_stream("Write a hello world function"):
|
|
88
|
-
match event:
|
|
89
|
-
case AgentMessageDeltaEvent(data=data):
|
|
90
|
-
print(data.delta, end="", flush=True)
|
|
91
|
-
case TurnCompletedEvent():
|
|
92
|
-
print("\n")
|
|
93
|
-
break
|
|
94
|
-
|
|
95
|
-
# Second turn with different model
|
|
96
|
-
print("\nTurn 2 (override to claude-opus-4, high effort)")
|
|
97
|
-
print("> Now make it more elegant\n")
|
|
98
|
-
|
|
99
|
-
async for event in session.turn_stream(
|
|
100
|
-
"Now make it more elegant",
|
|
101
|
-
model="claude-opus-4",
|
|
102
|
-
effort="high",
|
|
103
|
-
):
|
|
104
|
-
match event:
|
|
105
|
-
case AgentMessageDeltaEvent(data=data):
|
|
106
|
-
print(data.delta, end="", flush=True)
|
|
107
|
-
case TurnCompletedEvent():
|
|
108
|
-
print("\n")
|
|
109
|
-
break
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
async def event_inspection_example() -> None:
|
|
113
|
-
"""Example showing detailed event inspection."""
|
|
114
|
-
print("=== Event Inspection Example ===\n")
|
|
115
|
-
|
|
116
|
-
async with CodexClient() as client:
|
|
117
|
-
session = await client.thread_start(cwd=".")
|
|
118
|
-
|
|
119
|
-
async for event in session.turn_stream("What files are here?"):
|
|
120
|
-
# Print all event types
|
|
121
|
-
print(f"[{event.event_type}]", end=" ")
|
|
122
|
-
print(event)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
async def main() -> None:
|
|
126
|
-
"""Run all examples."""
|
|
127
|
-
examples: list[tuple[str, Callable[[], Any]]] = [
|
|
128
|
-
# ("Simple Chat", simple_chat),
|
|
129
|
-
# ("Multi-Turn Chat", multi_turn_chat),
|
|
130
|
-
# ("Model Override", model_override_example),
|
|
131
|
-
("Event Inspection", event_inspection_example),
|
|
132
|
-
]
|
|
133
|
-
|
|
134
|
-
if len(sys.argv) > 1:
|
|
135
|
-
# Run specific example by number
|
|
136
|
-
try:
|
|
137
|
-
idx = int(sys.argv[1]) - 1
|
|
138
|
-
if 0 <= idx < len(examples):
|
|
139
|
-
name, func = examples[idx]
|
|
140
|
-
print(f"Running: {name}\n")
|
|
141
|
-
await func()
|
|
142
|
-
else:
|
|
143
|
-
print(f"Invalid example number. Choose 1-{len(examples)}")
|
|
144
|
-
except ValueError:
|
|
145
|
-
print("Usage: python example.py [example_number]")
|
|
146
|
-
else:
|
|
147
|
-
# Run all examples
|
|
148
|
-
print("Codex Adapter Examples")
|
|
149
|
-
print("=" * 50)
|
|
150
|
-
print("Running all examples...\n")
|
|
151
|
-
|
|
152
|
-
for i, (name, func) in enumerate(examples, 1):
|
|
153
|
-
print(f"\n{'=' * 50}")
|
|
154
|
-
print(f"Example {i}: {name}")
|
|
155
|
-
print("=" * 50)
|
|
156
|
-
await func()
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if __name__ == "__main__":
|
|
160
|
-
asyncio.run(main())
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
4
|
-
|
|
5
|
-
from codexed.models import HttpMcpServer, StdioMcpServer
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from codexed.models import McpServerConfig
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def kebab_to_camel(s: str) -> str:
|
|
13
|
-
"""Convert kebab-case to camelCase."""
|
|
14
|
-
parts = s.split("-")
|
|
15
|
-
return parts[0] + "".join(p.capitalize() for p in parts[1:])
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def mcp_config_to_toml_inline(name: str, config: McpServerConfig) -> str:
|
|
19
|
-
"""Convert MCP server config to TOML inline table format."""
|
|
20
|
-
match config:
|
|
21
|
-
case StdioMcpServer(command=command, args=args, env=env, enabled=enabled):
|
|
22
|
-
# Build stdio config
|
|
23
|
-
parts = [f'command = "{command}"']
|
|
24
|
-
if args:
|
|
25
|
-
args_str = ", ".join(f'"{arg}"' for arg in args)
|
|
26
|
-
parts.append(f"args = [{args_str}]")
|
|
27
|
-
if env:
|
|
28
|
-
# env as inline table
|
|
29
|
-
env_items = ", ".join(f'{k} = "{v}"' for k, v in env.items())
|
|
30
|
-
parts.append(f"env = {{{env_items}}}")
|
|
31
|
-
if not enabled:
|
|
32
|
-
parts.append("enabled = false")
|
|
33
|
-
return f"mcp_servers.{name}={{{', '.join(parts)}}}"
|
|
34
|
-
|
|
35
|
-
case HttpMcpServer(
|
|
36
|
-
url=url,
|
|
37
|
-
bearer_token_env_var=bearer_token_env_var,
|
|
38
|
-
http_headers=http_headers,
|
|
39
|
-
enabled=enabled,
|
|
40
|
-
):
|
|
41
|
-
# Build HTTP config
|
|
42
|
-
parts = [f'url = "{url}"']
|
|
43
|
-
if bearer_token_env_var:
|
|
44
|
-
parts.append(f'bearer_token_env_var = "{bearer_token_env_var}"')
|
|
45
|
-
if http_headers:
|
|
46
|
-
# headers as inline table
|
|
47
|
-
headers_items = ", ".join(f'{k} = "{v}"' for k, v in http_headers.items())
|
|
48
|
-
parts.append(f"http_headers = {{{headers_items}}}")
|
|
49
|
-
if not enabled:
|
|
50
|
-
parts.append("enabled = false")
|
|
51
|
-
return f"mcp_servers.{name}={{{', '.join(parts)}}}"
|
|
52
|
-
case _:
|
|
53
|
-
raise ValueError(f"Unsupported MCP server config type: {type(config)}")
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"""MCP server configuration models."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from pydantic import BaseModel
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class StdioMcpServer(BaseModel):
|
|
9
|
-
"""MCP server running as a subprocess via stdio transport."""
|
|
10
|
-
|
|
11
|
-
command: str
|
|
12
|
-
args: list[str] = []
|
|
13
|
-
env: dict[str, str] | None = None
|
|
14
|
-
enabled: bool = True
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class HttpMcpServer(BaseModel):
|
|
18
|
-
"""MCP server accessible via HTTP/SSE transport."""
|
|
19
|
-
|
|
20
|
-
url: str
|
|
21
|
-
bearer_token_env_var: str | None = None
|
|
22
|
-
http_headers: dict[str, str] | None = None
|
|
23
|
-
enabled: bool = True
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
McpServerConfig = StdioMcpServer | HttpMcpServer
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|