codexed 0.1.3__tar.gz → 0.1.4__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.1.3 → codexed-0.1.4}/PKG-INFO +1 -1
- {codexed-0.1.3 → codexed-0.1.4}/pyproject.toml +5 -4
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/__init__.py +1 -2
- codexed-0.1.4/src/codexed/client/__init__.py +7 -0
- {codexed-0.1.3/src/codexed → codexed-0.1.4/src/codexed/client}/client.py +11 -181
- codexed-0.1.4/src/codexed/client/fs.py +158 -0
- codexed-0.1.4/src/codexed/helpers.py +46 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/event_data.py +5 -5
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/events.py +5 -5
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/misc.py +5 -4
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/request_params.py +52 -38
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/responses.py +3 -3
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/thread_item.py +5 -5
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/thread_status.py +1 -1
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/transport.py +9 -17
- codexed-0.1.3/src/codexed/helpers.py +0 -7
- {codexed-0.1.3 → codexed-0.1.4}/LICENSE +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/README.md +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/README.md +0 -0
- {codexed-0.1.3/src/codexed → codexed-0.1.4/src/codexed/client}/session.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/exceptions.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/log.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/__init__.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/base.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/codex_types.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/command_action.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/fuzzy_search.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/hooks.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/mcp_server.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/realtime.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/response_item.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/terminal.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/token_usage.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/tool_config.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/user_input.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/models/web_search.py +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/py.typed +0 -0
- {codexed-0.1.3 → codexed-0.1.4}/src/codexed/request_handlers.py +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[project]
|
|
4
4
|
name = "codexed"
|
|
5
|
-
version = "0.1.
|
|
5
|
+
version = "0.1.4"
|
|
6
6
|
description = "Alternative codex app-server client"
|
|
7
7
|
readme = "README.md"
|
|
8
8
|
requires-python = ">=3.13"
|
|
@@ -35,9 +35,6 @@ dependencies = [
|
|
|
35
35
|
# Only add below (Copier)
|
|
36
36
|
]
|
|
37
37
|
|
|
38
|
-
[project.optional-dependencies]
|
|
39
|
-
websocket = ["websockets>=13.0"]
|
|
40
|
-
|
|
41
38
|
[project.urls]
|
|
42
39
|
"Code coverage" = "https://app.codecov.io/gh/phil65/codexed"
|
|
43
40
|
Discussions = "https://github.com/phil65/codexed/discussions"
|
|
@@ -45,6 +42,9 @@ Documentation = "https://phil65.github.io/codexed/"
|
|
|
45
42
|
Issues = "https://github.com/phil65/codexed/issues"
|
|
46
43
|
Source = "https://github.com/phil65/codexed"
|
|
47
44
|
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
websocket = ["websockets>=13.0"]
|
|
47
|
+
|
|
48
48
|
[dependency-groups]
|
|
49
49
|
dev = [
|
|
50
50
|
"devtools",
|
|
@@ -242,6 +242,7 @@ runtime-evaluated-base-classes = [
|
|
|
242
242
|
"sqlalchemy.orm.DeclarativeBase",
|
|
243
243
|
"schemez.Schema",
|
|
244
244
|
"sqlmodel.SQLModel",
|
|
245
|
+
"codexed.models.base.CodexBaseModel"
|
|
245
246
|
]
|
|
246
247
|
runtime-evaluated-decorators = [
|
|
247
248
|
"pydantic.validate_call",
|
|
@@ -17,8 +17,7 @@ __license__ = "MIT"
|
|
|
17
17
|
__url__ = "https://github.com/phil65/codexed"
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
from codexed.client import CodexClient
|
|
21
|
-
from codexed.session import Session
|
|
20
|
+
from codexed.client import CodexClient, Session
|
|
22
21
|
from codexed.exceptions import (
|
|
23
22
|
CodexError,
|
|
24
23
|
CodexProcessError,
|
|
@@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Any, assert_never
|
|
|
10
10
|
|
|
11
11
|
from pydantic import BaseModel, TypeAdapter
|
|
12
12
|
|
|
13
|
+
from codexed.client.fs import CodexFS
|
|
13
14
|
from codexed.exceptions import (
|
|
14
15
|
CodexProcessError,
|
|
15
16
|
CodexRequestError,
|
|
@@ -17,7 +18,7 @@ from codexed.exceptions import (
|
|
|
17
18
|
TurnFailedError,
|
|
18
19
|
map_jsonrpc_error,
|
|
19
20
|
)
|
|
20
|
-
from codexed.helpers import kebab_to_camel
|
|
21
|
+
from codexed.helpers import kebab_to_camel, merge_config
|
|
21
22
|
from codexed.models import (
|
|
22
23
|
AppsListParams,
|
|
23
24
|
AppsListResponse,
|
|
@@ -39,19 +40,6 @@ from codexed.models import (
|
|
|
39
40
|
ExternalAgentConfigImportParams,
|
|
40
41
|
FeedbackUploadParams,
|
|
41
42
|
FeedbackUploadResponse,
|
|
42
|
-
FsCopyParams,
|
|
43
|
-
FsCreateDirectoryParams,
|
|
44
|
-
FsGetMetadataParams,
|
|
45
|
-
FsGetMetadataResponse,
|
|
46
|
-
FsReadDirectoryParams,
|
|
47
|
-
FsReadDirectoryResponse,
|
|
48
|
-
FsReadFileParams,
|
|
49
|
-
FsReadFileResponse,
|
|
50
|
-
FsRemoveParams,
|
|
51
|
-
FsUnwatchParams,
|
|
52
|
-
FsWatchParams,
|
|
53
|
-
FsWatchResponse,
|
|
54
|
-
FsWriteFileParams,
|
|
55
43
|
GetAccountParams,
|
|
56
44
|
GetAccountRateLimitsResponse,
|
|
57
45
|
GetAccountResponse,
|
|
@@ -106,7 +94,6 @@ from codexed.models import (
|
|
|
106
94
|
UserInputText,
|
|
107
95
|
codex_event_adapter,
|
|
108
96
|
)
|
|
109
|
-
from codexed.models.tool_config import tools_to_config_dict
|
|
110
97
|
from codexed.request_handlers import (
|
|
111
98
|
SERVER_REQUEST_COMMAND_APPROVAL,
|
|
112
99
|
SERVER_REQUEST_DYNAMIC_TOOL_CALL,
|
|
@@ -123,6 +110,7 @@ from codexed.transport import StdioTransport
|
|
|
123
110
|
if TYPE_CHECKING:
|
|
124
111
|
from typing import Self
|
|
125
112
|
|
|
113
|
+
from codexed.client.session import Session
|
|
126
114
|
from codexed.models import (
|
|
127
115
|
AppInfo,
|
|
128
116
|
ApprovalPolicy,
|
|
@@ -132,7 +120,6 @@ if TYPE_CHECKING:
|
|
|
132
120
|
ConfigEdit,
|
|
133
121
|
ExperimentalFeature,
|
|
134
122
|
ExternalAgentConfigMigrationItem,
|
|
135
|
-
FsReadDirectoryEntry,
|
|
136
123
|
McpServerConfig,
|
|
137
124
|
MergeStrategy,
|
|
138
125
|
ModelData,
|
|
@@ -159,7 +146,6 @@ if TYPE_CHECKING:
|
|
|
159
146
|
ServerRequestHandler,
|
|
160
147
|
UserInputHandler,
|
|
161
148
|
)
|
|
162
|
-
from codexed.session import Session
|
|
163
149
|
from codexed.transport import Transport
|
|
164
150
|
|
|
165
151
|
logger = logging.getLogger(__name__)
|
|
@@ -217,7 +203,7 @@ class CodexClient:
|
|
|
217
203
|
self._transport = transport
|
|
218
204
|
else:
|
|
219
205
|
self._transport = StdioTransport(
|
|
220
|
-
|
|
206
|
+
command=codex_command,
|
|
221
207
|
profile=profile,
|
|
222
208
|
env_vars=env_vars,
|
|
223
209
|
mcp_servers=mcp_servers,
|
|
@@ -231,6 +217,7 @@ class CodexClient:
|
|
|
231
217
|
self._mcp_elicitation_enabled = on_mcp_elicitation is not None
|
|
232
218
|
self._mcp_elicitation_for_approvals = mcp_elicitation_for_approvals
|
|
233
219
|
self._server_request_handlers: dict[str, ServerRequestHandler] = {}
|
|
220
|
+
self.fs = CodexFS(self)
|
|
234
221
|
if on_approval:
|
|
235
222
|
self.register_handler(SERVER_REQUEST_COMMAND_APPROVAL, on_approval) # type: ignore[arg-type]
|
|
236
223
|
self.register_handler(SERVER_REQUEST_FILE_CHANGE_APPROVAL, on_approval) # type: ignore[arg-type]
|
|
@@ -292,35 +279,6 @@ class CodexClient:
|
|
|
292
279
|
# Thread lifecycle methods
|
|
293
280
|
# ========================================================================
|
|
294
281
|
|
|
295
|
-
@staticmethod
|
|
296
|
-
def _merge_config(
|
|
297
|
-
config: dict[str, Any] | None,
|
|
298
|
-
tools: list[ToolConfig] | None,
|
|
299
|
-
code_mode: bool | None,
|
|
300
|
-
mcp_servers: Mapping[str, McpServerConfig] | None = None,
|
|
301
|
-
mcp_elicitation_for_approvals: bool = False,
|
|
302
|
-
) -> dict[str, Any] | None:
|
|
303
|
-
"""Merge tools, code_mode, and mcp_servers into a config dict."""
|
|
304
|
-
merged = dict(config) if config else {}
|
|
305
|
-
if code_mode is not None:
|
|
306
|
-
merged.setdefault("features", {})["code_mode"] = code_mode
|
|
307
|
-
merged.setdefault("features", {})["codex_hooks"] = True
|
|
308
|
-
merged.setdefault("features", {})["realtime_conversation"] = True
|
|
309
|
-
if mcp_elicitation_for_approvals:
|
|
310
|
-
merged.setdefault("features", {})["tool_call_mcp_elicitation"] = True
|
|
311
|
-
if tools is not None:
|
|
312
|
-
tool_config = tools_to_config_dict(tools)
|
|
313
|
-
for key, value in tool_config.items():
|
|
314
|
-
if key not in merged:
|
|
315
|
-
merged[key] = value
|
|
316
|
-
elif isinstance(value, dict) and isinstance(merged[key], dict):
|
|
317
|
-
merged[key] = {**value, **merged[key]}
|
|
318
|
-
if mcp_servers:
|
|
319
|
-
servers = merged.setdefault("mcp_servers", {})
|
|
320
|
-
for name, srv in mcp_servers.items():
|
|
321
|
-
servers.setdefault(name, srv.model_dump(exclude_none=True))
|
|
322
|
-
return merged or None
|
|
323
|
-
|
|
324
282
|
async def thread_start(
|
|
325
283
|
self,
|
|
326
284
|
*,
|
|
@@ -363,7 +321,7 @@ class CodexClient:
|
|
|
363
321
|
Returns:
|
|
364
322
|
Session wrapping the new thread
|
|
365
323
|
"""
|
|
366
|
-
from codexed.session import Session
|
|
324
|
+
from codexed.client.session import Session
|
|
367
325
|
|
|
368
326
|
params = ThreadStartParams(
|
|
369
327
|
cwd=cwd,
|
|
@@ -373,7 +331,7 @@ class CodexClient:
|
|
|
373
331
|
developer_instructions=developer_instructions,
|
|
374
332
|
approval_policy=approval_policy,
|
|
375
333
|
sandbox=sandbox,
|
|
376
|
-
config=
|
|
334
|
+
config=merge_config(
|
|
377
335
|
config,
|
|
378
336
|
tools,
|
|
379
337
|
code_mode,
|
|
@@ -428,9 +386,9 @@ class CodexClient:
|
|
|
428
386
|
Returns:
|
|
429
387
|
Session wrapping the resumed thread
|
|
430
388
|
"""
|
|
431
|
-
from codexed.session import Session
|
|
389
|
+
from codexed.client.session import Session
|
|
432
390
|
|
|
433
|
-
cfg =
|
|
391
|
+
cfg = merge_config(
|
|
434
392
|
config,
|
|
435
393
|
tools,
|
|
436
394
|
code_mode,
|
|
@@ -496,9 +454,9 @@ class CodexClient:
|
|
|
496
454
|
Returns:
|
|
497
455
|
Session wrapping the new forked thread
|
|
498
456
|
"""
|
|
499
|
-
from codexed.session import Session
|
|
457
|
+
from codexed.client.session import Session
|
|
500
458
|
|
|
501
|
-
cfg =
|
|
459
|
+
cfg = merge_config(
|
|
502
460
|
config,
|
|
503
461
|
tools,
|
|
504
462
|
code_mode,
|
|
@@ -1027,134 +985,6 @@ class CodexClient:
|
|
|
1027
985
|
result = await self._send_request("command/exec", params)
|
|
1028
986
|
return CommandExecResponse.model_validate(result)
|
|
1029
987
|
|
|
1030
|
-
# ========================================================================
|
|
1031
|
-
# Filesystem methods
|
|
1032
|
-
# ========================================================================
|
|
1033
|
-
|
|
1034
|
-
async def fs_read_file(self, path: str) -> FsReadFileResponse:
|
|
1035
|
-
"""Read a file from the host filesystem.
|
|
1036
|
-
|
|
1037
|
-
Args:
|
|
1038
|
-
path: Absolute path to read.
|
|
1039
|
-
|
|
1040
|
-
Returns:
|
|
1041
|
-
FsReadFileResponse with base64-encoded file contents.
|
|
1042
|
-
"""
|
|
1043
|
-
params = FsReadFileParams(path=path)
|
|
1044
|
-
result = await self._send_request("fs/readFile", params)
|
|
1045
|
-
return FsReadFileResponse.model_validate(result)
|
|
1046
|
-
|
|
1047
|
-
async def fs_write_file(self, path: str, data_base64: str) -> None:
|
|
1048
|
-
"""Write a file on the host filesystem.
|
|
1049
|
-
|
|
1050
|
-
Args:
|
|
1051
|
-
path: Absolute path to write.
|
|
1052
|
-
data_base64: File contents encoded as base64.
|
|
1053
|
-
"""
|
|
1054
|
-
params = FsWriteFileParams(path=path, data_base64=data_base64)
|
|
1055
|
-
await self._send_request("fs/writeFile", params)
|
|
1056
|
-
|
|
1057
|
-
async def fs_create_directory(self, path: str, *, recursive: bool | None = None) -> None:
|
|
1058
|
-
"""Create a directory on the host filesystem.
|
|
1059
|
-
|
|
1060
|
-
Args:
|
|
1061
|
-
path: Absolute directory path to create.
|
|
1062
|
-
recursive: Whether to create parent directories. Defaults to True server-side.
|
|
1063
|
-
"""
|
|
1064
|
-
params = FsCreateDirectoryParams(path=path, recursive=recursive)
|
|
1065
|
-
await self._send_request("fs/createDirectory", params)
|
|
1066
|
-
|
|
1067
|
-
async def fs_get_metadata(self, path: str) -> FsGetMetadataResponse:
|
|
1068
|
-
"""Get metadata for an absolute path.
|
|
1069
|
-
|
|
1070
|
-
Args:
|
|
1071
|
-
path: Absolute path to inspect.
|
|
1072
|
-
|
|
1073
|
-
Returns:
|
|
1074
|
-
FsGetMetadataResponse with isDirectory, isFile, and timestamps.
|
|
1075
|
-
"""
|
|
1076
|
-
params = FsGetMetadataParams(path=path)
|
|
1077
|
-
result = await self._send_request("fs/getMetadata", params)
|
|
1078
|
-
return FsGetMetadataResponse.model_validate(result)
|
|
1079
|
-
|
|
1080
|
-
async def fs_read_directory(
|
|
1081
|
-
self,
|
|
1082
|
-
path: str,
|
|
1083
|
-
*,
|
|
1084
|
-
recursive: bool = False,
|
|
1085
|
-
) -> list[FsReadDirectoryEntry]:
|
|
1086
|
-
"""List child entries for a directory.
|
|
1087
|
-
|
|
1088
|
-
Args:
|
|
1089
|
-
path: Absolute directory path to read.
|
|
1090
|
-
recursive: If True, recursively list all descendant entries.
|
|
1091
|
-
|
|
1092
|
-
Returns:
|
|
1093
|
-
List of directory entries with fileName, isDirectory, isFile.
|
|
1094
|
-
"""
|
|
1095
|
-
params = FsReadDirectoryParams(path=path)
|
|
1096
|
-
result = await self._send_request("fs/readDirectory", params)
|
|
1097
|
-
entries = FsReadDirectoryResponse.model_validate(result).entries
|
|
1098
|
-
if not recursive:
|
|
1099
|
-
return entries
|
|
1100
|
-
all_entries = list(entries)
|
|
1101
|
-
for entry in entries:
|
|
1102
|
-
if entry.is_directory:
|
|
1103
|
-
sub_path = f"{path.rstrip('/')}/{entry.file_name}"
|
|
1104
|
-
sub_entries = await self.fs_read_directory(sub_path, recursive=True)
|
|
1105
|
-
all_entries.extend(sub_entries)
|
|
1106
|
-
return all_entries
|
|
1107
|
-
|
|
1108
|
-
async def fs_remove(
|
|
1109
|
-
self,
|
|
1110
|
-
path: str,
|
|
1111
|
-
*,
|
|
1112
|
-
recursive: bool | None = None,
|
|
1113
|
-
force: bool | None = None,
|
|
1114
|
-
) -> None:
|
|
1115
|
-
"""Remove a file or directory from the host filesystem.
|
|
1116
|
-
|
|
1117
|
-
Args:
|
|
1118
|
-
path: Absolute path to remove.
|
|
1119
|
-
recursive: Whether to recurse into directories. Defaults to True server-side.
|
|
1120
|
-
force: Whether to ignore missing paths. Defaults to True server-side.
|
|
1121
|
-
"""
|
|
1122
|
-
params = FsRemoveParams(path=path, recursive=recursive, force=force)
|
|
1123
|
-
await self._send_request("fs/remove", params)
|
|
1124
|
-
|
|
1125
|
-
async def fs_copy(self, source: str, destination: str, *, recursive: bool = False) -> None:
|
|
1126
|
-
"""Copy a file or directory tree on the host filesystem.
|
|
1127
|
-
|
|
1128
|
-
Args:
|
|
1129
|
-
source: Absolute source path.
|
|
1130
|
-
destination: Absolute destination path.
|
|
1131
|
-
recursive: Required for directory copies; ignored for file copies.
|
|
1132
|
-
"""
|
|
1133
|
-
params = FsCopyParams(source_path=source, destination_path=destination, recursive=recursive)
|
|
1134
|
-
await self._send_request("fs/copy", params)
|
|
1135
|
-
|
|
1136
|
-
async def fs_watch(self, path: str) -> FsWatchResponse:
|
|
1137
|
-
"""Start filesystem watch notifications for an absolute path.
|
|
1138
|
-
|
|
1139
|
-
Args:
|
|
1140
|
-
path: Absolute file or directory path to watch.
|
|
1141
|
-
|
|
1142
|
-
Returns:
|
|
1143
|
-
FsWatchResponse with watch_id and canonicalized path.
|
|
1144
|
-
"""
|
|
1145
|
-
params = FsWatchParams(path=path)
|
|
1146
|
-
result = await self._send_request("fs/watch", params)
|
|
1147
|
-
return FsWatchResponse.model_validate(result)
|
|
1148
|
-
|
|
1149
|
-
async def fs_unwatch(self, watch_id: str) -> None:
|
|
1150
|
-
"""Stop filesystem watch notifications for a prior watch.
|
|
1151
|
-
|
|
1152
|
-
Args:
|
|
1153
|
-
watch_id: Watch identifier returned by fs_watch.
|
|
1154
|
-
"""
|
|
1155
|
-
params = FsUnwatchParams(watch_id=watch_id)
|
|
1156
|
-
await self._send_request("fs/unwatch", params)
|
|
1157
|
-
|
|
1158
988
|
# ========================================================================
|
|
1159
989
|
# MCP server methods
|
|
1160
990
|
# ========================================================================
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Codex app-server client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from codexed.models import (
|
|
9
|
+
FsCopyParams,
|
|
10
|
+
FsCreateDirectoryParams,
|
|
11
|
+
FsGetMetadataParams,
|
|
12
|
+
FsGetMetadataResponse,
|
|
13
|
+
FsReadDirectoryParams,
|
|
14
|
+
FsReadDirectoryResponse,
|
|
15
|
+
FsReadFileParams,
|
|
16
|
+
FsReadFileResponse,
|
|
17
|
+
FsRemoveParams,
|
|
18
|
+
FsUnwatchParams,
|
|
19
|
+
FsWatchParams,
|
|
20
|
+
FsWatchResponse,
|
|
21
|
+
FsWriteFileParams,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from codexed.client import CodexClient
|
|
27
|
+
from codexed.models import FsReadDirectoryEntry
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class CodexFS:
|
|
33
|
+
def __init__(self, client: CodexClient):
|
|
34
|
+
self._client = client
|
|
35
|
+
|
|
36
|
+
async def read_file(self, path: str) -> FsReadFileResponse:
|
|
37
|
+
"""Read a file from the host filesystem.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
path: Absolute path to read.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
FsReadFileResponse with base64-encoded file contents.
|
|
44
|
+
"""
|
|
45
|
+
params = FsReadFileParams(path=path)
|
|
46
|
+
result = await self._client._send_request("fs/readFile", params)
|
|
47
|
+
return FsReadFileResponse.model_validate(result)
|
|
48
|
+
|
|
49
|
+
async def write_file(self, path: str, data_base64: str) -> None:
|
|
50
|
+
"""Write a file on the host filesystem.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
path: Absolute path to write.
|
|
54
|
+
data_base64: File contents encoded as base64.
|
|
55
|
+
"""
|
|
56
|
+
params = FsWriteFileParams(path=path, data_base64=data_base64)
|
|
57
|
+
await self._client._send_request("fs/writeFile", params)
|
|
58
|
+
|
|
59
|
+
async def create_directory(self, path: str, *, recursive: bool | None = None) -> None:
|
|
60
|
+
"""Create a directory on the host filesystem.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
path: Absolute directory path to create.
|
|
64
|
+
recursive: Whether to create parent directories. Defaults to True server-side.
|
|
65
|
+
"""
|
|
66
|
+
params = FsCreateDirectoryParams(path=path, recursive=recursive)
|
|
67
|
+
await self._client._send_request("fs/createDirectory", params)
|
|
68
|
+
|
|
69
|
+
async def get_metadata(self, path: str) -> FsGetMetadataResponse:
|
|
70
|
+
"""Get metadata for an absolute path.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
path: Absolute path to inspect.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
FsGetMetadataResponse with isDirectory, isFile, and timestamps.
|
|
77
|
+
"""
|
|
78
|
+
params = FsGetMetadataParams(path=path)
|
|
79
|
+
result = await self._client._send_request("fs/getMetadata", params)
|
|
80
|
+
return FsGetMetadataResponse.model_validate(result)
|
|
81
|
+
|
|
82
|
+
async def read_directory(
|
|
83
|
+
self,
|
|
84
|
+
path: str,
|
|
85
|
+
*,
|
|
86
|
+
recursive: bool = False,
|
|
87
|
+
) -> list[FsReadDirectoryEntry]:
|
|
88
|
+
"""List child entries for a directory.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
path: Absolute directory path to read.
|
|
92
|
+
recursive: If True, recursively list all descendant entries.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
List of directory entries with fileName, isDirectory, isFile.
|
|
96
|
+
"""
|
|
97
|
+
params = FsReadDirectoryParams(path=path)
|
|
98
|
+
result = await self._client._send_request("fs/readDirectory", params)
|
|
99
|
+
entries = FsReadDirectoryResponse.model_validate(result).entries
|
|
100
|
+
if not recursive:
|
|
101
|
+
return entries
|
|
102
|
+
all_entries = list(entries)
|
|
103
|
+
for entry in entries:
|
|
104
|
+
if entry.is_directory:
|
|
105
|
+
sub_path = f"{path.rstrip('/')}/{entry.file_name}"
|
|
106
|
+
sub_entries = await self.read_directory(sub_path, recursive=True)
|
|
107
|
+
all_entries.extend(sub_entries)
|
|
108
|
+
return all_entries
|
|
109
|
+
|
|
110
|
+
async def remove(
|
|
111
|
+
self,
|
|
112
|
+
path: str,
|
|
113
|
+
*,
|
|
114
|
+
recursive: bool | None = None,
|
|
115
|
+
force: bool | None = None,
|
|
116
|
+
) -> None:
|
|
117
|
+
"""Remove a file or directory from the host filesystem.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
path: Absolute path to remove.
|
|
121
|
+
recursive: Whether to recurse into directories. Defaults to True server-side.
|
|
122
|
+
force: Whether to ignore missing paths. Defaults to True server-side.
|
|
123
|
+
"""
|
|
124
|
+
params = FsRemoveParams(path=path, recursive=recursive, force=force)
|
|
125
|
+
await self._client._send_request("fs/remove", params)
|
|
126
|
+
|
|
127
|
+
async def copy(self, source: str, destination: str, *, recursive: bool = False) -> None:
|
|
128
|
+
"""Copy a file or directory tree on the host filesystem.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
source: Absolute source path.
|
|
132
|
+
destination: Absolute destination path.
|
|
133
|
+
recursive: Required for directory copies; ignored for file copies.
|
|
134
|
+
"""
|
|
135
|
+
params = FsCopyParams(source_path=source, destination_path=destination, recursive=recursive)
|
|
136
|
+
await self._client._send_request("fs/copy", params)
|
|
137
|
+
|
|
138
|
+
async def watch(self, path: str) -> FsWatchResponse:
|
|
139
|
+
"""Start filesystem watch notifications for an absolute path.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
path: Absolute file or directory path to watch.
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
FsWatchResponse with watch_id and canonicalized path.
|
|
146
|
+
"""
|
|
147
|
+
params = FsWatchParams(path=path)
|
|
148
|
+
result = await self._client._send_request("fs/watch", params)
|
|
149
|
+
return FsWatchResponse.model_validate(result)
|
|
150
|
+
|
|
151
|
+
async def unwatch(self, watch_id: str) -> None:
|
|
152
|
+
"""Stop filesystem watch notifications for a prior watch.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
watch_id: Watch identifier returned by fs_watch.
|
|
156
|
+
"""
|
|
157
|
+
params = FsUnwatchParams(watch_id=watch_id)
|
|
158
|
+
await self._client._send_request("fs/unwatch", params)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
|
|
5
|
+
from codexed.models.tool_config import tools_to_config_dict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from collections.abc import Mapping
|
|
10
|
+
|
|
11
|
+
from codexed.models import McpServerConfig, ToolConfig
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def kebab_to_camel(s: str) -> str:
|
|
15
|
+
"""Convert kebab-case to camelCase."""
|
|
16
|
+
parts = s.split("-")
|
|
17
|
+
return parts[0] + "".join(p.capitalize() for p in parts[1:])
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def merge_config(
|
|
21
|
+
config: dict[str, Any] | None,
|
|
22
|
+
tools: list[ToolConfig] | None,
|
|
23
|
+
code_mode: bool | None,
|
|
24
|
+
mcp_servers: Mapping[str, McpServerConfig] | None = None,
|
|
25
|
+
mcp_elicitation_for_approvals: bool = False,
|
|
26
|
+
) -> dict[str, Any] | None:
|
|
27
|
+
"""Merge tools, code_mode, and mcp_servers into a config dict."""
|
|
28
|
+
merged = dict(config) if config else {}
|
|
29
|
+
if code_mode is not None:
|
|
30
|
+
merged.setdefault("features", {})["code_mode"] = code_mode
|
|
31
|
+
merged.setdefault("features", {})["codex_hooks"] = True
|
|
32
|
+
merged.setdefault("features", {})["realtime_conversation"] = True
|
|
33
|
+
if mcp_elicitation_for_approvals:
|
|
34
|
+
merged.setdefault("features", {})["tool_call_mcp_elicitation"] = True
|
|
35
|
+
if tools is not None:
|
|
36
|
+
tool_config = tools_to_config_dict(tools)
|
|
37
|
+
for key, value in tool_config.items():
|
|
38
|
+
if key not in merged:
|
|
39
|
+
merged[key] = value
|
|
40
|
+
elif isinstance(value, dict) and isinstance(merged[key], dict):
|
|
41
|
+
merged[key] = {**value, **merged[key]}
|
|
42
|
+
if mcp_servers:
|
|
43
|
+
servers = merged.setdefault("mcp_servers", {})
|
|
44
|
+
for name, srv in mcp_servers.items():
|
|
45
|
+
servers.setdefault(name, srv.model_dump(exclude_none=True))
|
|
46
|
+
return merged or None
|
|
@@ -3,8 +3,8 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import Any
|
|
4
4
|
|
|
5
5
|
from codexed.models.base import CodexBaseModel
|
|
6
|
-
from codexed.models.codex_types import ModelRerouteReason
|
|
7
|
-
from codexed.models.misc import (
|
|
6
|
+
from codexed.models.codex_types import ModelRerouteReason
|
|
7
|
+
from codexed.models.misc import (
|
|
8
8
|
AppInfo,
|
|
9
9
|
RateLimitSnapshot,
|
|
10
10
|
TextRange,
|
|
@@ -13,9 +13,9 @@ from codexed.models.misc import ( # noqa: TC001
|
|
|
13
13
|
TurnError,
|
|
14
14
|
TurnPlanStep,
|
|
15
15
|
)
|
|
16
|
-
from codexed.models.thread_item import ThreadItem
|
|
17
|
-
from codexed.models.thread_status import ThreadStatusValue
|
|
18
|
-
from codexed.models.token_usage import ThreadTokenUsage
|
|
16
|
+
from codexed.models.thread_item import ThreadItem
|
|
17
|
+
from codexed.models.thread_status import ThreadStatusValue
|
|
18
|
+
from codexed.models.token_usage import ThreadTokenUsage
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class TurnPlanUpdatedData(CodexBaseModel):
|
|
@@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, Annotated, Literal
|
|
|
11
11
|
from pydantic import Field, TypeAdapter
|
|
12
12
|
|
|
13
13
|
from codexed.models.base import CodexBaseModel
|
|
14
|
-
from codexed.models.event_data import (
|
|
14
|
+
from codexed.models.event_data import (
|
|
15
15
|
AccountLoginCompletedData,
|
|
16
16
|
AccountRateLimitsUpdatedData,
|
|
17
17
|
AccountUpdatedData,
|
|
@@ -53,12 +53,12 @@ from codexed.models.event_data import ( # noqa: TC001
|
|
|
53
53
|
TurnStartedData,
|
|
54
54
|
WindowsWorldWritableWarningData,
|
|
55
55
|
)
|
|
56
|
-
from codexed.models.fuzzy_search import (
|
|
56
|
+
from codexed.models.fuzzy_search import (
|
|
57
57
|
FuzzyFileSearchSessionCompletedData,
|
|
58
58
|
FuzzyFileSearchSessionUpdatedData,
|
|
59
59
|
)
|
|
60
|
-
from codexed.models.hooks import HookCompletedData, HookStartedData
|
|
61
|
-
from codexed.models.realtime import (
|
|
60
|
+
from codexed.models.hooks import HookCompletedData, HookStartedData
|
|
61
|
+
from codexed.models.realtime import (
|
|
62
62
|
RealtimeClosedData,
|
|
63
63
|
RealtimeErrorData,
|
|
64
64
|
RealtimeItemAddedData,
|
|
@@ -66,7 +66,7 @@ from codexed.models.realtime import ( # noqa: TC001
|
|
|
66
66
|
RealtimeStartedData,
|
|
67
67
|
RealtimeTranscriptUpdatedData,
|
|
68
68
|
)
|
|
69
|
-
from codexed.models.terminal import CommandExecOutputDeltaData
|
|
69
|
+
from codexed.models.terminal import CommandExecOutputDeltaData
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
if TYPE_CHECKING:
|
|
@@ -4,10 +4,11 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import TYPE_CHECKING, Any, Literal
|
|
6
6
|
|
|
7
|
+
from mcp.types import Annotations, Icon, ToolAnnotations
|
|
7
8
|
from pydantic import AnyUrl, Field
|
|
8
9
|
|
|
9
10
|
from codexed.models.base import CodexBaseModel
|
|
10
|
-
from codexed.models.codex_types import (
|
|
11
|
+
from codexed.models.codex_types import (
|
|
11
12
|
ExperimentalFeatureStage,
|
|
12
13
|
ExternalAgentConfigMigrationItemType,
|
|
13
14
|
InputModality,
|
|
@@ -22,12 +23,12 @@ from codexed.models.codex_types import ( # noqa: TC001
|
|
|
22
23
|
SkillApprovalDecision,
|
|
23
24
|
SkillScope,
|
|
24
25
|
)
|
|
25
|
-
from codexed.models.thread_item import ThreadItem
|
|
26
|
-
from codexed.models.thread_status import ThreadStatusValue
|
|
26
|
+
from codexed.models.thread_item import ThreadItem
|
|
27
|
+
from codexed.models.thread_status import ThreadStatusValue
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
if TYPE_CHECKING:
|
|
30
|
-
from mcp.types import
|
|
31
|
+
from mcp.types import Resource, ResourceTemplate, Tool
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
# Strict validation in tests to catch schema changes, lenient in production
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from collections.abc import Sequence
|
|
4
|
-
from typing import Annotated, Any, Literal, Self
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from typing import TYPE_CHECKING, Annotated, Any, Literal, Required, Self, TypedDict
|
|
5
5
|
|
|
6
|
-
import mcp.types
|
|
7
6
|
from pydantic import Discriminator, TypeAdapter
|
|
8
7
|
|
|
9
8
|
from codexed.models.base import CodexBaseModel
|
|
10
|
-
from codexed.models.codex_types import (
|
|
9
|
+
from codexed.models.codex_types import (
|
|
11
10
|
ApprovalDecision,
|
|
12
11
|
ApprovalPolicy,
|
|
13
12
|
CollaborationMode,
|
|
@@ -20,8 +19,8 @@ from codexed.models.codex_types import ( # noqa: TC001
|
|
|
20
19
|
ThreadSortKey,
|
|
21
20
|
ThreadSourceKind,
|
|
22
21
|
)
|
|
23
|
-
from codexed.models.command_action import CommandAction
|
|
24
|
-
from codexed.models.misc import (
|
|
22
|
+
from codexed.models.command_action import CommandAction
|
|
23
|
+
from codexed.models.misc import (
|
|
25
24
|
ClientInfo,
|
|
26
25
|
ConfigEdit,
|
|
27
26
|
ExecPolicyAmendment,
|
|
@@ -30,9 +29,13 @@ from codexed.models.misc import ( # noqa: TC001
|
|
|
30
29
|
NetworkPolicyAmendment,
|
|
31
30
|
ToolRequestUserInputQuestion,
|
|
32
31
|
)
|
|
33
|
-
from codexed.models.response_item import ResponseItem
|
|
34
|
-
from codexed.models.terminal import CommandExecTerminalSize
|
|
35
|
-
from codexed.models.user_input import UserInput
|
|
32
|
+
from codexed.models.response_item import ResponseItem
|
|
33
|
+
from codexed.models.terminal import CommandExecTerminalSize
|
|
34
|
+
from codexed.models.user_input import UserInput
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING:
|
|
38
|
+
from mcp.types import ElicitRequestFormParams, ElicitRequestURLParams
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
LoginType = Literal["apiKey", "chatgpt", "chatgptAuthTokens"]
|
|
@@ -533,33 +536,40 @@ class DynamicToolCallParams(CodexBaseModel):
|
|
|
533
536
|
arguments: Any
|
|
534
537
|
|
|
535
538
|
|
|
539
|
+
PersistOption = Literal["session", "always"]
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
class ToolApprovalParamDisplay(TypedDict):
|
|
543
|
+
"""A rendered tool parameter for display."""
|
|
544
|
+
|
|
545
|
+
name: str
|
|
546
|
+
value: Any
|
|
547
|
+
display_name: str
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
class ToolApprovalMeta(TypedDict, total=False):
|
|
551
|
+
"""Metadata for MCP tool approval requests."""
|
|
552
|
+
|
|
553
|
+
codex_approval_kind: Required[Literal["mcp_tool_call"]]
|
|
554
|
+
persist: PersistOption | list[PersistOption]
|
|
555
|
+
tool_title: str
|
|
556
|
+
tool_description: str
|
|
557
|
+
tool_params: dict[str, Any]
|
|
558
|
+
tool_params_display: list[ToolApprovalParamDisplay]
|
|
559
|
+
source: Literal["connector"]
|
|
560
|
+
connector_id: str
|
|
561
|
+
connector_name: str
|
|
562
|
+
connector_description: str
|
|
563
|
+
|
|
564
|
+
|
|
536
565
|
class _McpElicitationBase(CodexBaseModel):
|
|
537
566
|
"""Common fields for MCP elicitation requests."""
|
|
538
567
|
|
|
539
568
|
thread_id: str
|
|
540
569
|
turn_id: str | None = None
|
|
541
570
|
server_name: str
|
|
542
|
-
meta: Any | None = None
|
|
543
|
-
"""
|
|
544
|
-
|
|
545
|
-
For MCP tool approval requests (when ``tool_call_mcp_elicitation`` is enabled),
|
|
546
|
-
this contains:
|
|
547
|
-
|
|
548
|
-
- ``kind`` (str): Always ``"mcp_tool_call"`` for tool approvals.
|
|
549
|
-
- ``persist`` (str | list[str]): Allowed persistence options —
|
|
550
|
-
``"session"`` (remember for this session) and/or ``"always"``
|
|
551
|
-
(remember permanently).
|
|
552
|
-
- ``tool_title`` (str, optional): Human-readable tool name.
|
|
553
|
-
- ``tool_description`` (str, optional): Tool description.
|
|
554
|
-
- ``tool_params`` (dict, optional): The tool call arguments.
|
|
555
|
-
- ``tool_params_display`` (list, optional): Rendered parameter display.
|
|
556
|
-
- ``source`` (str, optional): ``"connector"`` if from a ChatGPT App.
|
|
557
|
-
- ``connector_id``, ``connector_name``, ``connector_description``
|
|
558
|
-
(str, optional): Connector details when source is ``"connector"``.
|
|
559
|
-
|
|
560
|
-
For regular MCP server elicitations (auth flows etc.), the meta content
|
|
561
|
-
is defined by the MCP server itself.
|
|
562
|
-
"""
|
|
571
|
+
meta: ToolApprovalMeta | Any | None = None
|
|
572
|
+
"""Approval metadata when ``tool_call_mcp_elicitation`` is enabled; otherwise server-defined."""
|
|
563
573
|
message: str
|
|
564
574
|
|
|
565
575
|
|
|
@@ -569,19 +579,21 @@ class McpElicitationFormParams(_McpElicitationBase):
|
|
|
569
579
|
mode: Literal["form"] = "form"
|
|
570
580
|
requested_schema: dict[str, Any]
|
|
571
581
|
|
|
572
|
-
def to_mcp(self) ->
|
|
573
|
-
|
|
582
|
+
def to_mcp(self) -> ElicitRequestFormParams:
|
|
583
|
+
from mcp.types import ElicitRequestFormParams, RequestParams
|
|
584
|
+
|
|
585
|
+
params = ElicitRequestFormParams(
|
|
574
586
|
message=self.message,
|
|
575
587
|
requestedSchema=self.requested_schema,
|
|
576
588
|
)
|
|
577
589
|
if self.meta is not None:
|
|
578
|
-
params.meta =
|
|
590
|
+
params.meta = RequestParams.Meta(**self.meta)
|
|
579
591
|
return params
|
|
580
592
|
|
|
581
593
|
@classmethod
|
|
582
594
|
def from_mcp(
|
|
583
595
|
cls,
|
|
584
|
-
params:
|
|
596
|
+
params: ElicitRequestFormParams,
|
|
585
597
|
thread_id: str,
|
|
586
598
|
server_name: str,
|
|
587
599
|
turn_id: str | None = None,
|
|
@@ -605,20 +617,22 @@ class McpElicitationUrlParams(_McpElicitationBase):
|
|
|
605
617
|
url: str
|
|
606
618
|
elicitation_id: str
|
|
607
619
|
|
|
608
|
-
def to_mcp(self) ->
|
|
609
|
-
|
|
620
|
+
def to_mcp(self) -> ElicitRequestURLParams:
|
|
621
|
+
from mcp.types import ElicitRequestURLParams, RequestParams
|
|
622
|
+
|
|
623
|
+
params = ElicitRequestURLParams(
|
|
610
624
|
message=self.message,
|
|
611
625
|
url=self.url,
|
|
612
626
|
elicitationId=self.elicitation_id,
|
|
613
627
|
)
|
|
614
628
|
if self.meta is not None:
|
|
615
|
-
params.meta =
|
|
629
|
+
params.meta = RequestParams.Meta(**self.meta)
|
|
616
630
|
return params
|
|
617
631
|
|
|
618
632
|
@classmethod
|
|
619
633
|
def from_mcp(
|
|
620
634
|
cls,
|
|
621
|
-
params:
|
|
635
|
+
params: ElicitRequestURLParams,
|
|
622
636
|
thread_id: str,
|
|
623
637
|
server_name: str,
|
|
624
638
|
turn_id: str | None = None,
|
|
@@ -5,7 +5,7 @@ from typing import Any, Literal
|
|
|
5
5
|
import mcp.types
|
|
6
6
|
|
|
7
7
|
from codexed.models.base import CodexBaseModel
|
|
8
|
-
from codexed.models.codex_types import (
|
|
8
|
+
from codexed.models.codex_types import (
|
|
9
9
|
ApprovalDecision,
|
|
10
10
|
AskForApproval,
|
|
11
11
|
ModeKind,
|
|
@@ -13,7 +13,7 @@ from codexed.models.codex_types import ( # noqa: TC001
|
|
|
13
13
|
SandboxPolicy,
|
|
14
14
|
WriteStatus,
|
|
15
15
|
)
|
|
16
|
-
from codexed.models.misc import (
|
|
16
|
+
from codexed.models.misc import (
|
|
17
17
|
AppInfo,
|
|
18
18
|
ConfigLayer,
|
|
19
19
|
ConfigLayerMetadata,
|
|
@@ -28,7 +28,7 @@ from codexed.models.misc import ( # noqa: TC001
|
|
|
28
28
|
Turn,
|
|
29
29
|
TurnData,
|
|
30
30
|
)
|
|
31
|
-
from codexed.models.thread_item import DynamicToolCallOutputContentItem
|
|
31
|
+
from codexed.models.thread_item import DynamicToolCallOutputContentItem
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
class CommandExecutionRequestApprovalResponse(CodexBaseModel):
|
|
@@ -2,11 +2,11 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import Any, Literal
|
|
4
4
|
|
|
5
|
-
from mcp.types import ContentBlock
|
|
5
|
+
from mcp.types import ContentBlock
|
|
6
6
|
from pydantic import Field
|
|
7
7
|
|
|
8
8
|
from codexed.models.base import CodexBaseModel
|
|
9
|
-
from codexed.models.codex_types import (
|
|
9
|
+
from codexed.models.codex_types import (
|
|
10
10
|
CollabAgentStatus,
|
|
11
11
|
CollabAgentTool,
|
|
12
12
|
CommandExecutionSource,
|
|
@@ -15,9 +15,9 @@ from codexed.models.codex_types import ( # noqa: TC001
|
|
|
15
15
|
PatchApplyStatus,
|
|
16
16
|
ToolCallStatus,
|
|
17
17
|
)
|
|
18
|
-
from codexed.models.command_action import CommandAction
|
|
19
|
-
from codexed.models.user_input import UserInput
|
|
20
|
-
from codexed.models.web_search import WebSearchAction
|
|
18
|
+
from codexed.models.command_action import CommandAction
|
|
19
|
+
from codexed.models.user_input import UserInput
|
|
20
|
+
from codexed.models.web_search import WebSearchAction
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
# ---------------------------------------------------------------------------
|
|
@@ -5,7 +5,7 @@ from typing import Literal
|
|
|
5
5
|
from pydantic import Field
|
|
6
6
|
|
|
7
7
|
from codexed.models.base import CodexBaseModel
|
|
8
|
-
from codexed.models.codex_types import ThreadActiveFlag
|
|
8
|
+
from codexed.models.codex_types import ThreadActiveFlag
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class ThreadStatusNotLoaded(CodexBaseModel):
|
|
@@ -9,7 +9,6 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import asyncio
|
|
11
11
|
import contextlib
|
|
12
|
-
import json
|
|
13
12
|
import logging
|
|
14
13
|
import os
|
|
15
14
|
from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
|
|
@@ -59,12 +58,12 @@ class StdioTransport:
|
|
|
59
58
|
|
|
60
59
|
def __init__(
|
|
61
60
|
self,
|
|
62
|
-
|
|
61
|
+
command: str,
|
|
63
62
|
profile: str | None = None,
|
|
64
63
|
env_vars: dict[str, str] | None = None,
|
|
65
64
|
mcp_servers: Mapping[str, McpServerConfig] | None = None,
|
|
66
65
|
) -> None:
|
|
67
|
-
self.
|
|
66
|
+
self._command = command
|
|
68
67
|
self._profile = profile
|
|
69
68
|
self._mcp_servers = dict(mcp_servers) if mcp_servers else {}
|
|
70
69
|
self._env_vars = env_vars or {}
|
|
@@ -75,7 +74,7 @@ class StdioTransport:
|
|
|
75
74
|
if self._process is not None:
|
|
76
75
|
return
|
|
77
76
|
|
|
78
|
-
cmd = [self.
|
|
77
|
+
cmd = [self._command, "app-server"]
|
|
79
78
|
if self._profile:
|
|
80
79
|
cmd.extend(["--profile", self._profile])
|
|
81
80
|
for server_name, server_config in self._mcp_servers.items():
|
|
@@ -92,7 +91,7 @@ class StdioTransport:
|
|
|
92
91
|
env={**os.environ, **self._env_vars},
|
|
93
92
|
)
|
|
94
93
|
except FileNotFoundError as exc:
|
|
95
|
-
raise CodexProcessError(f"Codex binary not found: {self.
|
|
94
|
+
raise CodexProcessError(f"Codex binary not found: {self._command}") from exc
|
|
96
95
|
except Exception as exc:
|
|
97
96
|
raise CodexProcessError(f"Failed to start Codex app-server: {exc}") from exc
|
|
98
97
|
|
|
@@ -112,7 +111,7 @@ class StdioTransport:
|
|
|
112
111
|
if self._process is None or self._process.stdin is None:
|
|
113
112
|
raise TransportClosedError("Not connected to Codex app-server")
|
|
114
113
|
async with self._writer_lock:
|
|
115
|
-
line =
|
|
114
|
+
line = anyenv.dump_json(message) + "\n"
|
|
116
115
|
self._process.stdin.write(line.encode())
|
|
117
116
|
await self._process.stdin.drain()
|
|
118
117
|
|
|
@@ -152,17 +151,10 @@ class WebSocketTransport:
|
|
|
152
151
|
self._writer_lock = asyncio.Lock()
|
|
153
152
|
|
|
154
153
|
async def start(self) -> None:
|
|
154
|
+
import websockets
|
|
155
|
+
|
|
155
156
|
if self._ws is not None:
|
|
156
157
|
return
|
|
157
|
-
try:
|
|
158
|
-
import websockets
|
|
159
|
-
except ImportError as exc:
|
|
160
|
-
msg = (
|
|
161
|
-
"WebSocketTransport requires the 'websockets' package. "
|
|
162
|
-
"Install it with: pip install codexed[websocket]"
|
|
163
|
-
)
|
|
164
|
-
raise ImportError(msg) from exc
|
|
165
|
-
|
|
166
158
|
headers = dict(self._extra_headers)
|
|
167
159
|
if self._auth_token:
|
|
168
160
|
headers["Authorization"] = f"Bearer {self._auth_token}"
|
|
@@ -180,7 +172,7 @@ class WebSocketTransport:
|
|
|
180
172
|
if self._ws is None:
|
|
181
173
|
raise TransportClosedError("WebSocket not connected")
|
|
182
174
|
async with self._writer_lock:
|
|
183
|
-
await self._ws.send(
|
|
175
|
+
await self._ws.send(anyenv.dump_json(message))
|
|
184
176
|
|
|
185
177
|
async def receive(self) -> dict[str, Any] | None:
|
|
186
178
|
if self._ws is None:
|
|
@@ -194,7 +186,7 @@ class WebSocketTransport:
|
|
|
194
186
|
raw = raw.strip()
|
|
195
187
|
if not raw or raw == "null":
|
|
196
188
|
return await self.receive()
|
|
197
|
-
return
|
|
189
|
+
return anyenv.load_json(raw, return_type=dict)
|
|
198
190
|
|
|
199
191
|
@property
|
|
200
192
|
def is_connected(self) -> bool:
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|