codexed 1.3.0__tar.gz → 1.3.1__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.
Files changed (35) hide show
  1. {codexed-1.3.0 → codexed-1.3.1}/PKG-INFO +1 -1
  2. {codexed-1.3.0 → codexed-1.3.1}/pyproject.toml +8 -19
  3. {codexed-1.3.0 → codexed-1.3.1}/pyproject.toml.orig +10 -12
  4. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/account.py +13 -3
  5. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/client.py +46 -15
  6. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/plugin.py +3 -1
  7. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/session.py +2 -2
  8. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/request_params.py +9 -1
  9. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/tool_config.py +1 -1
  10. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/request_handlers.py +6 -2
  11. {codexed-1.3.0 → codexed-1.3.1}/LICENSE +0 -0
  12. {codexed-1.3.0 → codexed-1.3.1}/README.md +0 -0
  13. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/README.md +0 -0
  14. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/__init__.py +0 -0
  15. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/__init__.py +0 -0
  16. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/dispatch.py +0 -0
  17. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/fs.py +0 -0
  18. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/marketplace.py +0 -0
  19. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/realtime.py +0 -0
  20. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/client/skills.py +0 -0
  21. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/exceptions.py +0 -0
  22. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/helpers.py +0 -0
  23. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/log.py +0 -0
  24. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/__init__.py +0 -0
  25. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/base.py +0 -0
  26. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/codex_types.py +0 -0
  27. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/event_data.py +0 -0
  28. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/events.py +0 -0
  29. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/mcp_server.py +0 -0
  30. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/misc.py +0 -0
  31. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/responses.py +0 -0
  32. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/thread_item.py +0 -0
  33. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/models/v2_protocol.py +0 -0
  34. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/py.typed +0 -0
  35. {codexed-1.3.0 → codexed-1.3.1}/src/codexed/transport.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codexed
3
- Version: 1.3.0
3
+ Version: 1.3.1
4
4
  Summary: Alternative codex app-server client
5
5
  Keywords:
6
6
  Author: Philipp Temminghoff
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codexed"
3
- version = "1.3.0"
3
+ version = "1.3.1"
4
4
  description = "Alternative codex app-server client"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -49,8 +49,8 @@ dev = [
49
49
  "devtools",
50
50
  "pyreadline3",
51
51
  "pytest",
52
- "pytest-cov",
53
52
  "pytest-asyncio>=1.5.0",
53
+ "pytest-cov",
54
54
  ]
55
55
  benchmark = ["pyinstrument"]
56
56
  docs = [
@@ -58,9 +58,9 @@ docs = [
58
58
  "mkdocs-mknodes",
59
59
  ]
60
60
  lint = [
61
- "mypy; python_version >= '3.14'",
62
- "mypy[faster-cache]; python_version < '3.14'",
61
+ "openai",
63
62
  "ruff",
63
+ "ty",
64
64
  ]
65
65
 
66
66
  [build-system]
@@ -88,21 +88,6 @@ allowed-commit-types = [
88
88
  ]
89
89
  docstring-style = "google"
90
90
 
91
- [tool.mypy]
92
- python_version = "3.13"
93
- disable_error_code = [
94
- "misc",
95
- "import",
96
- ]
97
- pretty = true
98
- check_untyped_defs = true
99
- exclude = [
100
- "venv/",
101
- ".venv/",
102
- "src/codexed/models/v2_protocol.py",
103
- ]
104
- plugins = ["pydantic.mypy"]
105
-
106
91
  [tool.pyright]
107
92
  venvPath = "."
108
93
  venv = ".venv"
@@ -261,12 +246,16 @@ max-complexity = 15
261
246
  preview = true
262
247
 
263
248
  [tool.ty.src]
249
+ include = ["src"]
264
250
  exclude = ["src/codexed/models/v2_protocol.py"]
265
251
 
266
252
  [tool.ty.environment]
267
253
  python-version = "3.13"
268
254
  python-platform = "all"
269
255
 
256
+ [tool.ty.rules]
257
+ incompatible-mutable-override = "ignore"
258
+
270
259
  [tool.uv]
271
260
  default-groups = [
272
261
  "dev",
@@ -2,7 +2,7 @@
2
2
 
3
3
  [project]
4
4
  name = "codexed"
5
- version = "1.3.0"
5
+ version = "1.3.1"
6
6
  description = "Alternative codex app-server client"
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.13"
@@ -51,9 +51,9 @@ dev = [
51
51
  "devtools",
52
52
  "pyreadline3",
53
53
  "pytest",
54
- "pytest-cov",
55
54
  # Only add below (Copier)
56
55
  "pytest-asyncio>=1.5.0",
56
+ "pytest-cov",
57
57
  ]
58
58
  benchmark = ["pyinstrument"]
59
59
  docs = [
@@ -62,9 +62,9 @@ docs = [
62
62
  # Only add below (Copier)
63
63
  ]
64
64
  lint = [
65
- "mypy; python_version >= '3.14'",
66
- "mypy[faster-cache]; python_version < '3.14'",
65
+ "openai", # type-only import (openai.types.responses) for ty
67
66
  "ruff",
67
+ "ty",
68
68
  # Only add below (Copier)
69
69
  ]
70
70
 
@@ -93,14 +93,6 @@ allowed-commit-types = [
93
93
  ]
94
94
  docstring-style = "google"
95
95
 
96
- [tool.mypy]
97
- python_version = "3.13"
98
- disable_error_code = ["misc", "import"]
99
- pretty = true
100
- check_untyped_defs = true
101
- exclude = ["venv/", ".venv/", "src/codexed/models/v2_protocol.py"]
102
- plugins = ["pydantic.mypy"]
103
-
104
96
  [tool.pyright]
105
97
  venvPath = "."
106
98
  venv = ".venv"
@@ -274,12 +266,18 @@ max-complexity = 15
274
266
  preview = true
275
267
 
276
268
  [tool.ty.src]
269
+ include = ["src"]
277
270
  exclude = ["src/codexed/models/v2_protocol.py"]
278
271
 
279
272
  [tool.ty.environment]
280
273
  python-version = "3.13"
281
274
  python-platform = "all"
282
275
 
276
+ [tool.ty.rules]
277
+ # Narrowing an overridden class attribute (e.g. pydantic discriminators,
278
+ # `Config` attributes) is an intentional pattern.
279
+ incompatible-mutable-override = "ignore"
280
+
283
281
  [tool.uv]
284
282
  default-groups = ["dev", "lint", "docs"]
285
283
 
@@ -21,7 +21,12 @@ from codexed.models import (
21
21
 
22
22
  if TYPE_CHECKING:
23
23
  from codexed.client import CodexClient
24
- from codexed.models import AddCreditsNudgeCreditType, AuthMode, CancelLoginAccountStatus
24
+ from codexed.models import (
25
+ AddCreditsNudgeCreditType,
26
+ AuthMode,
27
+ CancelLoginAccountStatus,
28
+ RateLimitSnapshot,
29
+ )
25
30
 
26
31
  logger = logging.getLogger(__name__)
27
32
 
@@ -29,6 +34,9 @@ logger = logging.getLogger(__name__)
29
34
  class CodexAccount:
30
35
  def __init__(self, client: CodexClient):
31
36
  self._client = client
37
+ self.rate_limits: RateLimitSnapshot | None = None
38
+ """Latest rate limits: from :meth:`rate_limits_read` and from the
39
+ ``account/rateLimits/updated`` notifications the server sends during turns."""
32
40
 
33
41
  async def read(self, *, refresh_token: bool = False) -> GetAccountResponse:
34
42
  """Read account information.
@@ -84,9 +92,11 @@ class CodexAccount:
84
92
  await self._client.dispatch.send_request("account/logout")
85
93
 
86
94
  async def rate_limits_read(self) -> GetAccountRateLimitsResponse:
87
- """Read account rate limits."""
95
+ """Read account rate limits (also updates :attr:`rate_limits`)."""
88
96
  result = await self._client.dispatch.send_request("account/rateLimits/read")
89
- return GetAccountRateLimitsResponse.model_validate(result)
97
+ response = GetAccountRateLimitsResponse.model_validate(result)
98
+ self.rate_limits = response.rate_limits
99
+ return response
90
100
 
91
101
  async def send_add_credits_nudge_email(self, credit_type: AddCreditsNudgeCreditType) -> None:
92
102
  """Send an add credits nudge email."""
@@ -3,7 +3,8 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
- from collections.abc import Mapping # noqa: TC003
6
+ from collections.abc import Awaitable, Callable, Mapping
7
+ import inspect
7
8
  import logging
8
9
  from typing import TYPE_CHECKING, Any
9
10
 
@@ -17,6 +18,7 @@ from codexed.client.plugin import CodexPlugin
17
18
  from codexed.client.skills import CodexSkills
18
19
  from codexed.helpers import merge_config
19
20
  from codexed.models import (
21
+ AccountRateLimitsUpdatedMessage,
20
22
  AppsListParams,
21
23
  AppsListResponse,
22
24
  CollaborationModeListResponse,
@@ -112,6 +114,9 @@ if TYPE_CHECKING:
112
114
 
113
115
  logger = logging.getLogger(__name__)
114
116
 
117
+ type EventListener = Callable[[CodexEvent], Awaitable[None] | None]
118
+ """Receives events that belong to no running turn."""
119
+
115
120
 
116
121
  class CodexClient:
117
122
  """Client for the Codex app-server JSON-RPC protocol.
@@ -174,7 +179,7 @@ class CodexClient:
174
179
  )
175
180
  self._turn_queues: dict[str, asyncio.Queue[CodexEvent | None]] = {}
176
181
  self._realtime_queues: dict[str, asyncio.Queue[CodexEvent | None]] = {}
177
- self._event_queue: asyncio.Queue[CodexEvent | None] = asyncio.Queue()
182
+ self._event_listeners: list[EventListener] = []
178
183
  self._active_threads: set[str] = set()
179
184
  self._mcp_elicitation_enabled = on_mcp_elicitation is not None
180
185
  self._mcp_elicitation_for_approvals = mcp_elicitation_for_approvals
@@ -185,15 +190,15 @@ class CodexClient:
185
190
  self.marketplace = CodexMarketPlace(self)
186
191
  self.skills = CodexSkills(self)
187
192
  if on_approval:
188
- self.register_handler(SERVER_REQUEST_COMMAND_APPROVAL, on_approval) # type: ignore[arg-type]
189
- self.register_handler(SERVER_REQUEST_FILE_CHANGE_APPROVAL, on_approval) # type: ignore[arg-type]
190
- self.register_handler(SERVER_REQUEST_SKILL_APPROVAL, on_approval) # type: ignore[arg-type]
193
+ self.register_handler(SERVER_REQUEST_COMMAND_APPROVAL, on_approval) # ty: ignore[invalid-argument-type]
194
+ self.register_handler(SERVER_REQUEST_FILE_CHANGE_APPROVAL, on_approval) # ty: ignore[invalid-argument-type]
195
+ self.register_handler(SERVER_REQUEST_SKILL_APPROVAL, on_approval) # ty: ignore[invalid-argument-type]
191
196
  if on_user_input:
192
- self.register_handler(SERVER_REQUEST_USER_INPUT, on_user_input) # type: ignore[arg-type]
197
+ self.register_handler(SERVER_REQUEST_USER_INPUT, on_user_input) # ty: ignore[invalid-argument-type]
193
198
  if on_dynamic_tool_call:
194
- self.register_handler(SERVER_REQUEST_DYNAMIC_TOOL_CALL, on_dynamic_tool_call) # type: ignore[arg-type]
199
+ self.register_handler(SERVER_REQUEST_DYNAMIC_TOOL_CALL, on_dynamic_tool_call) # ty: ignore[invalid-argument-type]
195
200
  if on_mcp_elicitation:
196
- self.register_handler(SERVER_REQUEST_MCP_ELICITATION, on_mcp_elicitation) # type: ignore[arg-type]
201
+ self.register_handler(SERVER_REQUEST_MCP_ELICITATION, on_mcp_elicitation) # ty: ignore[invalid-argument-type]
197
202
 
198
203
  async def __aenter__(self) -> Self:
199
204
  """Async context manager entry - starts the app-server."""
@@ -901,26 +906,52 @@ class CodexClient:
901
906
 
902
907
  event_data = {"method": method, "params": params}
903
908
  event = codex_event_adapter.validate_python(event_data)
909
+ if isinstance(event, AccountRateLimitsUpdatedMessage):
910
+ self.account.rate_limits = event.params.rate_limits
904
911
 
905
912
  thread_id = params.get("threadId")
906
913
 
907
914
  # Route realtime events to the realtime session queue
908
915
  if method.startswith("thread/realtime/") and thread_id:
909
916
  rt_key = f"realtime:{thread_id}"
910
- queue = self._realtime_queues.get(rt_key)
911
- await (queue or self._event_queue).put(event)
917
+ if (queue := self._realtime_queues.get(rt_key)) is not None:
918
+ await queue.put(event)
919
+ else:
920
+ await self._notify_listeners(event)
912
921
  return
913
922
 
914
923
  turn_id = params.get("turnId")
915
924
  if not turn_id and "turn" in params:
916
925
  turn_id = params.get("turn", {}).get("id")
917
926
 
918
- if thread_id and turn_id:
919
- turn_key = f"{thread_id}:{turn_id}"
920
- queue = self._turn_queues.get(turn_key)
921
- await (queue or self._event_queue).put(event)
927
+ turn_queue = (
928
+ self._turn_queues.get(f"{thread_id}:{turn_id}") if thread_id and turn_id else None
929
+ )
930
+ if turn_queue is not None:
931
+ await turn_queue.put(event)
922
932
  else:
923
- await self._event_queue.put(event)
933
+ await self._notify_listeners(event)
934
+
935
+ def add_event_listener(self, listener: EventListener) -> None:
936
+ """Receive events that belong to no running turn (account, config, app updates, ...).
937
+
938
+ Turn events go to the turn's stream; everything else is passed to the listeners
939
+ (and otherwise dropped).
940
+ """
941
+ self._event_listeners.append(listener)
942
+
943
+ def remove_event_listener(self, listener: EventListener) -> None:
944
+ """Stop passing events to a listener added with :meth:`add_event_listener`."""
945
+ self._event_listeners.remove(listener)
946
+
947
+ async def _notify_listeners(self, event: CodexEvent) -> None:
948
+ for listener in list(self._event_listeners):
949
+ try:
950
+ result = listener(event)
951
+ if inspect.isawaitable(result):
952
+ await result
953
+ except Exception:
954
+ logger.exception("Codex event listener failed for %s", event.method)
924
955
 
925
956
  async def _handle_server_request(
926
957
  self, method: str, request_id: int | str, params: dict[str, Any]
@@ -17,6 +17,8 @@ from codexed.models import (
17
17
 
18
18
 
19
19
  if TYPE_CHECKING:
20
+ import builtins
21
+
20
22
  from codexed.client import CodexClient
21
23
 
22
24
  logger = logging.getLogger(__name__)
@@ -46,7 +48,7 @@ class CodexPlugin:
46
48
  params = PluginUninstallParams(plugin_id=plugin_id)
47
49
  await self._client.dispatch.send_request("plugin/uninstall", params)
48
50
 
49
- async def list(self, cwds: list[str] | None = None) -> PluginListResponse:
51
+ async def list(self, cwds: builtins.list[str] | None = None) -> PluginListResponse:
50
52
  params = PluginListParams(cwds=cwds)
51
53
  response = await self._client.dispatch.send_request("plugin/list", params)
52
54
  return PluginListResponse.model_validate(response)
@@ -620,8 +620,8 @@ class Session:
620
620
  result = await self._client.dispatch.send_request("mcpServer/tool/call", params)
621
621
  data = McpServerToolCallResponse.model_validate(result)
622
622
  return CallToolResult(
623
- structuredContent=data.structured_content,
624
- isError=bool(data.is_error),
623
+ structured_content=data.structured_content,
624
+ is_error=bool(data.is_error),
625
625
  content=data.content,
626
626
  meta=data.field_meta,
627
627
  )
@@ -206,7 +206,15 @@ class McpElicitationUrlParams(_McpElicitationBase):
206
206
  server_name: str,
207
207
  turn_id: str | None = None,
208
208
  ) -> McpElicitationUrlParams:
209
- """Create from MCP ElicitRequestURLParams."""
209
+ """Create from MCP ElicitRequestURLParams.
210
+
211
+ Raises:
212
+ ValueError: If the MCP request carries no elicitation ID, which the
213
+ app-server protocol requires to correlate the response
214
+ """
215
+ if params.elicitation_id is None:
216
+ msg = "URL elicitation request without elicitation_id cannot be forwarded"
217
+ raise ValueError(msg)
210
218
  return cls(
211
219
  message=params.message,
212
220
  url=params.url,
@@ -341,7 +341,7 @@ def tools_to_config_dict(tools: list[ToolConfig]) -> dict[str, Any]:
341
341
  case None:
342
342
  pass
343
343
  case _ as unreachable:
344
- assert_never(unreachable) # ty: ignore[type-assertion-failure]
344
+ assert_never(unreachable)
345
345
 
346
346
  case WebSearchToolConfig(
347
347
  mode=mode,
@@ -97,7 +97,11 @@ ApprovalResponse = (
97
97
  ApprovalHandler = Callable[[ApprovalParams], Awaitable[ApprovalResponse]]
98
98
 
99
99
  # Validator: either a model class or a TypeAdapter for discriminated unions
100
- ParamsValidator = type[ServerRequestParams] | TypeAdapter[ServerRequestParams]
100
+ ParamsValidator = (
101
+ type[ServerRequestParams]
102
+ | TypeAdapter[ServerRequestParams]
103
+ | TypeAdapter[McpServerElicitationRequestParams]
104
+ )
101
105
 
102
106
  # Map from wire method names to param validator + response model type
103
107
  SERVER_REQUEST_TYPES: dict[str, tuple[ParamsValidator, type[ServerRequestResponse]]] = {
@@ -119,7 +123,7 @@ SERVER_REQUEST_TYPES: dict[str, tuple[ParamsValidator, type[ServerRequestRespons
119
123
  SkillRequestApprovalResponse,
120
124
  ),
121
125
  SERVER_REQUEST_MCP_ELICITATION: (
122
- mcp_elicitation_adapter, # type: ignore[dict-item]
126
+ mcp_elicitation_adapter,
123
127
  McpServerElicitationResponse,
124
128
  ),
125
129
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes