codexed 1.0.0__tar.gz → 1.1.0__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 (32) hide show
  1. {codexed-1.0.0 → codexed-1.1.0}/PKG-INFO +1 -1
  2. {codexed-1.0.0 → codexed-1.1.0}/pyproject.toml +1 -1
  3. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/client/__init__.py +2 -1
  4. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/client/client.py +9 -0
  5. codexed-1.1.0/src/codexed/client/realtime.py +174 -0
  6. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/client/session.py +17 -0
  7. {codexed-1.0.0 → codexed-1.1.0}/LICENSE +0 -0
  8. {codexed-1.0.0 → codexed-1.1.0}/README.md +0 -0
  9. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/README.md +0 -0
  10. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/__init__.py +0 -0
  11. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/client/dispatch.py +0 -0
  12. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/client/fs.py +0 -0
  13. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/exceptions.py +0 -0
  14. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/helpers.py +0 -0
  15. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/log.py +0 -0
  16. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/__init__.py +0 -0
  17. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/base.py +0 -0
  18. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/codex_types.py +0 -0
  19. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/event_data.py +0 -0
  20. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/events.py +0 -0
  21. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/mcp_server.py +0 -0
  22. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/misc.py +0 -0
  23. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/request_params.py +0 -0
  24. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/response_item.py +0 -0
  25. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/responses.py +0 -0
  26. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/thread_item.py +0 -0
  27. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/tool_config.py +0 -0
  28. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/user_input.py +0 -0
  29. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/models/v2_protocol.py +0 -0
  30. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/py.typed +0 -0
  31. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/request_handlers.py +0 -0
  32. {codexed-1.0.0 → codexed-1.1.0}/src/codexed/transport.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codexed
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: Alternative codex app-server client
5
5
  Keywords:
6
6
  Author: Philipp Temminghoff
@@ -2,7 +2,7 @@
2
2
 
3
3
  [project]
4
4
  name = "codexed"
5
- version = "1.0.0"
5
+ version = "1.1.0"
6
6
  description = "Alternative codex app-server client"
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.13"
@@ -2,6 +2,7 @@
2
2
 
3
3
  from .client import CodexClient
4
4
  from .fs import CodexFS
5
+ from .realtime import RealtimeSession
5
6
  from .session import Session
6
7
 
7
- __all__ = ["CodexClient", "CodexFS", "Session"]
8
+ __all__ = ["CodexClient", "CodexFS", "RealtimeSession", "Session"]
@@ -177,6 +177,7 @@ class CodexClient:
177
177
  on_server_request=self._handle_server_request,
178
178
  )
179
179
  self._turn_queues: dict[str, asyncio.Queue[CodexEvent | None]] = {}
180
+ self._realtime_queues: dict[str, asyncio.Queue[CodexEvent | None]] = {}
180
181
  self._event_queue: asyncio.Queue[CodexEvent | None] = asyncio.Queue()
181
182
  self._active_threads: set[str] = set()
182
183
  self._mcp_elicitation_enabled = on_mcp_elicitation is not None
@@ -973,6 +974,14 @@ class CodexClient:
973
974
  event: CodexEvent = codex_event_adapter.validate_python(event_data)
974
975
 
975
976
  thread_id = params.get("threadId")
977
+
978
+ # Route realtime events to the realtime session queue
979
+ if method.startswith("thread/realtime/") and thread_id:
980
+ rt_key = f"realtime:{thread_id}"
981
+ queue = self._realtime_queues.get(rt_key)
982
+ await (queue or self._event_queue).put(event)
983
+ return
984
+
976
985
  turn_id = params.get("turnId")
977
986
  if not turn_id and "turn" in params:
978
987
  turn_id = params.get("turn", {}).get("id")
@@ -0,0 +1,174 @@
1
+ """Realtime voice session — async context manager for thread-scoped realtime."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import logging
7
+ from typing import TYPE_CHECKING, Self
8
+
9
+ from codexed.models import (
10
+ ThreadRealtimeAppendAudioParams,
11
+ ThreadRealtimeAppendAudioResponse,
12
+ ThreadRealtimeAppendTextParams,
13
+ ThreadRealtimeAppendTextResponse,
14
+ ThreadRealtimeAudioChunk,
15
+ ThreadRealtimeClosedMessage,
16
+ ThreadRealtimeStartedMessage,
17
+ ThreadRealtimeStartParams,
18
+ ThreadRealtimeStartResponse,
19
+ ThreadRealtimeStopParams,
20
+ ThreadRealtimeStopResponse,
21
+ )
22
+
23
+
24
+ if TYPE_CHECKING:
25
+ from collections.abc import AsyncIterator
26
+ from types import TracebackType
27
+
28
+ from codexed.client import CodexClient
29
+ from codexed.models import CodexEvent
30
+
31
+ logger = logging.getLogger(__name__)
32
+
33
+
34
+ class RealtimeSession:
35
+ """Async context manager for a thread-scoped realtime voice session.
36
+
37
+ Usage::
38
+
39
+ async with session.realtime(prompt="You are helpful") as rt:
40
+ await rt.send_text("hello")
41
+ async for event in rt:
42
+ match event:
43
+ case ThreadRealtimeOutputAudioDeltaMessage():
44
+ play(event.params.audio)
45
+ case ThreadRealtimeTranscriptUpdatedMessage():
46
+ print(event.params.text)
47
+ case ThreadRealtimeClosedMessage():
48
+ break
49
+ """
50
+
51
+ def __init__(
52
+ self,
53
+ client: CodexClient,
54
+ thread_id: str,
55
+ prompt: str,
56
+ *,
57
+ session_id: str | None = None,
58
+ ) -> None:
59
+ self._client = client
60
+ self._thread_id = thread_id
61
+ self._prompt = prompt
62
+ self._session_id = session_id
63
+ self._queue: asyncio.Queue[CodexEvent | None] = asyncio.Queue()
64
+ self._closed = False
65
+ self._queue_key = f"realtime:{thread_id}"
66
+
67
+ @property
68
+ def thread_id(self) -> str:
69
+ return self._thread_id
70
+
71
+ @property
72
+ def session_id(self) -> str | None:
73
+ return self._session_id
74
+
75
+ async def __aenter__(self) -> Self:
76
+ # Register our queue for realtime events
77
+ self._client._realtime_queues[self._queue_key] = self._queue
78
+
79
+ # Send start request
80
+ params = ThreadRealtimeStartParams(
81
+ thread_id=self._thread_id,
82
+ prompt=self._prompt,
83
+ session_id=self._session_id,
84
+ )
85
+ result = await self._client.dispatch.send_request("thread/realtime/start", params)
86
+ ThreadRealtimeStartResponse.model_validate(result)
87
+
88
+ # Wait for the started notification
89
+ event = await self._queue.get()
90
+ if isinstance(event, ThreadRealtimeStartedMessage):
91
+ self._session_id = event.params.session_id
92
+ return self
93
+
94
+ async def __aexit__(
95
+ self,
96
+ exc_type: type[BaseException] | None,
97
+ exc_val: BaseException | None,
98
+ exc_tb: TracebackType | None,
99
+ ) -> None:
100
+ try:
101
+ if not self._closed:
102
+ params = ThreadRealtimeStopParams(thread_id=self._thread_id)
103
+ result = await self._client.dispatch.send_request("thread/realtime/stop", params)
104
+ ThreadRealtimeStopResponse.model_validate(result)
105
+ # Drain until we get the closed notification
106
+ while True:
107
+ event = await self._queue.get()
108
+ if event is None or isinstance(event, ThreadRealtimeClosedMessage):
109
+ break
110
+ except Exception: # noqa: BLE001
111
+ logger.debug("Error during realtime cleanup", exc_info=True)
112
+ finally:
113
+ self._client._realtime_queues.pop(self._queue_key, None)
114
+
115
+ def __aiter__(self) -> AsyncIterator[CodexEvent]:
116
+ return self
117
+
118
+ async def __anext__(self) -> CodexEvent:
119
+ if self._closed:
120
+ raise StopAsyncIteration
121
+ event = await self._queue.get()
122
+ if event is None or isinstance(event, ThreadRealtimeClosedMessage):
123
+ self._closed = True
124
+ if isinstance(event, ThreadRealtimeClosedMessage):
125
+ return event
126
+ raise StopAsyncIteration
127
+ return event
128
+
129
+ async def send_text(self, text: str) -> None:
130
+ """Send text input to the realtime session."""
131
+ params = ThreadRealtimeAppendTextParams(
132
+ thread_id=self._thread_id,
133
+ text=text,
134
+ )
135
+ result = await self._client.dispatch.send_request("thread/realtime/appendText", params)
136
+ ThreadRealtimeAppendTextResponse.model_validate(result)
137
+
138
+ async def send_audio(
139
+ self,
140
+ data: str,
141
+ *,
142
+ sample_rate: int = 24_000,
143
+ num_channels: int = 1,
144
+ samples_per_channel: int | None = None,
145
+ item_id: str | None = None,
146
+ ) -> None:
147
+ """Send an audio chunk to the realtime session.
148
+
149
+ Args:
150
+ data: Base64-encoded audio data.
151
+ sample_rate: Audio sample rate in Hz.
152
+ num_channels: Number of audio channels.
153
+ samples_per_channel: Number of samples per channel.
154
+ item_id: Optional item ID for the audio chunk.
155
+ """
156
+ params = ThreadRealtimeAppendAudioParams(
157
+ thread_id=self._thread_id,
158
+ audio=ThreadRealtimeAudioChunk(
159
+ data=data,
160
+ sample_rate=sample_rate,
161
+ num_channels=num_channels,
162
+ samples_per_channel=samples_per_channel,
163
+ item_id=item_id,
164
+ ),
165
+ )
166
+ result = await self._client.dispatch.send_request("thread/realtime/appendAudio", params)
167
+ ThreadRealtimeAppendAudioResponse.model_validate(result)
168
+
169
+ def __repr__(self) -> str:
170
+ state = "closed" if self._closed else "active"
171
+ return (
172
+ f"RealtimeSession(thread_id={self._thread_id!r}, "
173
+ f"session_id={self._session_id!r}, {state})"
174
+ )
@@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Any, assert_never
9
9
 
10
10
  from pydantic import BaseModel, TypeAdapter
11
11
 
12
+ from codexed.client.realtime import RealtimeSession
12
13
  from codexed.exceptions import CodexRequestError, TurnFailedError
13
14
  from codexed.helpers import kebab_to_camel
14
15
  from codexed.models import (
@@ -321,6 +322,22 @@ class Session:
321
322
  params = ThreadCompactStartParams(thread_id=self.thread_id)
322
323
  await self._client.dispatch.send_request("thread/compact/start", params)
323
324
 
325
+ def realtime(self, prompt: str, *, session_id: str | None = None) -> RealtimeSession:
326
+ """Open a realtime voice session on this thread.
327
+
328
+ Returns an async context manager that sends ``thread/realtime/start``
329
+ on enter and ``thread/realtime/stop`` on exit. Iterate over the
330
+ returned object to receive realtime events.
331
+
332
+ Example::
333
+
334
+ async with session.realtime(prompt="You are helpful") as rt:
335
+ await rt.send_text("hello")
336
+ async for event in rt:
337
+ ...
338
+ """
339
+ return RealtimeSession(self._client, self.thread_id, prompt, session_id=session_id)
340
+
324
341
  async def rollback(self, turns: int) -> ThreadRollbackResponse:
325
342
  """Rollback the last N turns from this thread.
326
343
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes