python-codex 0.5.2__py3-none-any.whl → 0.6.1__py3-none-any.whl
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.
- pycodex/__init__.py +22 -12
- pycodex/agent.py +89 -74
- pycodex/bootstrap.py +37 -251
- pycodex/cli.py +19 -28
- pycodex/config.py +36 -0
- pycodex/context.py +368 -51
- pycodex/events.py +14 -187
- pycodex/model.py +197 -95
- pycodex/multi_agents.py +401 -0
- pycodex/portable/__init__.py +8 -6
- pycodex/portable/client.py +24 -39
- pycodex/portable/protocol.py +28 -0
- pycodex/portable/server.py +3 -3
- pycodex/prompts/developer_messages.json +13 -0
- pycodex/prompts/goals/budget_limit.md +19 -0
- pycodex/prompts/goals/continuation.md +56 -0
- pycodex/prompts/models.json +1143 -200
- pycodex/protocol.py +81 -15
- pycodex/runtime.py +370 -226
- pycodex/tools/__init__.py +102 -10
- pycodex/tools/agent_tool_schemas.py +0 -38
- pycodex/tools/apply_patch_tool.py +17 -34
- pycodex/tools/base_tool.py +63 -35
- pycodex/tools/clock_manager.py +182 -0
- pycodex/tools/clock_tool.py +58 -187
- pycodex/tools/code_mode_manager.py +165 -246
- pycodex/tools/exec_command_tool.py +0 -18
- pycodex/tools/exec_runtime.py +332 -0
- pycodex/tools/exec_tool.py +74 -31
- pycodex/tools/followup_task_tool.py +44 -0
- pycodex/tools/goal_manager.py +205 -0
- pycodex/tools/goal_tool.py +126 -0
- pycodex/tools/interrupt_agent_tool.py +48 -0
- pycodex/tools/list_agents_tool.py +66 -0
- pycodex/tools/python_tool_schema.py +141 -0
- pycodex/tools/request_permissions_tool.py +1 -0
- pycodex/tools/runtime_services.py +122 -450
- pycodex/tools/send_message_tool.py +42 -0
- pycodex/tools/spawn_agent_tool.py +55 -94
- pycodex/tools/unified_exec_manager.py +26 -35
- pycodex/tools/wait_agent_tool.py +46 -66
- pycodex/tools/wait_tool.py +24 -13
- pycodex/tools/web_search_tool.py +1 -0
- pycodex/utils/codex_config.py +105 -0
- pycodex/utils/compactor.py +4 -0
- pycodex/utils/compat.py +43 -2
- pycodex/utils/doctor.py +5 -4
- pycodex/utils/dotenv.py +0 -7
- pycodex/utils/event_helpers.py +143 -13
- pycodex/utils/history.py +59 -0
- pycodex/utils/session_persist.py +104 -48
- python_codex-0.6.1.dist-info/METADATA +201 -0
- python_codex-0.6.1.dist-info/RECORD +106 -0
- responses_server/__init__.py +2 -0
- responses_server/app.py +10 -7
- responses_server/config.py +6 -12
- responses_server/gemini_api.py +333 -0
- responses_server/messages_api.py +9 -1
- responses_server/payload_processors.py +4 -4
- responses_server/request_translation.py +486 -0
- responses_server/server.py +31 -24
- responses_server/stream_events.py +124 -0
- responses_server/stream_router.py +48 -830
- responses_server/tools/custom_adapter.py +29 -29
- responses_server/tools/web_search.py +3 -0
- responses_server/transport.py +388 -0
- pycodex/tools/close_agent_tool.py +0 -60
- pycodex/tools/exec_runtime.js +0 -161
- pycodex/tools/request_user_input_tool.py +0 -102
- pycodex/tools/resume_agent_tool.py +0 -54
- pycodex/tools/send_input_tool.py +0 -110
- python_codex-0.5.2.dist-info/METADATA +0 -262
- python_codex-0.5.2.dist-info/RECORD +0 -90
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/WHEEL +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/entry_points.txt +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
import uuid
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ResponseOutputStream:
|
|
7
|
+
"""Keep output identities and lifecycle events local to one response."""
|
|
8
|
+
|
|
9
|
+
def __init__(self) -> "None":
|
|
10
|
+
self.items: "typing.List[typing.Dict[str, object]]" = []
|
|
11
|
+
self._next_index = 0
|
|
12
|
+
self._active_item: "typing.Optional[typing.Dict[str, object]]" = None
|
|
13
|
+
self._active_index = 0
|
|
14
|
+
self._text_parts: "typing.List[str]" = []
|
|
15
|
+
|
|
16
|
+
def _event(self, event_type: "str", fields: "typing.Dict[str, object]"):
|
|
17
|
+
return event_type, {"type": event_type, **fields}
|
|
18
|
+
|
|
19
|
+
def _start_item(self, item: "typing.Dict[str, object]"):
|
|
20
|
+
index = self._next_index
|
|
21
|
+
self._next_index += 1
|
|
22
|
+
started = dict(item, id=item.get("id") or "item_" + uuid.uuid4().hex)
|
|
23
|
+
return index, started
|
|
24
|
+
|
|
25
|
+
def text_delta(self, item_type: "str", delta: "str"):
|
|
26
|
+
if self._active_item is not None and self._active_item["type"] != item_type:
|
|
27
|
+
yield from self.finish_text()
|
|
28
|
+
if self._active_item is None:
|
|
29
|
+
item: "typing.Dict[str, object]" = {
|
|
30
|
+
"type": item_type,
|
|
31
|
+
"status": "in_progress",
|
|
32
|
+
"content": [],
|
|
33
|
+
}
|
|
34
|
+
if item_type == "message":
|
|
35
|
+
item["role"] = "assistant"
|
|
36
|
+
else:
|
|
37
|
+
item["summary"] = []
|
|
38
|
+
self._active_index, self._active_item = self._start_item(item)
|
|
39
|
+
yield self._event("response.output_item.added", {
|
|
40
|
+
"output_index": self._active_index,
|
|
41
|
+
"item": deepcopy(self._active_item),
|
|
42
|
+
})
|
|
43
|
+
if item_type == "message":
|
|
44
|
+
yield self._event("response.content_part.added", {
|
|
45
|
+
"item_id": self._active_item["id"],
|
|
46
|
+
"output_index": self._active_index,
|
|
47
|
+
"content_index": 0,
|
|
48
|
+
"part": {"type": "output_text", "text": "", "annotations": []},
|
|
49
|
+
})
|
|
50
|
+
self._text_parts.append(delta)
|
|
51
|
+
event_type = (
|
|
52
|
+
"response.output_text.delta" if item_type == "message"
|
|
53
|
+
else "response.reasoning_text.delta"
|
|
54
|
+
)
|
|
55
|
+
yield self._event(event_type, {
|
|
56
|
+
"delta": delta,
|
|
57
|
+
"item_id": self._active_item["id"],
|
|
58
|
+
"output_index": self._active_index,
|
|
59
|
+
"content_index": 0,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
def finish_text(self):
|
|
63
|
+
if self._active_item is None:
|
|
64
|
+
return
|
|
65
|
+
text = "".join(self._text_parts)
|
|
66
|
+
item = self._active_item
|
|
67
|
+
index = self._active_index
|
|
68
|
+
self._active_item = None
|
|
69
|
+
self._text_parts = []
|
|
70
|
+
is_message = item["type"] == "message"
|
|
71
|
+
part = {
|
|
72
|
+
"type": "output_text" if is_message else "reasoning_text",
|
|
73
|
+
"text": text,
|
|
74
|
+
}
|
|
75
|
+
if is_message:
|
|
76
|
+
part["annotations"] = []
|
|
77
|
+
item = dict(item, status="completed", content=[part])
|
|
78
|
+
fields = {"item_id": item["id"], "output_index": index, "content_index": 0}
|
|
79
|
+
yield self._event(
|
|
80
|
+
"response.output_text.done" if is_message else "response.reasoning_text.done",
|
|
81
|
+
dict(fields, text=text),
|
|
82
|
+
)
|
|
83
|
+
if is_message:
|
|
84
|
+
yield self._event("response.content_part.done", dict(fields, part=deepcopy(part)))
|
|
85
|
+
self.items.append(item)
|
|
86
|
+
yield self._event("response.output_item.done", {
|
|
87
|
+
"output_index": index,
|
|
88
|
+
"item": deepcopy(item),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
def discard_text(self) -> "None":
|
|
92
|
+
# A rejected reasoning-only attempt must never be committed with `done`.
|
|
93
|
+
# Its replacement gets a fresh identity, like an abandoned partial item.
|
|
94
|
+
self._active_item = None
|
|
95
|
+
self._text_parts = []
|
|
96
|
+
|
|
97
|
+
def complete_tool(self, item: "typing.Dict[str, object]"):
|
|
98
|
+
yield from self.finish_text()
|
|
99
|
+
index, completed = self._start_item(dict(item, status="completed"))
|
|
100
|
+
started = dict(completed, status="in_progress")
|
|
101
|
+
field = None
|
|
102
|
+
if item["type"] == "function_call":
|
|
103
|
+
field = "arguments"
|
|
104
|
+
event_prefix = "response.function_call_arguments"
|
|
105
|
+
elif item["type"] == "custom_tool_call":
|
|
106
|
+
field = "input"
|
|
107
|
+
event_prefix = "response.custom_tool_call_input"
|
|
108
|
+
if field is not None:
|
|
109
|
+
started[field] = ""
|
|
110
|
+
yield self._event("response.output_item.added", {
|
|
111
|
+
"output_index": index, "item": started,
|
|
112
|
+
})
|
|
113
|
+
if field is not None:
|
|
114
|
+
fields = {
|
|
115
|
+
"item_id": completed["id"],
|
|
116
|
+
"output_index": index,
|
|
117
|
+
"call_id": completed["call_id"],
|
|
118
|
+
}
|
|
119
|
+
yield self._event(event_prefix + ".delta", dict(fields, delta=completed[field]))
|
|
120
|
+
yield self._event(event_prefix + ".done", dict(fields, **{field: completed[field]}))
|
|
121
|
+
self.items.append(completed)
|
|
122
|
+
yield self._event("response.output_item.done", {
|
|
123
|
+
"output_index": index, "item": deepcopy(completed),
|
|
124
|
+
})
|