codexed 1.1.8__tar.gz → 1.2.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.
- {codexed-1.1.8 → codexed-1.2.0}/PKG-INFO +1 -1
- {codexed-1.1.8 → codexed-1.2.0}/pyproject.toml +1 -1
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/client/client.py +62 -13
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/client/fs.py +3 -2
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/client/realtime.py +25 -21
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/client/session.py +78 -5
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/__init__.py +56 -23
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/codex_types.py +0 -2
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/events.py +14 -7
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/misc.py +93 -22
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/thread_item.py +2 -16
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/v2_protocol.py +502 -54
- codexed-1.1.8/src/codexed/models/user_input.py +0 -43
- {codexed-1.1.8 → codexed-1.2.0}/LICENSE +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/README.md +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/README.md +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/__init__.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/client/__init__.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/client/dispatch.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/client/skills.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/exceptions.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/helpers.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/log.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/base.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/event_data.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/mcp_server.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/request_params.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/responses.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/models/tool_config.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/py.typed +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/request_handlers.py +0 -0
- {codexed-1.1.8 → codexed-1.2.0}/src/codexed/transport.py +0 -0
|
@@ -41,13 +41,17 @@ from codexed.models import (
|
|
|
41
41
|
ListMcpServerStatusResponse,
|
|
42
42
|
LoginAccountParams,
|
|
43
43
|
LoginAccountResponse,
|
|
44
|
+
MarketplaceAddParams,
|
|
45
|
+
MarketplaceAddResponse,
|
|
44
46
|
McpServerOauthLoginParams,
|
|
45
47
|
McpServerOauthLoginResponse,
|
|
48
|
+
MemoryResetResponse,
|
|
46
49
|
ModelListParams,
|
|
47
50
|
ModelListResponse,
|
|
48
51
|
ThreadForkParams,
|
|
49
52
|
ThreadListParams,
|
|
50
53
|
ThreadListResponse,
|
|
54
|
+
ThreadLoadedListParams,
|
|
51
55
|
ThreadLoadedListResponse,
|
|
52
56
|
ThreadResponse,
|
|
53
57
|
ThreadResumeParams,
|
|
@@ -85,14 +89,15 @@ if TYPE_CHECKING:
|
|
|
85
89
|
ExperimentalFeature,
|
|
86
90
|
ExternalAgentConfigMigrationItem,
|
|
87
91
|
McpServerConfig,
|
|
92
|
+
McpServerStatusDetail,
|
|
88
93
|
MergeStrategy,
|
|
89
|
-
Model,
|
|
90
94
|
Personality,
|
|
91
95
|
SandboxMode,
|
|
92
96
|
SandboxPolicy,
|
|
93
97
|
ServiceTier,
|
|
94
98
|
ThreadSortKey,
|
|
95
99
|
ThreadSourceKind,
|
|
100
|
+
ThreadStartSource,
|
|
96
101
|
ToolConfig,
|
|
97
102
|
)
|
|
98
103
|
from codexed.request_handlers import (
|
|
@@ -231,6 +236,7 @@ class CodexClient:
|
|
|
231
236
|
mcp_servers: Mapping[str, McpServerConfig] | None = None,
|
|
232
237
|
experimental_raw_events: bool = False,
|
|
233
238
|
persist_extended_history: bool = False,
|
|
239
|
+
session_start_source: ThreadStartSource | None = None,
|
|
234
240
|
) -> Session:
|
|
235
241
|
"""Start a new conversation thread.
|
|
236
242
|
|
|
@@ -257,6 +263,7 @@ class CodexClient:
|
|
|
257
263
|
Merged into ``config`` under the ``mcp_servers`` key.
|
|
258
264
|
experimental_raw_events: Emit raw Responses API items (internal)
|
|
259
265
|
persist_extended_history: Persist full history for resume/fork/read
|
|
266
|
+
session_start_source: Source of the session start
|
|
260
267
|
|
|
261
268
|
Returns:
|
|
262
269
|
Session wrapping the new thread
|
|
@@ -287,6 +294,7 @@ class CodexClient:
|
|
|
287
294
|
dynamic_tools=dynamic_tools,
|
|
288
295
|
experimental_raw_events=experimental_raw_events,
|
|
289
296
|
persist_extended_history=persist_extended_history,
|
|
297
|
+
session_start_source=session_start_source,
|
|
290
298
|
)
|
|
291
299
|
result = await self.dispatch.send_request("thread/start", params)
|
|
292
300
|
response = ThreadResponse.model_validate(result)
|
|
@@ -489,29 +497,49 @@ class CodexClient:
|
|
|
489
497
|
result = await self.dispatch.send_request("thread/list", params)
|
|
490
498
|
return ThreadListResponse.model_validate(result)
|
|
491
499
|
|
|
492
|
-
async def thread_loaded_list(
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
500
|
+
async def thread_loaded_list(
|
|
501
|
+
self,
|
|
502
|
+
*,
|
|
503
|
+
cursor: str | None = None,
|
|
504
|
+
limit: int | None = None,
|
|
505
|
+
) -> ThreadLoadedListResponse:
|
|
506
|
+
"""List thread IDs currently loaded in memory.
|
|
507
|
+
|
|
508
|
+
Args:
|
|
509
|
+
cursor: Opaque pagination cursor from previous response
|
|
510
|
+
limit: Maximum number of thread IDs to return
|
|
511
|
+
|
|
512
|
+
Returns:
|
|
513
|
+
ThreadLoadedListResponse with data (list of thread IDs) and next_cursor
|
|
514
|
+
"""
|
|
515
|
+
params = ThreadLoadedListParams(cursor=cursor, limit=limit)
|
|
516
|
+
result = await self.dispatch.send_request("thread/loaded/list", params)
|
|
517
|
+
return ThreadLoadedListResponse.model_validate(result)
|
|
497
518
|
|
|
498
519
|
# ========================================================================
|
|
499
520
|
# Model methods
|
|
500
521
|
# ========================================================================
|
|
501
522
|
|
|
502
|
-
async def model_list(
|
|
523
|
+
async def model_list(
|
|
524
|
+
self,
|
|
525
|
+
*,
|
|
526
|
+
include_hidden: bool | None = None,
|
|
527
|
+
cursor: str | None = None,
|
|
528
|
+
limit: int | None = None,
|
|
529
|
+
) -> ModelListResponse:
|
|
503
530
|
"""List available models with reasoning effort options.
|
|
504
531
|
|
|
505
532
|
Args:
|
|
506
533
|
include_hidden: When true, include hidden models
|
|
534
|
+
cursor: Opaque pagination cursor from previous response
|
|
535
|
+
limit: Maximum number of models to return
|
|
507
536
|
|
|
508
537
|
Returns:
|
|
509
|
-
|
|
538
|
+
ModelListResponse with data (list of models) and next_cursor
|
|
510
539
|
"""
|
|
511
|
-
params = ModelListParams(include_hidden=include_hidden, limit=
|
|
540
|
+
params = ModelListParams(include_hidden=include_hidden, cursor=cursor, limit=limit)
|
|
512
541
|
result = await self.dispatch.send_request("model/list", params)
|
|
513
|
-
|
|
514
|
-
return response.data
|
|
542
|
+
return ModelListResponse.model_validate(result)
|
|
515
543
|
|
|
516
544
|
async def collaboration_mode_list(self) -> list[CollaborationModeMask]:
|
|
517
545
|
"""List available collaboration mode presets (experimental).
|
|
@@ -569,19 +597,21 @@ class CodexClient:
|
|
|
569
597
|
async def mcp_server_status_list(
|
|
570
598
|
self,
|
|
571
599
|
*,
|
|
600
|
+
detail: McpServerStatusDetail | None = None,
|
|
572
601
|
cursor: str | None = None,
|
|
573
602
|
limit: int | None = None,
|
|
574
603
|
) -> ListMcpServerStatusResponse:
|
|
575
604
|
"""List MCP server status with tool and resource information.
|
|
576
605
|
|
|
577
606
|
Args:
|
|
607
|
+
detail: Level of detail to include in the response
|
|
578
608
|
cursor: Pagination cursor from previous call
|
|
579
609
|
limit: Maximum number of servers to return
|
|
580
610
|
|
|
581
611
|
Returns:
|
|
582
612
|
Response with server status entries and optional next_cursor
|
|
583
613
|
"""
|
|
584
|
-
params = ListMcpServerStatusParams(cursor=cursor, limit=limit)
|
|
614
|
+
params = ListMcpServerStatusParams(cursor=cursor, limit=limit, detail=detail)
|
|
585
615
|
result = await self.dispatch.send_request("mcpServerStatus/list", params)
|
|
586
616
|
return ListMcpServerStatusResponse.model_validate(result)
|
|
587
617
|
|
|
@@ -821,6 +851,7 @@ class CodexClient:
|
|
|
821
851
|
*,
|
|
822
852
|
reason: str | None = None,
|
|
823
853
|
thread_id: str | None = None,
|
|
854
|
+
tags: dict[str, Any] | None = None,
|
|
824
855
|
include_logs: bool = False,
|
|
825
856
|
extra_log_files: list[str] | None = None,
|
|
826
857
|
) -> str:
|
|
@@ -830,6 +861,7 @@ class CodexClient:
|
|
|
830
861
|
classification: Feedback classification
|
|
831
862
|
reason: Optional reason text
|
|
832
863
|
thread_id: Optional thread ID to associate
|
|
864
|
+
tags: Optional tags to associate with the feedback
|
|
833
865
|
include_logs: Whether to include logs
|
|
834
866
|
extra_log_files: Additional log files to include
|
|
835
867
|
|
|
@@ -840,6 +872,7 @@ class CodexClient:
|
|
|
840
872
|
classification=classification,
|
|
841
873
|
reason=reason,
|
|
842
874
|
thread_id=thread_id,
|
|
875
|
+
tags=tags,
|
|
843
876
|
include_logs=include_logs,
|
|
844
877
|
extra_log_files=extra_log_files,
|
|
845
878
|
)
|
|
@@ -893,7 +926,7 @@ class CodexClient:
|
|
|
893
926
|
return
|
|
894
927
|
|
|
895
928
|
event_data = {"method": method, "params": params}
|
|
896
|
-
event
|
|
929
|
+
event = codex_event_adapter.validate_python(event_data)
|
|
897
930
|
|
|
898
931
|
thread_id = params.get("threadId")
|
|
899
932
|
|
|
@@ -974,6 +1007,22 @@ class CodexClient:
|
|
|
974
1007
|
"""
|
|
975
1008
|
self._server_request_handlers = create_auto_approve_dict()
|
|
976
1009
|
|
|
1010
|
+
async def add_marketplace(
|
|
1011
|
+
self,
|
|
1012
|
+
ref_name: str | None,
|
|
1013
|
+
source: str,
|
|
1014
|
+
sparse_paths: list[str] | None = None,
|
|
1015
|
+
) -> MarketplaceAddResponse:
|
|
1016
|
+
"""Add a marketplace to the app-server."""
|
|
1017
|
+
params = MarketplaceAddParams(ref_name=ref_name, source=source, sparse_paths=sparse_paths)
|
|
1018
|
+
response = await self.dispatch.send_request("marketplace/add", params)
|
|
1019
|
+
return MarketplaceAddResponse.model_validate(response)
|
|
1020
|
+
|
|
1021
|
+
async def reset_memory(self) -> MemoryResetResponse:
|
|
1022
|
+
"""Reset the app-server memory."""
|
|
1023
|
+
response = await self.dispatch.send_request("memory/reset")
|
|
1024
|
+
return MemoryResetResponse.model_validate(response)
|
|
1025
|
+
|
|
977
1026
|
|
|
978
1027
|
if __name__ == "__main__":
|
|
979
1028
|
|
|
@@ -135,16 +135,17 @@ class CodexFS:
|
|
|
135
135
|
params = FsCopyParams(source_path=source, destination_path=destination, recursive=recursive)
|
|
136
136
|
await self._client.dispatch.send_request("fs/copy", params)
|
|
137
137
|
|
|
138
|
-
async def watch(self, path: str) -> FsWatchResponse:
|
|
138
|
+
async def watch(self, path: str, watch_id: str) -> FsWatchResponse:
|
|
139
139
|
"""Start filesystem watch notifications for an absolute path.
|
|
140
140
|
|
|
141
141
|
Args:
|
|
142
142
|
path: Absolute file or directory path to watch.
|
|
143
|
+
watch_id: Watch identifier to associate with the path.
|
|
143
144
|
|
|
144
145
|
Returns:
|
|
145
146
|
FsWatchResponse with watch_id and canonicalized path.
|
|
146
147
|
"""
|
|
147
|
-
params = FsWatchParams(path=path)
|
|
148
|
+
params = FsWatchParams(path=path, watch_id=watch_id)
|
|
148
149
|
result = await self._client.dispatch.send_request("fs/watch", params)
|
|
149
150
|
return FsWatchResponse.model_validate(result)
|
|
150
151
|
|
|
@@ -13,6 +13,8 @@ from codexed.models import (
|
|
|
13
13
|
ThreadRealtimeAppendTextResponse,
|
|
14
14
|
ThreadRealtimeAudioChunk,
|
|
15
15
|
ThreadRealtimeClosedMessage,
|
|
16
|
+
ThreadRealtimeListVoicesParams,
|
|
17
|
+
ThreadRealtimeListVoicesResponse,
|
|
16
18
|
ThreadRealtimeStartedMessage,
|
|
17
19
|
ThreadRealtimeStartParams,
|
|
18
20
|
ThreadRealtimeStartResponse,
|
|
@@ -26,35 +28,30 @@ if TYPE_CHECKING:
|
|
|
26
28
|
from types import TracebackType
|
|
27
29
|
|
|
28
30
|
from codexed.client import CodexClient
|
|
29
|
-
from codexed.models import
|
|
31
|
+
from codexed.models import (
|
|
32
|
+
CodexEvent,
|
|
33
|
+
RealtimeOutputModality,
|
|
34
|
+
RealtimeVoice,
|
|
35
|
+
RealtimeVoicesList,
|
|
36
|
+
ThreadRealtimeStartTransport,
|
|
37
|
+
)
|
|
30
38
|
|
|
31
39
|
logger = logging.getLogger(__name__)
|
|
32
40
|
|
|
33
41
|
|
|
34
42
|
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
|
-
"""
|
|
43
|
+
"""Async context manager for a thread-scoped realtime voice session."""
|
|
50
44
|
|
|
51
45
|
def __init__(
|
|
52
46
|
self,
|
|
53
47
|
client: CodexClient,
|
|
54
48
|
thread_id: str,
|
|
55
|
-
prompt: str,
|
|
49
|
+
prompt: str | None = None,
|
|
56
50
|
*,
|
|
57
51
|
session_id: str | None = None,
|
|
52
|
+
output_modality: RealtimeOutputModality | None = None,
|
|
53
|
+
transport: ThreadRealtimeStartTransport | None = None,
|
|
54
|
+
voice: RealtimeVoice | None = None,
|
|
58
55
|
) -> None:
|
|
59
56
|
self._client = client
|
|
60
57
|
self._thread_id = thread_id
|
|
@@ -63,6 +60,9 @@ class RealtimeSession:
|
|
|
63
60
|
self._queue: asyncio.Queue[CodexEvent | None] = asyncio.Queue()
|
|
64
61
|
self._closed = False
|
|
65
62
|
self._queue_key = f"realtime:{thread_id}"
|
|
63
|
+
self._output_modality = output_modality
|
|
64
|
+
self._transport = transport
|
|
65
|
+
self._voice = voice
|
|
66
66
|
|
|
67
67
|
@property
|
|
68
68
|
def thread_id(self) -> str:
|
|
@@ -128,13 +128,17 @@ class RealtimeSession:
|
|
|
128
128
|
|
|
129
129
|
async def send_text(self, text: str) -> None:
|
|
130
130
|
"""Send text input to the realtime session."""
|
|
131
|
-
params = ThreadRealtimeAppendTextParams(
|
|
132
|
-
thread_id=self._thread_id,
|
|
133
|
-
text=text,
|
|
134
|
-
)
|
|
131
|
+
params = ThreadRealtimeAppendTextParams(thread_id=self._thread_id, text=text)
|
|
135
132
|
result = await self._client.dispatch.send_request("thread/realtime/appendText", params)
|
|
136
133
|
ThreadRealtimeAppendTextResponse.model_validate(result)
|
|
137
134
|
|
|
135
|
+
async def list_voices(self) -> RealtimeVoicesList:
|
|
136
|
+
"""List available voices for the realtime session."""
|
|
137
|
+
params = ThreadRealtimeListVoicesParams()
|
|
138
|
+
result = await self._client.dispatch.send_request("thread/realtime/listVoices", params)
|
|
139
|
+
data = ThreadRealtimeListVoicesResponse.model_validate(result)
|
|
140
|
+
return data.voices
|
|
141
|
+
|
|
138
142
|
async def send_audio(
|
|
139
143
|
self,
|
|
140
144
|
data: str,
|
|
@@ -7,6 +7,7 @@ from collections.abc import AsyncIterator, Mapping, Sequence # noqa: TC003
|
|
|
7
7
|
import logging
|
|
8
8
|
from typing import TYPE_CHECKING, Any, assert_never
|
|
9
9
|
|
|
10
|
+
from mcp.types import BlobResourceContents, CallToolResult, TextResourceContents
|
|
10
11
|
from pydantic import BaseModel, TypeAdapter
|
|
11
12
|
|
|
12
13
|
from codexed.client.realtime import RealtimeSession
|
|
@@ -17,6 +18,10 @@ from codexed.models import (
|
|
|
17
18
|
ErrorMessage,
|
|
18
19
|
ErrorNotification,
|
|
19
20
|
ExternalSandboxSandboxPolicy,
|
|
21
|
+
McpResourceReadParams,
|
|
22
|
+
McpResourceReadResponse,
|
|
23
|
+
McpServerToolCallParams,
|
|
24
|
+
McpServerToolCallResponse,
|
|
20
25
|
ReadOnlySandboxPolicy,
|
|
21
26
|
ReviewStartParams,
|
|
22
27
|
ReviewStartResponse,
|
|
@@ -24,6 +29,8 @@ from codexed.models import (
|
|
|
24
29
|
TextUserInput,
|
|
25
30
|
ThreadArchiveParams,
|
|
26
31
|
ThreadCompactStartParams,
|
|
32
|
+
ThreadInjectItemsParams,
|
|
33
|
+
ThreadMemoryModeSetParams,
|
|
27
34
|
ThreadReadParams,
|
|
28
35
|
ThreadReadResponse,
|
|
29
36
|
ThreadRollbackParams,
|
|
@@ -48,6 +55,8 @@ from codexed.models import (
|
|
|
48
55
|
|
|
49
56
|
|
|
50
57
|
if TYPE_CHECKING:
|
|
58
|
+
from openai.types.responses import ResponseItem
|
|
59
|
+
|
|
51
60
|
from codexed.client import CodexClient
|
|
52
61
|
from codexed.models import (
|
|
53
62
|
ApprovalsReviewer,
|
|
@@ -62,6 +71,7 @@ if TYPE_CHECKING:
|
|
|
62
71
|
ReviewTarget,
|
|
63
72
|
SandboxMode,
|
|
64
73
|
ServiceTier,
|
|
74
|
+
ThreadMemoryMode,
|
|
65
75
|
ThreadResponse,
|
|
66
76
|
ThreadTokenUsage,
|
|
67
77
|
ToolConfig,
|
|
@@ -71,6 +81,8 @@ if TYPE_CHECKING:
|
|
|
71
81
|
|
|
72
82
|
logger = logging.getLogger(__name__)
|
|
73
83
|
|
|
84
|
+
ResourceContents = TextResourceContents | BlobResourceContents
|
|
85
|
+
|
|
74
86
|
|
|
75
87
|
class Session:
|
|
76
88
|
"""Runtime handle for an active Codex thread.
|
|
@@ -116,6 +128,7 @@ class Session:
|
|
|
116
128
|
service_tier: ServiceTier | None = None,
|
|
117
129
|
summary: ReasoningSummary | None = None,
|
|
118
130
|
collaboration_mode: CollaborationMode | None = None,
|
|
131
|
+
responsesapi_client_metadata: dict[str, Any] | None = None,
|
|
119
132
|
) -> AsyncIterator[CodexEvent]:
|
|
120
133
|
"""Start a turn and stream events.
|
|
121
134
|
|
|
@@ -132,6 +145,7 @@ class Session:
|
|
|
132
145
|
service_tier: Optional service tier (fast/flex)
|
|
133
146
|
summary: Optional reasoning summary mode
|
|
134
147
|
collaboration_mode: Optional collaboration mode preset (experimental)
|
|
148
|
+
responsesapi_client_metadata: Optional turn-scoped Responses API client metadata.
|
|
135
149
|
|
|
136
150
|
Yields:
|
|
137
151
|
CodexEvent: Streaming events from the turn
|
|
@@ -162,11 +176,10 @@ class Session:
|
|
|
162
176
|
policy = sandbox_policy
|
|
163
177
|
case _:
|
|
164
178
|
assert_never(sandbox_policy)
|
|
179
|
+
in_ = [TextUserInput(text=user_input)] if isinstance(user_input, str) else list(user_input)
|
|
165
180
|
params = TurnStartParams(
|
|
166
181
|
thread_id=self.thread_id,
|
|
167
|
-
input=
|
|
168
|
-
if isinstance(user_input, str)
|
|
169
|
-
else list(user_input),
|
|
182
|
+
input=in_,
|
|
170
183
|
model=model,
|
|
171
184
|
effort=effort,
|
|
172
185
|
approval_policy=approval_policy,
|
|
@@ -178,6 +191,7 @@ class Session:
|
|
|
178
191
|
personality=personality,
|
|
179
192
|
summary=summary,
|
|
180
193
|
collaboration_mode=collaboration_mode,
|
|
194
|
+
responsesapi_client_metadata=responsesapi_client_metadata,
|
|
181
195
|
)
|
|
182
196
|
turn_result = await self._client.dispatch.send_request("turn/start", params)
|
|
183
197
|
response = TurnStartResponse.model_validate(turn_result)
|
|
@@ -213,12 +227,14 @@ class Session:
|
|
|
213
227
|
user_input: str | Sequence[UserInput],
|
|
214
228
|
*,
|
|
215
229
|
expected_turn_id: str,
|
|
230
|
+
responsesapi_client_metadata: dict[str, Any] | None = None,
|
|
216
231
|
) -> TurnSteerResponse:
|
|
217
232
|
"""Steer a running turn with additional input.
|
|
218
233
|
|
|
219
234
|
Args:
|
|
220
235
|
user_input: Additional user input
|
|
221
236
|
expected_turn_id: The expected active turn ID (precondition)
|
|
237
|
+
responsesapi_client_metadata: Optional turn-scoped Responses API client metadata.
|
|
222
238
|
|
|
223
239
|
Returns:
|
|
224
240
|
TurnSteerResponse with the turn ID
|
|
@@ -229,6 +245,7 @@ class Session:
|
|
|
229
245
|
if isinstance(user_input, str)
|
|
230
246
|
else list(user_input),
|
|
231
247
|
expected_turn_id=expected_turn_id,
|
|
248
|
+
responsesapi_client_metadata=responsesapi_client_metadata,
|
|
232
249
|
)
|
|
233
250
|
result = await self._client.dispatch.send_request("turn/steer", params)
|
|
234
251
|
return TurnSteerResponse.model_validate(result)
|
|
@@ -407,10 +424,14 @@ class Session:
|
|
|
407
424
|
self,
|
|
408
425
|
target: ReviewTarget,
|
|
409
426
|
*,
|
|
410
|
-
delivery: ReviewDelivery
|
|
427
|
+
delivery: ReviewDelivery = "inline",
|
|
411
428
|
) -> ReviewStartResponse:
|
|
412
429
|
"""Start a code review.
|
|
413
430
|
|
|
431
|
+
Inline delivery runs the review on the same thread, so review items
|
|
432
|
+
appear in the existing thread history. Detached delivery creates a new
|
|
433
|
+
thread for the review, keeping the original thread's history clean.
|
|
434
|
+
|
|
414
435
|
Args:
|
|
415
436
|
target: Review target (uncommittedChanges, baseBranch, commit, or custom)
|
|
416
437
|
delivery: Where to run the review (inline or detached)
|
|
@@ -426,10 +447,14 @@ class Session:
|
|
|
426
447
|
self,
|
|
427
448
|
target: ReviewTarget,
|
|
428
449
|
*,
|
|
429
|
-
delivery: ReviewDelivery
|
|
450
|
+
delivery: ReviewDelivery = "inline",
|
|
430
451
|
) -> AsyncIterator[CodexEvent]:
|
|
431
452
|
"""Start a code review and stream events.
|
|
432
453
|
|
|
454
|
+
Inline delivery runs the review on the same thread, so review items
|
|
455
|
+
appear in the existing thread history. Detached delivery creates a new
|
|
456
|
+
thread for the review, keeping the original thread's history clean.
|
|
457
|
+
|
|
433
458
|
Args:
|
|
434
459
|
target: Review target (uncommittedChanges, baseBranch, commit, or custom)
|
|
435
460
|
delivery: Where to run the review (inline or detached)
|
|
@@ -531,5 +556,53 @@ class Session:
|
|
|
531
556
|
persist_extended_history=persist_extended_history,
|
|
532
557
|
)
|
|
533
558
|
|
|
559
|
+
async def read_resource(self, server: str, uri: str) -> list[ResourceContents]:
|
|
560
|
+
"""Read a resource from the MCP server."""
|
|
561
|
+
params = McpResourceReadParams(server=server, thread_id=self.thread_id, uri=uri)
|
|
562
|
+
result = await self._client.dispatch.send_request("mcpServer/resource/read", params)
|
|
563
|
+
data = McpResourceReadResponse.model_validate(result)
|
|
564
|
+
ta = TypeAdapter[ResourceContents](ResourceContents)
|
|
565
|
+
|
|
566
|
+
def convert(old: BaseModel) -> ResourceContents:
|
|
567
|
+
dct = old.model_dump()
|
|
568
|
+
dct["_meta"] = dct.pop("field_meta")
|
|
569
|
+
return ta.validate_python(dct)
|
|
570
|
+
|
|
571
|
+
return [convert(i) for i in data.contents]
|
|
572
|
+
|
|
573
|
+
async def tool_call(
|
|
574
|
+
self,
|
|
575
|
+
server: str,
|
|
576
|
+
tool: str,
|
|
577
|
+
arguments: Any | None = None,
|
|
578
|
+
meta: dict[str, Any] | None = None,
|
|
579
|
+
) -> CallToolResult:
|
|
580
|
+
"""Call a tool on the MCP server."""
|
|
581
|
+
params = McpServerToolCallParams(
|
|
582
|
+
server=server,
|
|
583
|
+
thread_id=self.thread_id,
|
|
584
|
+
tool=tool,
|
|
585
|
+
arguments=arguments,
|
|
586
|
+
field_meta=meta,
|
|
587
|
+
)
|
|
588
|
+
result = await self._client.dispatch.send_request("mcpServer/tool/call", params)
|
|
589
|
+
data = McpServerToolCallResponse.model_validate(result)
|
|
590
|
+
return CallToolResult(
|
|
591
|
+
structuredContent=data.structured_content,
|
|
592
|
+
isError=data.is_error,
|
|
593
|
+
content=data.content,
|
|
594
|
+
_meta=data.field_meta,
|
|
595
|
+
)
|
|
596
|
+
|
|
534
597
|
def __repr__(self) -> str:
|
|
535
598
|
return f"Session(thread_id={self.thread_id!r})"
|
|
599
|
+
|
|
600
|
+
async def inject_items(self, items: list[ResponseItem]) -> None:
|
|
601
|
+
"""Inject raw responses-API Items into the thread's model-visible history."""
|
|
602
|
+
params = ThreadInjectItemsParams(items=items, thread_id=self.thread_id)
|
|
603
|
+
await self._client.dispatch.send_request("thread/inject_items", params)
|
|
604
|
+
|
|
605
|
+
async def set_memory_mode(self, mode: ThreadMemoryMode) -> None:
|
|
606
|
+
"""Set the thread's memory mode."""
|
|
607
|
+
params = ThreadMemoryModeSetParams(mode=mode, thread_id=self.thread_id)
|
|
608
|
+
await self._client.dispatch.send_request("thread/memoryMode/set", params)
|