codexed 1.2.6__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 (37) hide show
  1. {codexed-1.2.6 → codexed-1.3.1}/PKG-INFO +1 -1
  2. {codexed-1.2.6 → codexed-1.3.1}/pyproject.toml +8 -19
  3. {codexed-1.2.6 → codexed-1.3.1}/pyproject.toml.orig +10 -12
  4. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/__init__.py +2 -2
  5. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/__init__.py +0 -2
  6. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/account.py +13 -3
  7. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/client.py +68 -48
  8. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/plugin.py +3 -1
  9. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/realtime.py +6 -6
  10. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/session.py +31 -53
  11. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/__init__.py +14 -24
  12. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/event_data.py +8 -0
  13. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/events.py +102 -44
  14. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/misc.py +7 -81
  15. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/request_params.py +9 -1
  16. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/responses.py +11 -9
  17. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/thread_item.py +90 -0
  18. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/tool_config.py +4 -4
  19. codexed-1.3.1/src/codexed/models/v2_protocol.py +13355 -0
  20. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/request_handlers.py +6 -2
  21. codexed-1.2.6/src/codexed/client/device.py +0 -67
  22. codexed-1.2.6/src/codexed/models/v2_protocol.py +0 -6475
  23. {codexed-1.2.6 → codexed-1.3.1}/LICENSE +0 -0
  24. {codexed-1.2.6 → codexed-1.3.1}/README.md +0 -0
  25. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/README.md +0 -0
  26. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/dispatch.py +0 -0
  27. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/fs.py +0 -0
  28. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/marketplace.py +0 -0
  29. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/client/skills.py +0 -0
  30. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/exceptions.py +0 -0
  31. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/helpers.py +0 -0
  32. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/log.py +0 -0
  33. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/base.py +0 -0
  34. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/codex_types.py +0 -0
  35. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/models/mcp_server.py +0 -0
  36. {codexed-1.2.6 → codexed-1.3.1}/src/codexed/py.typed +0 -0
  37. {codexed-1.2.6 → 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.2.6
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.2.6"
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.2.6"
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
 
@@ -53,7 +53,7 @@ from codexed.models import (
53
53
  ThreadNameUpdatedNotification,
54
54
  ThreadReadResponse,
55
55
  ThreadResponse,
56
- ThreadRollbackResponse,
56
+ ThreadRevertResponse,
57
57
  ThreadStartedData,
58
58
  ThreadStatusChangedNotification,
59
59
  ThreadTokenUsage,
@@ -228,7 +228,7 @@ __all__ = [
228
228
  "ThreadNameUpdatedNotification",
229
229
  "ThreadReadResponse",
230
230
  "ThreadResponse",
231
- "ThreadRollbackResponse",
231
+ "ThreadRevertResponse",
232
232
  "ThreadSortKey",
233
233
  "ThreadSourceKind",
234
234
  "ThreadStartedData",
@@ -5,13 +5,11 @@ from .fs import CodexFS
5
5
  from .skills import CodexSkills
6
6
  from .plugin import CodexPlugin
7
7
  from .marketplace import CodexMarketPlace
8
- from .device import CodexDevice
9
8
  from .realtime import RealtimeSession
10
9
  from .session import Session
11
10
 
12
11
  __all__ = [
13
12
  "CodexClient",
14
- "CodexDevice",
15
13
  "CodexFS",
16
14
  "CodexMarketPlace",
17
15
  "CodexPlugin",
@@ -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,14 +3,14 @@
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
 
10
11
  from pydantic import TypeAdapter
11
12
 
12
13
  from codexed.client.account import CodexAccount
13
- from codexed.client.device import CodexDevice
14
14
  from codexed.client.dispatch import Dispatch
15
15
  from codexed.client.fs import CodexFS
16
16
  from codexed.client.marketplace import CodexMarketPlace
@@ -18,6 +18,7 @@ from codexed.client.plugin import CodexPlugin
18
18
  from codexed.client.skills import CodexSkills
19
19
  from codexed.helpers import merge_config
20
20
  from codexed.models import (
21
+ AccountRateLimitsUpdatedMessage,
21
22
  AppsListParams,
22
23
  AppsListResponse,
23
24
  CollaborationModeListResponse,
@@ -90,11 +91,9 @@ if TYPE_CHECKING:
90
91
  McpServerConfig,
91
92
  McpServerStatusDetail,
92
93
  MergeStrategy,
93
- PermissionProfile,
94
94
  Personality,
95
95
  SandboxMode,
96
96
  SandboxPolicy,
97
- ServiceTier,
98
97
  SortDirection,
99
98
  ThreadSortKey,
100
99
  ThreadSourceKind,
@@ -115,6 +114,9 @@ if TYPE_CHECKING:
115
114
 
116
115
  logger = logging.getLogger(__name__)
117
116
 
117
+ type EventListener = Callable[[CodexEvent], Awaitable[None] | None]
118
+ """Receives events that belong to no running turn."""
119
+
118
120
 
119
121
  class CodexClient:
120
122
  """Client for the Codex app-server JSON-RPC protocol.
@@ -177,27 +179,26 @@ class CodexClient:
177
179
  )
178
180
  self._turn_queues: dict[str, asyncio.Queue[CodexEvent | None]] = {}
179
181
  self._realtime_queues: dict[str, asyncio.Queue[CodexEvent | None]] = {}
180
- self._event_queue: asyncio.Queue[CodexEvent | None] = asyncio.Queue()
182
+ self._event_listeners: list[EventListener] = []
181
183
  self._active_threads: set[str] = set()
182
184
  self._mcp_elicitation_enabled = on_mcp_elicitation is not None
183
185
  self._mcp_elicitation_for_approvals = mcp_elicitation_for_approvals
184
186
  self._server_request_handlers: dict[str, ServerRequestHandler] = {}
185
187
  self.account = CodexAccount(self)
186
188
  self.fs = CodexFS(self)
187
- self.device = CodexDevice(self)
188
189
  self.plugins = CodexPlugin(self)
189
190
  self.marketplace = CodexMarketPlace(self)
190
191
  self.skills = CodexSkills(self)
191
192
  if on_approval:
192
- self.register_handler(SERVER_REQUEST_COMMAND_APPROVAL, on_approval) # type: ignore[arg-type]
193
- self.register_handler(SERVER_REQUEST_FILE_CHANGE_APPROVAL, on_approval) # type: ignore[arg-type]
194
- 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]
195
196
  if on_user_input:
196
- 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]
197
198
  if on_dynamic_tool_call:
198
- 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]
199
200
  if on_mcp_elicitation:
200
- 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]
201
202
 
202
203
  async def __aenter__(self) -> Self:
203
204
  """Async context manager entry - starts the app-server."""
@@ -236,13 +237,12 @@ class CodexClient:
236
237
  tools: list[ToolConfig] | None = None,
237
238
  code_mode: bool | None = None,
238
239
  service_name: str | None = None,
239
- service_tier: ServiceTier | None = None,
240
+ service_tier: str | None = None,
240
241
  personality: Personality | None = None,
241
242
  ephemeral: bool | None = None,
242
243
  dynamic_tools: list[DynamicToolSpec] | None = None,
243
244
  mcp_servers: Mapping[str, McpServerConfig] | None = None,
244
245
  experimental_raw_events: bool = False,
245
- persist_extended_history: bool = False,
246
246
  session_start_source: ThreadStartSource | None = None,
247
247
  environments: list[TurnEnvironmentParams] | None = None,
248
248
  ) -> Session:
@@ -263,14 +263,13 @@ class CodexClient:
263
263
  exactly those tools. Merged into ``config``.
264
264
  code_mode: Enable experimental code mode feature flag
265
265
  service_name: Optional service name
266
- service_tier: Service tier (fast/flex)
266
+ service_tier: Service tier
267
267
  personality: Personality preset (none, friendly, pragmatic)
268
268
  ephemeral: If true, thread is not persisted to disk
269
269
  dynamic_tools: Dynamic tool specifications
270
270
  mcp_servers: Per-thread MCP server configurations.
271
271
  Merged into ``config`` under the ``mcp_servers`` key.
272
272
  experimental_raw_events: Emit raw Responses API items (internal)
273
- persist_extended_history: Persist full history for resume/fork/read
274
273
  session_start_source: Source of the session start
275
274
  environments: List of environment variables to set for the thread
276
275
 
@@ -302,7 +301,6 @@ class CodexClient:
302
301
  ephemeral=ephemeral,
303
302
  dynamic_tools=dynamic_tools,
304
303
  experimental_raw_events=experimental_raw_events,
305
- persist_extended_history=persist_extended_history,
306
304
  session_start_source=session_start_source,
307
305
  environments=environments,
308
306
  )
@@ -327,12 +325,11 @@ class CodexClient:
327
325
  config: dict[str, Any] | None = None,
328
326
  tools: list[ToolConfig] | None = None,
329
327
  code_mode: bool | None = None,
330
- service_tier: ServiceTier | None = None,
328
+ service_tier: str | None = None,
331
329
  personality: Personality | None = None,
332
330
  mcp_servers: Mapping[str, McpServerConfig] | None = None,
333
- persist_extended_history: bool = False,
334
331
  exclude_turns: bool | None = None,
335
- permission_profile: PermissionProfile | None = None,
332
+ permissions: str | None = None,
336
333
  ) -> Session:
337
334
  """Resume an existing thread by ID.
338
335
 
@@ -350,12 +347,11 @@ class CodexClient:
350
347
  config: Additional configuration overrides
351
348
  tools: Builtin tool configurations override
352
349
  code_mode: Enable experimental code mode feature flag
353
- service_tier: Service tier (fast/flex)
350
+ service_tier: Service tier
354
351
  personality: Personality override
355
352
  mcp_servers: Per-thread MCP server configurations
356
- persist_extended_history: Persist full history for resume/fork/read
357
353
  exclude_turns: If true, exclude turns from the thread's history
358
- permission_profile: Permission profile override
354
+ permissions: Named permissions profile ID (cannot be combined with sandbox)
359
355
 
360
356
  Returns:
361
357
  Session wrapping the resumed thread
@@ -383,9 +379,8 @@ class CodexClient:
383
379
  config=cfg,
384
380
  service_tier=service_tier,
385
381
  personality=personality,
386
- persist_extended_history=persist_extended_history,
387
382
  exclude_turns=exclude_turns,
388
- permission_profile=permission_profile,
383
+ permissions=permissions,
389
384
  )
390
385
  result = await self.dispatch.send_request("thread/resume", params)
391
386
  response = ThreadResponse.model_validate(result)
@@ -408,13 +403,13 @@ class CodexClient:
408
403
  config: dict[str, Any] | None = None,
409
404
  tools: list[ToolConfig] | None = None,
410
405
  code_mode: bool | None = None,
411
- service_tier: ServiceTier | None = None,
406
+ service_tier: str | None = None,
412
407
  ephemeral: bool | None = None,
413
408
  mcp_servers: Mapping[str, McpServerConfig] | None = None,
414
- turn_id: str | None = None,
415
- persist_extended_history: bool = False,
409
+ last_turn_id: str | None = None,
410
+ before_turn_id: str | None = None,
416
411
  exclude_turns: bool | None = None,
417
- permission_profile: PermissionProfile | None = None,
412
+ permissions: str | None = None,
418
413
  ) -> Session:
419
414
  """Fork an existing thread into a new thread with copied history.
420
415
 
@@ -432,16 +427,16 @@ class CodexClient:
432
427
  config: Additional configuration overrides
433
428
  tools: Builtin tool configurations for forked thread
434
429
  code_mode: Enable experimental code mode feature flag
435
- service_tier: Service tier (fast/flex)
430
+ service_tier: Service tier
436
431
  personality: Personality for forked thread
437
432
  ephemeral: If true, forked thread is not persisted
438
433
  mcp_servers: Per-thread MCP server configurations
439
- turn_id: If provided, rollback the forked thread to this turn
440
- persist_extended_history: Persist full history for resume/fork/read
434
+ last_turn_id: Fork through this turn (inclusive), omitting later turns
435
+ before_turn_id: Fork before this turn, excluding it and all later turns
441
436
  exclude_turns: When true, return only thread metadata and live fork state
442
437
  without populating `thread.turns`. This is useful when
443
438
  the client plans to call `thread/turns/list` immediately after forking.
444
- permission_profile: Permission profile for forked thread
439
+ permissions: Named permissions profile ID (cannot be combined with sandbox)
445
440
 
446
441
  Returns:
447
442
  Session wrapping the new forked thread
@@ -469,17 +464,15 @@ class CodexClient:
469
464
  config=cfg,
470
465
  service_tier=service_tier,
471
466
  ephemeral=ephemeral,
472
- persist_extended_history=persist_extended_history,
467
+ last_turn_id=last_turn_id,
468
+ before_turn_id=before_turn_id,
473
469
  exclude_turns=exclude_turns,
474
- permission_profile=permission_profile,
470
+ permissions=permissions,
475
471
  )
476
472
  result = await self.dispatch.send_request("thread/fork", params)
477
473
  response = ThreadResponse.model_validate(result)
478
474
  self._active_threads.add(response.thread.id)
479
- session = Session(self, response)
480
- if turn_id is not None:
481
- await session.rollback_to_turn(turn_id)
482
- return session
475
+ return Session(self, response)
483
476
 
484
477
  async def thread_list(
485
478
  self,
@@ -593,7 +586,7 @@ class CodexClient:
593
586
  sandbox_policy: SandboxPolicy | None = None,
594
587
  output_bytes_cap: int | None = None,
595
588
  timeout_ms: int | None = None,
596
- permission_profile: PermissionProfile | None = None,
589
+ permission_profile: str | None = None,
597
590
  ) -> CommandExecResponse:
598
591
  """Execute a command without creating a thread/turn.
599
592
 
@@ -603,7 +596,8 @@ class CodexClient:
603
596
  sandbox_policy: Sandbox policy override
604
597
  output_bytes_cap: Cap output based on bytes
605
598
  timeout_ms: Timeout in milliseconds
606
- permission_profile: Permission profile override
599
+ permission_profile: Named permissions profile ID
600
+ (cannot be combined with sandbox_policy)
607
601
 
608
602
  Returns:
609
603
  CommandExecResponse with exit_code, stdout, stderr
@@ -912,26 +906,52 @@ class CodexClient:
912
906
 
913
907
  event_data = {"method": method, "params": params}
914
908
  event = codex_event_adapter.validate_python(event_data)
909
+ if isinstance(event, AccountRateLimitsUpdatedMessage):
910
+ self.account.rate_limits = event.params.rate_limits
915
911
 
916
912
  thread_id = params.get("threadId")
917
913
 
918
914
  # Route realtime events to the realtime session queue
919
915
  if method.startswith("thread/realtime/") and thread_id:
920
916
  rt_key = f"realtime:{thread_id}"
921
- queue = self._realtime_queues.get(rt_key)
922
- 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)
923
921
  return
924
922
 
925
923
  turn_id = params.get("turnId")
926
924
  if not turn_id and "turn" in params:
927
925
  turn_id = params.get("turn", {}).get("id")
928
926
 
929
- if thread_id and turn_id:
930
- turn_key = f"{thread_id}:{turn_id}"
931
- queue = self._turn_queues.get(turn_key)
932
- 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)
933
932
  else:
934
- 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)
935
955
 
936
956
  async def _handle_server_request(
937
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)
@@ -49,14 +49,14 @@ class RealtimeSession:
49
49
  output_modality: RealtimeOutputModality,
50
50
  prompt: str | None = None,
51
51
  *,
52
- session_id: str | None = None,
52
+ realtime_session_id: str | None = None,
53
53
  transport: ThreadRealtimeStartTransport | None = None,
54
54
  voice: RealtimeVoice | None = None,
55
55
  ) -> None:
56
56
  self._client = client
57
57
  self._thread_id = thread_id
58
58
  self._prompt = prompt
59
- self._session_id = session_id
59
+ self._session_id = realtime_session_id
60
60
  self._queue: asyncio.Queue[CodexEvent | None] = asyncio.Queue()
61
61
  self._closed = False
62
62
  self._queue_key = f"realtime:{thread_id}"
@@ -69,7 +69,7 @@ class RealtimeSession:
69
69
  return self._thread_id
70
70
 
71
71
  @property
72
- def session_id(self) -> str | None:
72
+ def realtime_session_id(self) -> str | None:
73
73
  return self._session_id
74
74
 
75
75
  async def __aenter__(self) -> Self:
@@ -80,7 +80,7 @@ class RealtimeSession:
80
80
  params = ThreadRealtimeStartParams(
81
81
  thread_id=self._thread_id,
82
82
  prompt=self._prompt,
83
- session_id=self._session_id,
83
+ realtime_session_id=self._session_id,
84
84
  output_modality=self._output_modality,
85
85
  )
86
86
  result = await self._client.dispatch.send_request("thread/realtime/start", params)
@@ -89,7 +89,7 @@ class RealtimeSession:
89
89
  # Wait for the started notification
90
90
  event = await self._queue.get()
91
91
  if isinstance(event, ThreadRealtimeStartedMessage):
92
- self._session_id = event.params.session_id
92
+ self._session_id = event.params.realtime_session_id
93
93
  return self
94
94
 
95
95
  async def __aexit__(
@@ -175,5 +175,5 @@ class RealtimeSession:
175
175
  state = "closed" if self._closed else "active"
176
176
  return (
177
177
  f"RealtimeSession(thread_id={self._thread_id!r}, "
178
- f"session_id={self._session_id!r}, {state})"
178
+ f"realtime_session_id={self._session_id!r}, {state})"
179
179
  )