python-codex 0.5.2__py3-none-any.whl → 0.6.0__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.
Files changed (71) hide show
  1. pycodex/__init__.py +18 -8
  2. pycodex/agent.py +89 -74
  3. pycodex/bootstrap.py +27 -239
  4. pycodex/cli.py +19 -14
  5. pycodex/config.py +36 -0
  6. pycodex/context.py +369 -51
  7. pycodex/events.py +13 -186
  8. pycodex/model.py +181 -88
  9. pycodex/multi_agents.py +401 -0
  10. pycodex/portable/__init__.py +8 -6
  11. pycodex/portable/client.py +24 -39
  12. pycodex/portable/protocol.py +28 -0
  13. pycodex/portable/server.py +3 -3
  14. pycodex/prompts/developer_messages.json +13 -0
  15. pycodex/prompts/goals/budget_limit.md +19 -0
  16. pycodex/prompts/goals/continuation.md +56 -0
  17. pycodex/prompts/models.json +1069 -140
  18. pycodex/protocol.py +78 -15
  19. pycodex/runtime.py +370 -226
  20. pycodex/tools/__init__.py +100 -7
  21. pycodex/tools/agent_tool_schemas.py +0 -38
  22. pycodex/tools/apply_patch_tool.py +17 -34
  23. pycodex/tools/base_tool.py +63 -35
  24. pycodex/tools/clock_manager.py +182 -0
  25. pycodex/tools/clock_tool.py +2 -181
  26. pycodex/tools/code_mode_manager.py +165 -246
  27. pycodex/tools/exec_command_tool.py +0 -18
  28. pycodex/tools/exec_runtime.py +381 -0
  29. pycodex/tools/exec_tool.py +78 -31
  30. pycodex/tools/followup_task_tool.py +44 -0
  31. pycodex/tools/goal_manager.py +205 -0
  32. pycodex/tools/goal_tool.py +126 -0
  33. pycodex/tools/interrupt_agent_tool.py +48 -0
  34. pycodex/tools/list_agents_tool.py +66 -0
  35. pycodex/tools/python_tool_schema.py +141 -0
  36. pycodex/tools/request_permissions_tool.py +1 -0
  37. pycodex/tools/request_user_input_tool.py +3 -23
  38. pycodex/tools/runtime_services.py +122 -450
  39. pycodex/tools/send_message_tool.py +42 -0
  40. pycodex/tools/spawn_agent_tool.py +55 -94
  41. pycodex/tools/unified_exec_manager.py +26 -35
  42. pycodex/tools/wait_agent_tool.py +46 -66
  43. pycodex/tools/wait_tool.py +24 -13
  44. pycodex/tools/web_search_tool.py +1 -0
  45. pycodex/utils/codex_config.py +105 -0
  46. pycodex/utils/compactor.py +4 -0
  47. pycodex/utils/compat.py +2 -2
  48. pycodex/utils/doctor.py +5 -4
  49. pycodex/utils/event_helpers.py +143 -13
  50. pycodex/utils/history.py +33 -0
  51. pycodex/utils/session_persist.py +78 -36
  52. {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/METADATA +117 -27
  53. python_codex-0.6.0.dist-info/RECORD +106 -0
  54. responses_server/__init__.py +2 -0
  55. responses_server/app.py +7 -6
  56. responses_server/config.py +0 -11
  57. responses_server/payload_processors.py +4 -4
  58. responses_server/request_translation.py +480 -0
  59. responses_server/server.py +31 -24
  60. responses_server/stream_events.py +124 -0
  61. responses_server/stream_router.py +33 -830
  62. responses_server/tools/custom_adapter.py +29 -29
  63. responses_server/transport.py +332 -0
  64. pycodex/tools/close_agent_tool.py +0 -60
  65. pycodex/tools/exec_runtime.js +0 -161
  66. pycodex/tools/resume_agent_tool.py +0 -54
  67. pycodex/tools/send_input_tool.py +0 -110
  68. python_codex-0.5.2.dist-info/RECORD +0 -90
  69. {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/WHEEL +0 -0
  70. {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/entry_points.txt +0 -0
  71. {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-codex
3
- Version: 0.5.2
3
+ Version: 0.6.0
4
4
  Summary: A minimal Python extraction of Codex's main agent loop
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.6.2
@@ -23,10 +23,15 @@ Description-Content-Type: text/markdown
23
23
  [中文](README_ZH.md)
24
24
 
25
25
  pycodex brings the [Codex](https://github.com/openai/codex) agent loop to Python,
26
- with a CLI, reusable Agent API and browser workspace. It aims to follow upstream
27
- behavior; supported features and deliberate differences are documented in
26
+ with a CLI, reusable Agent API and browser workspace. It targets upstream default
27
+ behavior for the selected features, model and protocol; supported features and
28
+ deliberate differences are documented in
28
29
  [Alignment](docs/ALIGNMENT.md).
29
30
 
31
+ Intentional boundaries include no sandbox enforcement or collaboration-mode
32
+ switching, no OpenAI-specific model/effort allowlists for sub-agents, and no
33
+ requirement to mirror every OpenAI model-catalog entry.
34
+
30
35
  | Package | Provides | Python |
31
36
  | --- | --- | --- |
32
37
  | `python-codex` | Agent, runtime, CLI, tools, Responses compatibility server and portable storage | 3.6.2+ |
@@ -35,6 +40,12 @@ behavior; supported features and deliberate differences are documented in
35
40
  The workspace package installs the matching core version. Python imports use
36
41
  `pycodex`; the commands are `pycodex` and `pycodex-ws`.
37
42
 
43
+ The `exec` tool runs Python with top-level `await` in the host process. Each cell
44
+ has its own namespace, output and tracked asyncio tasks; imports and process
45
+ state are shared. Stopping is cooperative, so run blocking work through
46
+ `tools.exec_command`. Direct file access can use the cell's `cwd` Path.
47
+ See [exec lifecycle and limits](docs/RUNTIME.md#python-exec-cells).
48
+
38
49
  ## Install and run
39
50
 
40
51
  Install the core CLI:
@@ -63,14 +74,21 @@ The built-in `openai` provider uses `OPENAI_API_KEY`. Authentication uses API
63
74
  keys; ChatGPT sign-in credentials from `auth.json` or the OS keychain are not
64
75
  loaded.
65
76
 
77
+ `--profile NAME` selects an adjacent `NAME.config.toml` or an embedded
78
+ `[profiles.NAME]` table. Both recursively merge over the base config, including
79
+ provider and feature tables. A top-level `profile = "NAME"` sets the default;
80
+ `--profile` overrides it. Duplicate names across both formats and missing selected
81
+ profiles are errors. Existing embedded profiles can be used without migration.
82
+
66
83
  ```bash
67
84
  pycodex --profile my_profile "Summarize this repository."
68
85
  pycodex --config /path/to/config.toml
69
86
  pycodex doctor
70
87
  ```
71
88
 
72
- Models use the streaming Responses API. For a Chat Completions backend, set
73
- `use_chat_completion = true` in its provider table. Other backend options include:
89
+ Models use the streaming Responses API; OpenAI models use native Responses
90
+ directly. For a vLLM Chat Completions backend, set `use_chat_completion = true`
91
+ in its provider table. Other backend options include:
74
92
 
75
93
  ```bash
76
94
  pycodex --vllm-endpoint http://127.0.0.1:18000
@@ -79,6 +97,16 @@ pycodex --profile my_profile --use-messages
79
97
 
80
98
  See [context and configuration](docs/CONTEXT.md) and the
81
99
  [Responses compatibility server](docs/responses_server/README.md).
100
+ The compatibility server supports namespaced function/custom tools, including
101
+ upstream Codex subagent tools, with namespace restoration on returned calls.
102
+ Text and reasoning streams include item lifecycle events for Codex's live display.
103
+
104
+ For `step-5-preview` on Step's `step_plan/v1` endpoint, enable
105
+ `use_chat_completion = true` in the Step provider or profile: its native Responses
106
+ endpoint does not expose namespaced collaboration tools correctly. The adapter
107
+ presents names such as `collaboration__spawn_agent` as ordinary functions.
108
+ Prompts follow the declared direct-call names and describe Python `exec`
109
+ collaboration only when both `exec` and collaboration tools are visible.
82
110
 
83
111
  ## CLI
84
112
 
@@ -98,7 +126,6 @@ pycodex --json "Reply with exactly OK."
98
126
  | `/title`, `/history` | Manage the title and inspect conversation history |
99
127
  | `/resume` | List saved sessions; pass an index or session UUID to resume |
100
128
  | `/compact` | Summarize history to free context |
101
- | `/fork` | Continue the current history under a new session ID |
102
129
  | `/queue <message>` | Wait for the active turn to finish before submitting |
103
130
 
104
131
  Ordinary input during a turn steers at the next safe sampling boundary.
@@ -110,8 +137,10 @@ These rules also apply to the browser workspace and Feishu.
110
137
  Sessions are saved under `CODEX_HOME/sessions`. Set
111
138
  `model_auto_compact_token_limit` in the configuration to compact automatically.
112
139
 
113
- Ctrl+D or Ctrl+C closes the CLI after accepted work finishes. A second Ctrl+C
114
- during closing exits immediately. Use `pycodex --help` for startup options.
140
+ Ctrl+D or Ctrl+C stops the session and its child agents: pending turns are
141
+ discarded, and active turns stop after issued model/tool operations finish.
142
+ Session close uses the same behavior. A second Ctrl+C during closing exits
143
+ immediately. Use `pycodex --help` for startup options.
115
144
 
116
145
  ## Browser workspace
117
146
 
@@ -132,17 +161,28 @@ pycodex-ws --listen 127.0.0.1:6007 --workspace-config workspaces.json
132
161
  Open `http://127.0.0.1:6007`. The workspace combines conversations with a live
133
162
  HTML Canvas and read-only file/diff viewers. Click file links in replies to open
134
163
  them, and use **Insert into chat** to add selected code to an editable draft.
164
+ Text and image views support files up to 10 MiB each.
165
+ The context ring opens the built-in Agent tree with `n running · m failed` counts
166
+ (including the root), each Agent's turn duration, and error details for failures.
167
+ Click a root or child Agent in the popover to open its live transcript tab.
168
+ Compare local files with `diff:left..right`; either path can be absolute or relative.
169
+ Use `[TODO](TODO.md)` for a local file link; bare filenames stay as text.
135
170
  Local PDF links open in the browser's built-in reader, with **Open in new tab**
136
171
  and **Download** links. PDF files are streamed separately from text snapshots.
137
172
  Keep the server's stdin open: EOF initiates shutdown.
138
- **New session** directly creates a session using the launch `--profile`, or the
139
- base config when unset. The **+** button on its right (**Custom profile**) lets
140
- you choose a named profile from the server's Codex config; **Default** uses the
141
- launch setting. Each session saves its profile name and uses it again on restart; existing sessions
173
+ **New session** uses the launch `--profile`, then the config's default `profile`,
174
+ then the base config. The **+** button on its right (**Custom profile**) lets
175
+ you choose from adjacent `*.config.toml` files and embedded `[profiles.NAME]`
176
+ tables; **Default** uses the same default selection.
177
+ Each session saves its profile name and uses it again on restart; existing sessions
142
178
  keep their configuration. Restart the server after adding or removing profiles.
179
+ The page loads the last selected session directly on reopening. Switching back
180
+ to a visited session immediately restores its rendered messages and scroll
181
+ position, then refreshes its content from the server.
143
182
  While the selected Agent is working, the empty composer cycles through usage
144
- hints about commands, frontend customization, workspace sharing, session collaboration and optional
145
- features about every six seconds, starting at a random hint. Edit the short
183
+ hints about commands, frontend customization, workspace sharing, Agent status,
184
+ live transcripts and optional features, including clock tick dividers, about every
185
+ six seconds, starting at a random hint. Edit the short
146
186
  strings in the `hints` list in `workspace.html`'s `updatePromptPlaceholder` to change the tips.
147
187
  The gear button opens **Customize Agent** and **Share**, with a short description of each.
148
188
  Customize Agent starts an Agent conversation for editing files in
@@ -171,20 +211,69 @@ workspace backend, including on Remote SSH hosts.
171
211
  Use the standard model and tool setup from Python:
172
212
 
173
213
  ```python
174
- from pycodex.bootstrap import build_agent, build_model
175
-
176
- agent = build_agent(build_model())
177
- try:
178
- result = agent.ask("Summarize this repository in one sentence.")
179
- print(result.output_text)
180
- finally:
181
- agent.shutdown()
214
+ import atexit
215
+
216
+ from pycodex import AgentsManager, CodexConfig
217
+ from pycodex.bootstrap import build_model
218
+ from pycodex.utils.async_bridge import run_async
219
+
220
+ async def main():
221
+ config = CodexConfig.from_env()
222
+ bootstrap = build_model(config.provider)
223
+ if bootstrap.owned_server is not None:
224
+ atexit.register(bootstrap.owned_server.stop)
225
+ runtime = AgentsManager(
226
+ bootstrap.client, config.context,
227
+ ).create_root_runtime()
228
+ await runtime.start()
229
+ try:
230
+ receipt = await runtime.submit_input("Summarize this repository in one sentence.")
231
+ print((await receipt.future).output_text)
232
+ finally:
233
+ await runtime.close()
234
+
235
+ run_async(main())
182
236
  ```
183
237
 
184
- For custom integrations, `Agent` accepts a model client, `ToolRegistry` and
185
- `ContextConfig`. `await agent.run_turn([...])` runs an asynchronous turn;
186
- `AgentRuntime` adds input queues, commands and frontend subscriptions.
187
- See [runtime contracts and examples](docs/RUNTIME.md).
238
+ `CodexConfig.from_env(path, profile)` loads the selected TOML and adjacent `.env`
239
+ once for startup. Pass `config.provider` to `build_model` and `config.context` to
240
+ `AgentsManager`; use `dataclasses.replace` for explicit overrides, including `None`.
241
+ API keys are still read from the environment when requests are sent.
242
+ `build_model` returns `ModelBootstrapResult(client, owned_server)`. The caller owns
243
+ any locally started compatibility server; `close()` stops only that server.
244
+ CLI and workspace entry points retain process-exit cleanup for these services.
245
+
246
+ For custom integrations, `Agent` requires a model client, `ToolRegistry`,
247
+ `ContextConfig` and `session_id`. `await agent.run_turn([...])` runs an asynchronous
248
+ turn; `AgentRuntime(agent, agents_manager)` adds input queues, commands and frontend
249
+ subscriptions. `AgentsManager` owns the tree of named tasks and supplies the
250
+ standard construction path.
251
+
252
+ The current prototype uses MultiAgentV2 tools: `spawn_agent`, `send_message`,
253
+ `followup_task`, `wait_agent`, `interrupt_agent` and `list_agents`. Child context
254
+ inheritance uses `fork_turns`; the session `/fork` command has been removed.
255
+ `features.multi_agent_v2.max_concurrent_threads_per_session` sets the total
256
+ capacity, defaulting to 16 including the root. When full, spawn closes the least
257
+ recently used idle leaf with no pending or background work, or reports a capacity
258
+ error. Closed children are removed from the Agent tree and Workspace views;
259
+ their task names can be reused. The Manager retains closing child references
260
+ until their cleanup finishes, even after they leave the live tree.
261
+ Recorded sessions retain the clock period in a small environment snapshot beside
262
+ the rollout. Resuming starts a fresh countdown and restores `idle: sleeping`
263
+ in attached frontends; child Agents remain in memory.
264
+ Runtime reads execution facts through `Agent.execution_snapshot()`; session
265
+ history and live-state snapshots retain their separate frontend formats.
266
+ Tool factories register shared resource managers with the environment, which
267
+ owns their callbacks, restart, background state and cleanup. Tools provide their
268
+ model-callable behavior. Pass `tools_factory(manager, environment, toolset)` to
269
+ `AgentsManager` to construct custom tools for both root and child Agents; see the
270
+ [resource contract](docs/RUNTIME.md#tools).
271
+ Model clients expose explicit recording metadata; Agent supplies each request's
272
+ session identity through `Prompt`, including compaction and resumed sessions.
273
+ Tool summaries and conversation-history projections are pure helpers shared by
274
+ event and session views.
275
+ See [runtime contracts](docs/RUNTIME.md), [context assembly](docs/CONTEXT.md) and
276
+ the [versioned alignment baseline and remaining differences](docs/ALIGNMENT.md).
188
277
 
189
278
  ## Portable configuration
190
279
 
@@ -222,7 +311,8 @@ uv run --dev pytest
222
311
  - [Responses compatibility server](docs/responses_server/README.md)
223
312
  - [Portable configuration contracts](docs/PORTABLE.md)
224
313
 
225
- Release notes and implementation details live in `docs/`.
314
+ See the [0.6.0 release notes](https://github.com/Randomizez/pycodex/blob/v0.6.0/docs/RELEASE_0.6.0.md) for the major changes and
315
+ Python integration migration from 0.5.0. Implementation details live in `docs/`.
226
316
 
227
317
  ## Markdown view modes
228
318
 
@@ -0,0 +1,106 @@
1
+ pycodex/__init__.py,sha256=2DyU0vUq3EAS1Pya-farjLv4Z86k8JxVJqRnkeSXNQM,2918
2
+ pycodex/__main__.py,sha256=MHKZ_ae3fSLGTLUUMOx15fWdeOnJSHhq-zslRP5F5Lc,79
3
+ pycodex/agent.py,sha256=yZ75cpCBM2acDBayKo9ekqHZRvODXsKtJFjyhm78v9M,22704
4
+ pycodex/bootstrap.py,sha256=OhSzxwyi54bXwuO2tM9Q0AJGem46nQ24l08XEpH77V4,5070
5
+ pycodex/cli.py,sha256=yEwPZLehVrWd-vs-cWyb_8PCqt9INb5O08YlILYn5pQ,13077
6
+ pycodex/config.py,sha256=mGM7oLaciBwGXHMQjKVifWFTd7gZTfzqlQeJSFzcQic,1218
7
+ pycodex/context.py,sha256=K8Q-PRNj9GQ79KdQXb_U1YhmgvnDEqsGhZ12_kbISX8,41076
8
+ pycodex/events.py,sha256=qJnQItZOq4xs9JAbaEzDng1WdiqlH7i3D9fSIy36mHg,22749
9
+ pycodex/model.py,sha256=13EP4v2Hlry5_cQ8hxYDj2fgSLpPWBxiA5yt1UB_WoI,58201
10
+ pycodex/multi_agents.py,sha256=3KN_Ai3UremtsQppvxd0pE7pFam_v0zBastCNi-NNx8,16150
11
+ pycodex/protocol.py,sha256=Jl0-Zah0mzb04HlBF3SLk5XwtALec7M9IPn_0BZnTNQ,14568
12
+ pycodex/runtime.py,sha256=Szeufq_cAPSw_r7HCmpin1nm_Ugsj3FCcn-pgCCkrrI,37525
13
+ pycodex/portable/__init__.py,sha256=NgACNTFK5hbRK6fqbL89qjPuh44N950pr4eoDWLfKD4,1110
14
+ pycodex/portable/client.py,sha256=ZvXjKCB557ZZ-ELmec9DIxymWbG8QBZsaU6e0axu0T0,15508
15
+ pycodex/portable/protocol.py,sha256=jtyPHI3aVY4UldlSIzeZRQX3MCFzPYfG-0iDC6JSWYo,931
16
+ pycodex/portable/server.py,sha256=UCQAqcO0OTNkEv4MQgR-fIt1y5bzdqMndFJtMm16Lqk,7503
17
+ pycodex/prompts/default_base_instructions.md,sha256=D65mcj6bo4CDvVom-D9cbJRJVNquo0NghKt164_fRsg,20923
18
+ pycodex/prompts/developer_messages.json,sha256=E-CAWMOL2KoImJ1U_1aA-OYbuVtJF0-GtZkn983B-TI,4007
19
+ pycodex/prompts/models.json,sha256=fq_8UCJ8EJ_0ajUWrnYwwU4I1a9d9UWjJbdLdGaynGk,611262
20
+ pycodex/prompts/goals/budget_limit.md,sha256=RbvI03fMD3tTy-ytnzylqAsIr9b2O_Cb81CQejR1J-k,775
21
+ pycodex/prompts/goals/continuation.md,sha256=K7OtQKQNoCKcgne-e-SQBGJjEpnCVcVCtML7T-82bWI,6153
22
+ pycodex/prompts/permissions/approval_policy/never.md,sha256=QceTG6wjkaJARjYr0HYV1aPnPcpGcrkRUW-smWRr6MQ,120
23
+ pycodex/prompts/permissions/approval_policy/on_failure.md,sha256=dfJjpXkpO6_ANdCKxbVJ8o4vyLxevrJWfKsGHTqtbkc,289
24
+ pycodex/prompts/permissions/approval_policy/on_request.md,sha256=hVQalzh0FAdkKzw5u-N4H7-LtC9ijVDlYsh3OKsZKzo,3661
25
+ pycodex/prompts/permissions/approval_policy/on_request_rule_request_permission.md,sha256=mOinishp1k-wlPsaEuIOMn5GoVm_dAIsWIuEMmv2r7o,1725
26
+ pycodex/prompts/permissions/approval_policy/unless_trusted.md,sha256=XHpi1Lfx1iIXFbbQ_ho_kGstA3JN-RLho291HM30UNw,247
27
+ pycodex/prompts/permissions/sandbox_mode/danger_full_access.md,sha256=nZ7YHacBd3cAHKRZc9XClOOOnXJPXPh0WFBueh5C2D0,197
28
+ pycodex/prompts/permissions/sandbox_mode/read_only.md,sha256=2rAPEXsBYCcuttI5j3euS-3uv_v97catIsnhxlSQSIM,173
29
+ pycodex/prompts/permissions/sandbox_mode/workspace_write.md,sha256=lVN-LwrBbHqlv5yVjcd_mU8tzZW8jfKpTatJKIZu9HI,277
30
+ pycodex/tools/__init__.py,sha256=fMNf_nlYvgCuP0EkkYPb0Jh82GLkuKFqVYnpumDtbvs,5231
31
+ pycodex/tools/agent_tool_schemas.py,sha256=juw4b2pp2tDhDPVTVY4rytm8IyVr2h686Qfk_5e9S0E,780
32
+ pycodex/tools/apply_patch_tool.py,sha256=LcyJuGtndmLLbFL1sIUQ2Y6KLCef95KBfi0adGA1bN8,13183
33
+ pycodex/tools/base_tool.py,sha256=dD_makVyjbnJN_cAhRAj_sJJHYh8VUDoXFiRoWDh6Ko,8644
34
+ pycodex/tools/clock_manager.py,sha256=Xn1i4aasN_ZZdL9WsA_cS-RAVLV-SQXmOecMc1nGCa4,5884
35
+ pycodex/tools/clock_tool.py,sha256=G4SSchZq8qAz-Rjc2qAbN2bFTIkD7pUsNRFL4K3fvj8,2100
36
+ pycodex/tools/code_mode_manager.py,sha256=_bZ7RlKzAEqb2m6PBfR7Or1GJYajeuSz1xCmuJcGsV8,15975
37
+ pycodex/tools/exec_command_tool.py,sha256=Mf2FRsx6o5pWq68PCXNCSOce4wzwqyX6VrXNOvym_So,4076
38
+ pycodex/tools/exec_runtime.py,sha256=AEmZw0eH4omw2ssOJXGcHR4YpVAmOyeHlU60p73cDao,14227
39
+ pycodex/tools/exec_tool.py,sha256=0X3obuj6XPa0qamQK_WAmwhALZmd8zbFVjCBLGfKbYs,5477
40
+ pycodex/tools/followup_task_tool.py,sha256=D3nRu6csiriwe1WVig_HNLRzJQfDNMmk2R75vMfSI4Y,1609
41
+ pycodex/tools/goal_manager.py,sha256=8zicCSjqJgYyONL6EaOIyaGjTA6EBECi1NYQgEwLFms,8480
42
+ pycodex/tools/goal_tool.py,sha256=TShHf6dh6YCdMPoc6zuIgj0W2D_O95ewmh6OZKFXAX0,5225
43
+ pycodex/tools/grep_files_tool.py,sha256=KCBVNaSTU45ND-iAhh14YawMyjQnMRZnGI1NGKL3zgg,4809
44
+ pycodex/tools/interrupt_agent_tool.py,sha256=q4TBTam6sFLwAQwDsoz1WNL_b9y1Esne7awgc77gerw,1589
45
+ pycodex/tools/list_agents_tool.py,sha256=_8WLGZiD006Txw2GRwgda2TVPWSbyfZVUD9-2RK5Xn0,2366
46
+ pycodex/tools/list_dir_tool.py,sha256=_U6ouRcVbGHT5mChVyUsiMgDGrFK7EFMFaspPLAHtH8,5337
47
+ pycodex/tools/python_tool_schema.py,sha256=yoJHP7GJGSu6oyT_0nxbGJWy_TaTobFwDoFQMl65464,5781
48
+ pycodex/tools/read_file_tool.py,sha256=YK__uhIVldBjAQega5S_ZuZU5jgP_kLOwr-YhjAmRo4,9735
49
+ pycodex/tools/request_permissions_tool.py,sha256=t-Y-iEhvUyE9IJAeiwnzfUdbQ73Gw7uxFcWLwS0no4o,4000
50
+ pycodex/tools/request_user_input_tool.py,sha256=rVjJPVzrkBPmAQkfPWiCvAuIAp0Lt8WwuVgfbNbbeHY,2893
51
+ pycodex/tools/runtime_services.py,sha256=oEqUyR7-oHQdTsEWXoiP7VKP_JDiG5dc8AjlSGQFjYI,7542
52
+ pycodex/tools/send_message_tool.py,sha256=mH51ufxTCcsHuLFI1tDKyX14AHPMij2cMJLJdlFFjZQ,1414
53
+ pycodex/tools/shell_command_tool.py,sha256=bJKlTdIs2i28vH5f4GZfpunezr6JNicRzsL_6Vc3HvU,3675
54
+ pycodex/tools/shell_tool.py,sha256=I6lYLABSmLddRrNmpk0Li83AV55MI8x0bckWaRkFGI0,3527
55
+ pycodex/tools/spawn_agent_tool.py,sha256=yjkjHsUxGdSHOn9_kZTs8Bd-0ZnWznZxOfcy3E-WKcA,3596
56
+ pycodex/tools/unified_exec_manager.py,sha256=O1o2dGkLsOLFf1XZ0_HeQQT_NIlDT6NOC1y2_OaYchw,14479
57
+ pycodex/tools/update_plan_tool.py,sha256=xwrSrerw5qfkbFc9Ltx1OZEmD__CWtryOy3UhL0-Jp4,3198
58
+ pycodex/tools/view_image_tool.py,sha256=H7OP-QZEU5Gf-E4YnQbXfu2hDkL5-dJ3Apla2YYjErQ,3754
59
+ pycodex/tools/wait_agent_tool.py,sha256=uo4KcFZBm8BAmw7i_wVjg2i3f_T9PrGL4ZnxbGt3-38,2516
60
+ pycodex/tools/wait_tool.py,sha256=fGpLbNP236xefDKg7wdJckzwEjFoCOTYV_OW-qruyfg,3637
61
+ pycodex/tools/web_search_tool.py,sha256=RDdBy0TiaG2FPKOoHoWvSKUhq0yW_o2VXViTNq9uPoU,1010
62
+ pycodex/tools/write_stdin_tool.py,sha256=jvBDchLLmoDITd7g-ZVeEVXHRhWKkmnjM5laL-53FOM,3609
63
+ pycodex/utils/__init__.py,sha256=ih_KyZ2_bajR5YlZ1QMTWOHnuEBda-S3gQ7PwnBtLZQ,453
64
+ pycodex/utils/async_bridge.py,sha256=BXsKTUTUvUtPJnItQlulFRdV7opdKKDlsKLdtVTYshs,1732
65
+ pycodex/utils/codex_config.py,sha256=oCisEGUJcJxcZL1wIqXkon1xTShymOlz96E3VgDVTlY,3748
66
+ pycodex/utils/compactor.py,sha256=IzRC6bY1ab6WP33jRMFMbmlJ3TMJcoTgDFFG-Y4C86E,6299
67
+ pycodex/utils/compat.py,sha256=OaUWtldoMYYuRgVCbrsuN2J3jsVUa_Xt8Wg3mjHcG2o,3572
68
+ pycodex/utils/crypto.py,sha256=HRCXF26Ft3S8CG2X0YpZwa8GMU9YJ0Loo8Q9PMPMcNw,1249
69
+ pycodex/utils/debug.py,sha256=5XMpWpwFSm6woyx6RGXvN2qL0afRtTQbwlOAv-LotTw,913
70
+ pycodex/utils/doctor.py,sha256=xhPflFEYFfmtQ4-LjnIyz-cNts0GjNtAK0inVTYfKiI,10764
71
+ pycodex/utils/dotenv.py,sha256=h7ZgvqpEswetqjhtwfiaHyokAHwNKPakizTAHPHz5Ds,1865
72
+ pycodex/utils/event_helpers.py,sha256=VH8MMmpAO98EFb-PeEKjqAw8LCiGGaWegENP9Jnc6kA,12021
73
+ pycodex/utils/get_env.py,sha256=L4S8h84tkgxZKvrxY7ezTgePbXepG-yIigUTKeY6uuE,6094
74
+ pycodex/utils/history.py,sha256=wCyf2Jf4flqzSEIKmebbdkwclfEMzl0Af7VZOgrpu24,1338
75
+ pycodex/utils/image_utils.py,sha256=OUzUs0Cow4L8Z2np0EBeEUotAqqsCmRmhrV8AxZUXRw,2460
76
+ pycodex/utils/model_metadata.py,sha256=uK3iI4yC7Ge7yN4I1_gQYalQ4MYKddz2qMwsmQb-P80,1337
77
+ pycodex/utils/random_ids.py,sha256=jLTxZZ0MBbRdQOFDFWGVRjWzIo6FKSQ5ADXbQSLPp1s,379
78
+ pycodex/utils/session_persist.py,sha256=mtYUZGkF0ag49aEmIPidwls-2zNafVf5SWMtGsa3DmU,27024
79
+ pycodex/utils/truncation.py,sha256=5D6vAorT8EgXgjd7ASwtraAyIZdlCR-w5jKZqJxDzho,5446
80
+ pycodex/utils/_aes_gcm/LICENSE,sha256=KvdHagY3sYIK34GldJaRi34sNnGwMVJIIoDhbC9MRu8,2805
81
+ pycodex/utils/_aes_gcm/README.md,sha256=D9XGeewCgU2PVqJCO6WusUs0Mw2FbMnABCqaVktqCnE,3045
82
+ pycodex/utils/_aes_gcm/__init__.py,sha256=p0U1CVy6dQBDAfGvSYG0opn6iP2VGF5rqUUM-mNLJxU,70
83
+ pycodex/utils/_aes_gcm/aes.py,sha256=12p_5O7gX-e-LQ08nNe2CBdP_H4eX3J84LlXaVr9i8A,9269
84
+ pycodex/utils/_aes_gcm/gcm.py,sha256=Z8fYHpnLpqJyTPmjDOZtryqe0xmT_93vscNuJe5ZY-w,2762
85
+ pycodex/utils/_aes_gcm/source-sha256.json,sha256=g9uPWXuA0D9Wq9EGnduyiVanTgi8QWRFW-9T69FG-fc,215
86
+ responses_server/__init__.py,sha256=SOMO5Q-Z0dpaRih8yWuKUTclPl28tpy_XIPTOO_BPq0,447
87
+ responses_server/__main__.py,sha256=876xZTqhPeDBD2GKKr8pKX33Af8PhFTosAI8bYQsFgQ,61
88
+ responses_server/app.py,sha256=SvH8xL3OlWXqC_yW04bMvlRvU9v6PjmI2nf70qF7ZiQ,8413
89
+ responses_server/config.py,sha256=ktUQlDT33vzfCuPvaMPNa7JRArEL5B-Yi1ngJPzR91Q,2374
90
+ responses_server/messages_api.py,sha256=ialAYTMmN0y-uxQB3Y51ukq-kvkSVO84WVLXaqLsKw0,18775
91
+ responses_server/payload_processors.py,sha256=jIiGCHGFootnkwPpZiM1-Zv1WKziHlklSWGo050hBgU,3567
92
+ responses_server/request_translation.py,sha256=0i8rserasFDcBbvrOL0zJd8A-9ULjFl7-LC40U8v8Oc,18479
93
+ responses_server/server.py,sha256=hFSRU3GjYa9cI1YSDxKvg2gLjp3OJ_Mh_JFyau3yzl4,2535
94
+ responses_server/session_store.py,sha256=nwGxQL6nUVKnDVeDHz8IzqNQ7dWk8Ybf0URekOHdxTo,1133
95
+ responses_server/stream_events.py,sha256=nWi5VcssytFD3SDHW5hQik5LR-US-Clk-5EEWAi3t-k,4984
96
+ responses_server/stream_router.py,sha256=jFm_YFb0f0FwYude42Hsm1juSF29n_vy1M7oUZ7tyR8,14216
97
+ responses_server/trajectory_dump.py,sha256=5_Wy6tslszrqx3j1JeP_boyTbzIicKy8No84PzMnmHk,5111
98
+ responses_server/transport.py,sha256=u-RiWvJeLMpifveQuODx7fcbjWKqlgRjXjq6GP6ly2Y,13557
99
+ responses_server/tools/__init__.py,sha256=ivsBSEy0SBUhY-Uea5v1XMLXShkwHdCVl0id-1FwdZg,150
100
+ responses_server/tools/custom_adapter.py,sha256=leYNJKp4Ute0JWNfGpe-ntSyFqRgYCdWF4dMYQFINlk,8615
101
+ responses_server/tools/web_search.py,sha256=pnKH9JyTScRehWpZS3HpXRvjWsQvC0QZqxjEOCT4ndg,8936
102
+ python_codex-0.6.0.dist-info/METADATA,sha256=tZYTIoKC6b9lSS0z2EGgozUUAVv-xOTHiX78PZKrrP4,16661
103
+ python_codex-0.6.0.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
104
+ python_codex-0.6.0.dist-info/entry_points.txt,sha256=sNUVakoVuTrzJH505ZgRTQxmtRRPUHV_EH0i6EbYTyM,45
105
+ python_codex-0.6.0.dist-info/licenses/LICENSE,sha256=0X8ifk312hYAORM4hlzg8wVSEXYKNmiPgWlB1YIy2Nw,10926
106
+ python_codex-0.6.0.dist-info/RECORD,,
@@ -2,11 +2,13 @@ from .app import ManagedResponseServer, launch_chat_completion_compat_server, ru
2
2
  from .config import CompatServerConfig
3
3
  from .server import ResponseServer
4
4
  from .stream_router import StreamRouter
5
+ from .transport import OutcommingTransport
5
6
 
6
7
  __all__ = [
7
8
  "CompatServerConfig",
8
9
  "ManagedResponseServer",
9
10
  "ResponseServer",
11
+ "OutcommingTransport",
10
12
  "launch_chat_completion_compat_server",
11
13
  "run_server",
12
14
  "StreamRouter",
responses_server/app.py CHANGED
@@ -16,8 +16,9 @@ from starlette.responses import JSONResponse, StreamingResponse
16
16
  from starlette.routing import Route
17
17
 
18
18
  from .config import CompatServerConfig
19
- from .server import ResponseServer
20
- from .stream_router import OutcommingChatError, UnsupportedIncommingFeature
19
+ from .request_translation import UnsupportedIncommingFeature
20
+ from .server import PreparedResponse, ResponseServer
21
+ from .transport import OutcommingChatError
21
22
 
22
23
 
23
24
  def _run_uvicorn_server(server) -> "None":
@@ -40,12 +41,12 @@ def _format_sse_event(
40
41
 
41
42
  def _stream_events(
42
43
  response_server: "ResponseServer",
43
- request_body: "typing.Dict[str, object]",
44
+ prepared: "PreparedResponse",
44
45
  request_headers: "typing.Dict[str, str]",
45
46
  ) -> "Iterator[bytes]":
46
47
  try:
47
48
  event_iter = response_server.start_response_stream(
48
- request_body, request_headers
49
+ prepared, request_headers
49
50
  )
50
51
  for event_name, payload in event_iter:
51
52
  yield _format_sse_event(event_name, payload)
@@ -159,7 +160,7 @@ class ManagedResponseServer:
159
160
  str(key).lower(): str(value) for key, value in request.headers.items()
160
161
  }
161
162
  try:
162
- response_server.stream_router.validate_incomming_request(request_body)
163
+ prepared = response_server.prepare_response(request_body)
163
164
  except UnsupportedIncommingFeature as exc:
164
165
  return JSONResponse(
165
166
  {"error": {"message": str(exc)}},
@@ -167,7 +168,7 @@ class ManagedResponseServer:
167
168
  )
168
169
 
169
170
  return StreamingResponse(
170
- _stream_events(response_server, request_body, request_headers),
171
+ _stream_events(response_server, prepared, request_headers),
171
172
  media_type="text/event-stream",
172
173
  headers={
173
174
  "Cache-Control": "no-cache",
@@ -40,17 +40,6 @@ class CompatServerConfig:
40
40
  value = str(self.outcomming_api or "").strip().lower()
41
41
  return value or "chat_completions"
42
42
 
43
- def with_ephemeral_port(self) -> "CompatServerConfig":
44
- return CompatServerConfig(
45
- host=self.host,
46
- port=0,
47
- outcomming_base_url=self.outcomming_base_url,
48
- outcomming_api=self.outcomming_api,
49
- outcomming_api_key_env=self.outcomming_api_key_env,
50
- model_provider=self.model_provider,
51
- timeout_seconds=self.timeout_seconds,
52
- )
53
-
54
43
  @classmethod
55
44
  def from_base_url(
56
45
  cls,
@@ -2,8 +2,8 @@
2
2
 
3
3
  Each downstream chat-completions provider may have its own payload quirks:
4
4
  extra fields, removed fields, role normalization, tool-shape tweaks, etc.
5
- Keep all of those provider-specific rewrites here so `StreamRouter` can keep
6
- building one canonical `outcomming_request`, while `server.py` selects the
5
+ Keep all of those provider-specific rewrites here so request translation produces
6
+ one canonical `outcomming_request`, while `server.py` selects the
7
7
  appropriate hook from `CompatServerConfig.model_provider`.
8
8
  """
9
9
 
@@ -11,7 +11,7 @@ import typing
11
11
  from copy import deepcopy
12
12
  from typing import Callable, Optional
13
13
 
14
- from typing_extensions import TypedDict
14
+ from pycodex.utils.compat import TypedDict
15
15
 
16
16
  ChatMessage = typing.Dict[str, object]
17
17
 
@@ -20,7 +20,7 @@ class OutgoingRequest(TypedDict):
20
20
  """Canonical downstream `/v1/chat/completions` request shape.
21
21
 
22
22
  `model`, `messages`, and `stream` are always populated by
23
- `StreamRouter.build_outcomming_request(...)`. Provider-specific fields that
23
+ `request_translation.build_outcomming_request(...)`. Provider-specific fields that
24
24
  may be omitted use `Optional[...]` here so the schema stays simple and does
25
25
  not rely on TypedDict inheritance.
26
26
  """