python-codex 0.6.1__py3-none-any.whl → 0.6.3__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/agent.py +35 -9
- pycodex/bootstrap.py +8 -0
- pycodex/context.py +54 -36
- pycodex/events.py +19 -10
- pycodex/model.py +32 -7
- pycodex/prompts/models.json +345 -0
- pycodex/protocol.py +15 -0
- pycodex/runtime.py +49 -54
- pycodex/utils/compactor.py +5 -2
- pycodex/utils/event_helpers.py +5 -9
- pycodex/utils/history.py +74 -41
- pycodex/utils/http_headers.py +25 -0
- pycodex/utils/session_persist.py +125 -42
- pycodex/utils/skill_catalog.py +18 -0
- {python_codex-0.6.1.dist-info → python_codex-0.6.3.dist-info}/METADATA +22 -4
- {python_codex-0.6.1.dist-info → python_codex-0.6.3.dist-info}/RECORD +27 -25
- responses_server/app.py +2 -0
- responses_server/config.py +4 -1
- responses_server/gemini_api.py +17 -6
- responses_server/messages_api.py +12 -6
- responses_server/payload_processors.py +1 -1
- responses_server/request_translation.py +55 -13
- responses_server/stream_router.py +9 -0
- responses_server/transport.py +12 -6
- {python_codex-0.6.1.dist-info → python_codex-0.6.3.dist-info}/WHEEL +0 -0
- {python_codex-0.6.1.dist-info → python_codex-0.6.3.dist-info}/entry_points.txt +0 -0
- {python_codex-0.6.1.dist-info → python_codex-0.6.3.dist-info}/licenses/LICENSE +0 -0
pycodex/utils/session_persist.py
CHANGED
|
@@ -24,8 +24,7 @@ from ..protocol import (
|
|
|
24
24
|
from .compactor import SUMMARY_PREFIX
|
|
25
25
|
from .event_helpers import shorten_title
|
|
26
26
|
from .history import (
|
|
27
|
-
conversation_history_to_turns,
|
|
28
|
-
restore_visibility, serialize_history_item,
|
|
27
|
+
conversation_history_to_turns, restore_message_metadata, serialize_history_item,
|
|
29
28
|
)
|
|
30
29
|
from .get_env import get_package_version
|
|
31
30
|
|
|
@@ -163,6 +162,9 @@ class SessionRolloutRecorder:
|
|
|
163
162
|
"message": item.text,
|
|
164
163
|
"name": item.name,
|
|
165
164
|
"visible": item.visible,
|
|
165
|
+
"message_id": item.message_id,
|
|
166
|
+
"created_at": item.created_at,
|
|
167
|
+
"turn_id": item.turn_id,
|
|
166
168
|
"images": [],
|
|
167
169
|
"local_images": [],
|
|
168
170
|
"text_elements": [],
|
|
@@ -310,7 +312,7 @@ def load_resumed_session_path(
|
|
|
310
312
|
replacement_history = payload.get("replacement_history")
|
|
311
313
|
if isinstance(replacement_history, list):
|
|
312
314
|
history = _deserialize_compacted_history(
|
|
313
|
-
replacement_history, payload.get("message")
|
|
315
|
+
replacement_history, payload.get("message"), entry["_record_offset"],
|
|
314
316
|
)
|
|
315
317
|
saw_input = any(
|
|
316
318
|
isinstance(item, (UserMessage, AgentMessage, ContextMessage))
|
|
@@ -325,7 +327,7 @@ def load_resumed_session_path(
|
|
|
325
327
|
|
|
326
328
|
if item_type == "event_msg" and isinstance(payload, dict):
|
|
327
329
|
if payload.get("type") == "user_message":
|
|
328
|
-
history.append(_user_message_from_event(payload))
|
|
330
|
+
history.append(_user_message_from_event(payload, entry))
|
|
329
331
|
saw_input = True
|
|
330
332
|
continue
|
|
331
333
|
|
|
@@ -341,6 +343,7 @@ def load_resumed_session_path(
|
|
|
341
343
|
payload,
|
|
342
344
|
tool_names_by_call_id,
|
|
343
345
|
include_user_messages=False,
|
|
346
|
+
record_id=entry["_record_offset"], timestamp=entry.get("timestamp"),
|
|
344
347
|
)
|
|
345
348
|
|
|
346
349
|
if not history:
|
|
@@ -351,7 +354,8 @@ def load_resumed_session_path(
|
|
|
351
354
|
raise ValueError(f"No resumable history found in {rollout_path}")
|
|
352
355
|
|
|
353
356
|
turns = conversation_history_to_turns(history)
|
|
354
|
-
first_prompt = next((
|
|
357
|
+
first_prompt = next(("\n".join(message.text for message in turn["messages"])
|
|
358
|
+
for turn in turns if turn["messages"]), "")
|
|
355
359
|
title = thread_name or shorten_title(first_prompt) or thread_id
|
|
356
360
|
return {
|
|
357
361
|
"session_id": session_id,
|
|
@@ -398,39 +402,75 @@ def read_rollout_history_page(rollout_path, before=None, limit=100):
|
|
|
398
402
|
|
|
399
403
|
def load_display_history(
|
|
400
404
|
rollout_path: "typing.Union[str, Path]",
|
|
401
|
-
limit: "int" = 80,
|
|
402
|
-
) -> "
|
|
403
|
-
"""Read
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
405
|
+
limit: "typing.Union[int, None]" = 80,
|
|
406
|
+
) -> "tuple":
|
|
407
|
+
"""Read recent complete display rows from the end of the rollout."""
|
|
408
|
+
if limit is None:
|
|
409
|
+
return conversation_history_to_turns(_iter_display_items(rollout_path))
|
|
410
|
+
if isinstance(limit, bool) or not isinstance(limit, int) or limit < 0:
|
|
411
|
+
raise ValueError("limit must be a non-negative integer or None")
|
|
412
|
+
if limit == 0:
|
|
413
|
+
return ()
|
|
414
|
+
|
|
415
|
+
items = []
|
|
416
|
+
oldest_turn_id = None
|
|
417
|
+
remaining = limit + 1
|
|
418
|
+
with closing(_iter_display_items(rollout_path, reverse=True)) as history:
|
|
419
|
+
for item in history:
|
|
420
|
+
items.append(item)
|
|
421
|
+
if isinstance(item, dict):
|
|
422
|
+
remaining -= 1
|
|
423
|
+
if oldest_turn_id is not None:
|
|
424
|
+
continue
|
|
425
|
+
elif not item.visible:
|
|
426
|
+
continue
|
|
427
|
+
else:
|
|
428
|
+
if item.turn_id != oldest_turn_id or item.turn_id is None:
|
|
429
|
+
remaining -= 1
|
|
430
|
+
oldest_turn_id = item.turn_id
|
|
431
|
+
if remaining <= 0:
|
|
432
|
+
turns = conversation_history_to_turns(reversed(items))
|
|
433
|
+
if len(turns) > limit:
|
|
434
|
+
return turns[-limit:]
|
|
435
|
+
remaining = limit - len(turns) + 1
|
|
436
|
+
return conversation_history_to_turns(reversed(items))[-limit:]
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def _user_message_from_event(payload, entry):
|
|
440
|
+
return restore_message_metadata(UserMessage(
|
|
409
441
|
text=str(payload.get("message", "")), name=payload.get("name", "user"),
|
|
410
|
-
), payload)
|
|
442
|
+
), payload, entry["_record_offset"], entry.get("timestamp"))
|
|
411
443
|
|
|
412
444
|
|
|
413
|
-
def _iter_display_items(rollout_path):
|
|
445
|
+
def _iter_display_items(rollout_path, reverse=False):
|
|
414
446
|
path = Path(rollout_path).expanduser().resolve()
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
item_type == "
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
447
|
+
reader = _iter_rollout_entries_reverse if reverse else _iter_rollout_entries
|
|
448
|
+
with closing(reader(path)) as entries:
|
|
449
|
+
for entry in entries:
|
|
450
|
+
item_type = entry.get("type")
|
|
451
|
+
payload = entry.get("payload")
|
|
452
|
+
if not isinstance(payload, dict):
|
|
453
|
+
continue
|
|
454
|
+
timestamp = entry.get("timestamp")
|
|
455
|
+
if not isinstance(timestamp, str):
|
|
456
|
+
timestamp = None
|
|
457
|
+
if item_type == "compacted":
|
|
458
|
+
yield {"type": "compacted", "id": "compaction-{0}".format(entry["_record_offset"])}
|
|
459
|
+
elif item_type == "event_msg" and payload.get("type") == "user_message":
|
|
460
|
+
yield _user_message_from_event(payload, entry)
|
|
461
|
+
elif (
|
|
462
|
+
item_type == "response_item"
|
|
463
|
+
and (
|
|
464
|
+
payload.get("type") == "agent_message"
|
|
465
|
+
or (payload.get("type") == "message" and payload.get("role") == "assistant")
|
|
466
|
+
)
|
|
467
|
+
):
|
|
468
|
+
items = []
|
|
469
|
+
_append_deserialized_response_item(
|
|
470
|
+
items, payload, {}, False, entry["_record_offset"], timestamp,
|
|
471
|
+
)
|
|
472
|
+
for item in items:
|
|
473
|
+
yield item
|
|
434
474
|
|
|
435
475
|
|
|
436
476
|
def _drop_unmatched_tool_calls(
|
|
@@ -534,6 +574,7 @@ def _iter_rollout_entries(
|
|
|
534
574
|
) -> "typing.Iterable[typing.Dict[str, object]]":
|
|
535
575
|
decoder = json.JSONDecoder()
|
|
536
576
|
buffer = ""
|
|
577
|
+
byte_offset = start_offset
|
|
537
578
|
start = 0
|
|
538
579
|
parsed_entries = 0
|
|
539
580
|
|
|
@@ -547,14 +588,16 @@ def _iter_rollout_entries(
|
|
|
547
588
|
buffer += chunk
|
|
548
589
|
|
|
549
590
|
while True:
|
|
591
|
+
whitespace_start = start
|
|
550
592
|
while start < len(buffer) and buffer[start].isspace():
|
|
551
593
|
start += 1
|
|
594
|
+
byte_offset += len(buffer[whitespace_start:start].encode("utf-8"))
|
|
552
595
|
if start >= len(buffer):
|
|
553
596
|
buffer = ""
|
|
554
597
|
start = 0
|
|
555
598
|
break
|
|
556
599
|
try:
|
|
557
|
-
entry,
|
|
600
|
+
entry, end = decoder.raw_decode(buffer, start)
|
|
558
601
|
except json.JSONDecodeError as exc:
|
|
559
602
|
if eof:
|
|
560
603
|
if parsed_entries > 0:
|
|
@@ -566,8 +609,12 @@ def _iter_rollout_entries(
|
|
|
566
609
|
buffer = buffer[start:]
|
|
567
610
|
start = 0
|
|
568
611
|
break
|
|
612
|
+
record_offset = byte_offset
|
|
613
|
+
byte_offset += len(buffer[start:end].encode("utf-8"))
|
|
614
|
+
start = end
|
|
569
615
|
if isinstance(entry, dict):
|
|
570
616
|
parsed_entries += 1
|
|
617
|
+
entry["_record_offset"] = record_offset
|
|
571
618
|
yield entry
|
|
572
619
|
if start > ROLLOUT_READ_CHUNK_SIZE:
|
|
573
620
|
buffer = buffer[start:]
|
|
@@ -580,6 +627,38 @@ def _iter_rollout_entries(
|
|
|
580
627
|
raise ValueError(f"no rollout entries found in {rollout_path}")
|
|
581
628
|
|
|
582
629
|
|
|
630
|
+
def _iter_rollout_entries_reverse(rollout_path):
|
|
631
|
+
"""Walk JSONL records backwards, including pretty-printed legacy records."""
|
|
632
|
+
parsed_entries = 0
|
|
633
|
+
with rollout_path.open("rb") as handle:
|
|
634
|
+
if not rollout_path.stat().st_size:
|
|
635
|
+
raise ValueError("no rollout entries found in {0}".format(rollout_path))
|
|
636
|
+
with mmap.mmap(handle.fileno(), 0, access=mmap.ACCESS_READ) as mapped:
|
|
637
|
+
end = len(mapped)
|
|
638
|
+
at_tail = True
|
|
639
|
+
while end:
|
|
640
|
+
start = mapped.rfind(b"\n{", 0, end)
|
|
641
|
+
start = start + 1 if start >= 0 else 0
|
|
642
|
+
text = mapped[start:end].decode("utf-8", errors="replace")
|
|
643
|
+
try:
|
|
644
|
+
entry = json.loads(text)
|
|
645
|
+
except json.JSONDecodeError as exc:
|
|
646
|
+
if not at_tail:
|
|
647
|
+
raise ValueError(
|
|
648
|
+
"failed to parse rollout file {0}: {1}".format(rollout_path, exc)
|
|
649
|
+
) from exc
|
|
650
|
+
else:
|
|
651
|
+
if isinstance(entry, dict):
|
|
652
|
+
leading = text[:len(text) - len(text.lstrip())]
|
|
653
|
+
entry["_record_offset"] = start + len(leading.encode("utf-8"))
|
|
654
|
+
parsed_entries += 1
|
|
655
|
+
yield entry
|
|
656
|
+
end = start
|
|
657
|
+
at_tail = False
|
|
658
|
+
if not parsed_entries:
|
|
659
|
+
raise ValueError("no rollout entries found in {0}".format(rollout_path))
|
|
660
|
+
|
|
661
|
+
|
|
583
662
|
def _extract_response_message_text(payload: "typing.Dict[str, object]") -> "str":
|
|
584
663
|
text_parts: "typing.List[str]" = []
|
|
585
664
|
for item in payload.get("content") or []:
|
|
@@ -604,10 +683,11 @@ def _compacted_payload(
|
|
|
604
683
|
def _deserialize_compacted_history(
|
|
605
684
|
replacement_history: "typing.Iterable[object]",
|
|
606
685
|
summary_message: "typing.Union[str, None]" = None,
|
|
686
|
+
record_id: "object" = "checkpoint",
|
|
607
687
|
) -> "typing.List[ConversationItem]":
|
|
608
688
|
history: "typing.List[ConversationItem]" = []
|
|
609
689
|
tool_names_by_call_id: "typing.Dict[str, str]" = {}
|
|
610
|
-
for payload in replacement_history:
|
|
690
|
+
for index, payload in enumerate(replacement_history):
|
|
611
691
|
if not isinstance(payload, dict):
|
|
612
692
|
continue
|
|
613
693
|
_append_deserialized_response_item(
|
|
@@ -615,6 +695,7 @@ def _deserialize_compacted_history(
|
|
|
615
695
|
payload,
|
|
616
696
|
tool_names_by_call_id,
|
|
617
697
|
include_user_messages=True,
|
|
698
|
+
record_id="{0}:{1}".format(record_id, index),
|
|
618
699
|
)
|
|
619
700
|
for index in range(len(history) - 1, -1, -1):
|
|
620
701
|
item = history[index]
|
|
@@ -632,26 +713,28 @@ def _append_deserialized_response_item(
|
|
|
632
713
|
payload: "typing.Dict[str, object]",
|
|
633
714
|
tool_names_by_call_id: "typing.Dict[str, str]",
|
|
634
715
|
include_user_messages: "bool",
|
|
716
|
+
record_id: "object" = "",
|
|
717
|
+
timestamp: "typing.Union[str, None]" = None,
|
|
635
718
|
) -> "None":
|
|
636
719
|
response_item_type = str(payload.get("type", "")).strip()
|
|
637
720
|
if response_item_type == "agent_message":
|
|
638
|
-
history.append(
|
|
639
|
-
AgentMessage.from_response_item(payload), payload,
|
|
721
|
+
history.append(restore_message_metadata(
|
|
722
|
+
AgentMessage.from_response_item(payload), payload, record_id, timestamp,
|
|
640
723
|
))
|
|
641
724
|
return
|
|
642
725
|
if response_item_type == "message":
|
|
643
726
|
role = str(payload.get("role", "")).strip()
|
|
644
727
|
if role == "assistant":
|
|
645
|
-
history.append(
|
|
646
|
-
AssistantMessage.from_response_item(payload), payload,
|
|
728
|
+
history.append(restore_message_metadata(
|
|
729
|
+
AssistantMessage.from_response_item(payload), payload, record_id, timestamp,
|
|
647
730
|
))
|
|
648
731
|
return
|
|
649
732
|
if include_user_messages and role == "user":
|
|
650
733
|
history.append(
|
|
651
|
-
|
|
734
|
+
restore_message_metadata(UserMessage(
|
|
652
735
|
text=_extract_response_message_text(payload), id=payload.get("id"),
|
|
653
736
|
name=payload.get("name", "user"),
|
|
654
|
-
), payload)
|
|
737
|
+
), payload, record_id, timestamp)
|
|
655
738
|
)
|
|
656
739
|
return
|
|
657
740
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Skill catalog for workspace input suggestions."""
|
|
2
|
+
|
|
3
|
+
from ..context import discover_skills
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def list_skills(codex_home):
|
|
7
|
+
"""Return unique, deterministic names without exposing local filesystem paths."""
|
|
8
|
+
result = []
|
|
9
|
+
seen = set()
|
|
10
|
+
for skill in sorted(
|
|
11
|
+
discover_skills(codex_home),
|
|
12
|
+
key=lambda item: (item.scope_rank, item.name, str(item.path_to_skill_md)),
|
|
13
|
+
):
|
|
14
|
+
if skill.name in seen:
|
|
15
|
+
continue
|
|
16
|
+
seen.add(skill.name)
|
|
17
|
+
result.append({"name": skill.name, "description": skill.description})
|
|
18
|
+
return sorted(result, key=lambda item: item["name"].lower())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-codex
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.3
|
|
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
|
|
@@ -48,6 +48,11 @@ python3 -m pip install --upgrade pycodex-ws
|
|
|
48
48
|
|
|
49
49
|
## Configure a model
|
|
50
50
|
|
|
51
|
+
Start with [config_examples/](config_examples/README.md) for Responses, StepFun,
|
|
52
|
+
Chat Completions, Claude Messages or Gemini. Give an agent your endpoint and key
|
|
53
|
+
(StepFun Coding Plan includes its endpoint) and ask it to follow that guide to
|
|
54
|
+
install and verify a config or profile.
|
|
55
|
+
|
|
51
56
|
Create `~/.codex/config.toml`. For example, with OpenAI:
|
|
52
57
|
|
|
53
58
|
```toml
|
|
@@ -82,6 +87,10 @@ See [configuration](docs/CONTEXT.md#配置读取与-profile) and the
|
|
|
82
87
|
[Gemini setup example](docs/responses_server/README.md#gemini-api).
|
|
83
88
|
Gemini 4 Argon includes a prompt adapted from Antigravity.
|
|
84
89
|
Gemini tool arguments stream as they are generated; tools run after the complete call is received.
|
|
90
|
+
Gemini tool results use `response.output`; returned images stay in the matching
|
|
91
|
+
`functionResponse.parts`.
|
|
92
|
+
Gemini continuation omits unsigned empty text parts while preserving thought signatures,
|
|
93
|
+
including when resuming recorded sessions.
|
|
85
94
|
|
|
86
95
|
## Use the CLI
|
|
87
96
|
|
|
@@ -95,6 +104,8 @@ pycodex --json "Summarize this repository."
|
|
|
95
104
|
```
|
|
96
105
|
|
|
97
106
|
The first command starts an interactive session; the others run a single task.
|
|
107
|
+
Web skill completion is an [optional frontend feature](packages/pycodex-ws/workspace_server/optional_features/skill-completion/README.md).
|
|
108
|
+
Apply `skill-completion` through Customize to enable @/$ prefix suggestions.
|
|
98
109
|
The agent can edit files and run commands with your user account's permissions.
|
|
99
110
|
|
|
100
111
|
| Command | Purpose |
|
|
@@ -137,11 +148,18 @@ pycodex-ws --listen 127.0.0.1:6007 --workspace-config workspaces.json
|
|
|
137
148
|
|
|
138
149
|
Open `http://127.0.0.1:6007`. The workspace uses the same model configuration as
|
|
139
150
|
the CLI and provides conversations, a live HTML Canvas, and file/diff viewers.
|
|
151
|
+
Chat updates arrive through two-second polling; completed replies render as Markdown.
|
|
140
152
|
Click file links to inspect code, then select text and use **Insert into chat**
|
|
141
153
|
to include it in your next message.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
154
|
+
Each input displays its author and creation time, including separate messages
|
|
155
|
+
in a steer batch. Recorded messages keep that metadata when the session resumes.
|
|
156
|
+
Restoring a tab reads the rollout tail needed for its latest 80 display rows;
|
|
157
|
+
Agent resume still restores the complete active context after the last checkpoint.
|
|
158
|
+
|
|
159
|
+
The settings menu provides interface customization, password-protected
|
|
160
|
+
workspace sharing, and [One-line Agent](packages/pycodex-ws/README.md#one-line-agent):
|
|
161
|
+
an Agent that runs directly in most shells without installation, for bootstrapping
|
|
162
|
+
an Agent environment or simple debugging. See the [workspace guide](packages/pycodex-ws/README.md) for
|
|
145
163
|
session controls, storage and Feishu setup. A separate
|
|
146
164
|
[VS Code extension](packages/pycodex-ws/extensions/vscode/README.md) connects to
|
|
147
165
|
the same backend, including over Remote SSH.
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
pycodex/__init__.py,sha256=2rP9Qd5ClJlSI3bPNB0Jmn9lJUpeeo7gcbRPUvH81eI,2904
|
|
2
2
|
pycodex/__main__.py,sha256=MHKZ_ae3fSLGTLUUMOx15fWdeOnJSHhq-zslRP5F5Lc,79
|
|
3
|
-
pycodex/agent.py,sha256=
|
|
4
|
-
pycodex/bootstrap.py,sha256=
|
|
3
|
+
pycodex/agent.py,sha256=EanBfEvRLnGSfvWv_P447mUw5CezVk680h2vP4pc_YI,23848
|
|
4
|
+
pycodex/bootstrap.py,sha256=4bn2MhNzAHk1fFVFO1V8p2hFKcOMbe4-y2PA5qhPY98,5429
|
|
5
5
|
pycodex/cli.py,sha256=HkX_fFNUyPnNo25FeSa9ZMaQG79rqk3b0oV4ZH0h68c,12576
|
|
6
6
|
pycodex/config.py,sha256=mGM7oLaciBwGXHMQjKVifWFTd7gZTfzqlQeJSFzcQic,1218
|
|
7
|
-
pycodex/context.py,sha256=
|
|
8
|
-
pycodex/events.py,sha256=
|
|
9
|
-
pycodex/model.py,sha256=
|
|
7
|
+
pycodex/context.py,sha256=OKIm-bs8ZosKn_tqy3CEU7XUu6rMFLbNZ_eyuIkzMaQ,42016
|
|
8
|
+
pycodex/events.py,sha256=8gPVe_wb5r5s2hVQhywFMnz1YVvBmDLhyq43e9Y71wk,23090
|
|
9
|
+
pycodex/model.py,sha256=SaAMysy0MaeFNbRgJS4zP_QcAerBYa5_Jilwvgtv34s,59992
|
|
10
10
|
pycodex/multi_agents.py,sha256=3KN_Ai3UremtsQppvxd0pE7pFam_v0zBastCNi-NNx8,16150
|
|
11
|
-
pycodex/protocol.py,sha256
|
|
12
|
-
pycodex/runtime.py,sha256=
|
|
11
|
+
pycodex/protocol.py,sha256=qYUS9371F-DadlsYgctCpQbm3JCqyfpcWcxkANRAZWQ,15586
|
|
12
|
+
pycodex/runtime.py,sha256=92hVNdBzugUYQb01-bbkAOYpNpjIB1IWVEU6_U6SERA,37120
|
|
13
13
|
pycodex/portable/__init__.py,sha256=NgACNTFK5hbRK6fqbL89qjPuh44N950pr4eoDWLfKD4,1110
|
|
14
14
|
pycodex/portable/client.py,sha256=ZvXjKCB557ZZ-ELmec9DIxymWbG8QBZsaU6e0axu0T0,15508
|
|
15
15
|
pycodex/portable/protocol.py,sha256=jtyPHI3aVY4UldlSIzeZRQX3MCFzPYfG-0iDC6JSWYo,931
|
|
16
16
|
pycodex/portable/server.py,sha256=UCQAqcO0OTNkEv4MQgR-fIt1y5bzdqMndFJtMm16Lqk,7503
|
|
17
17
|
pycodex/prompts/default_base_instructions.md,sha256=D65mcj6bo4CDvVom-D9cbJRJVNquo0NghKt164_fRsg,20923
|
|
18
18
|
pycodex/prompts/developer_messages.json,sha256=E-CAWMOL2KoImJ1U_1aA-OYbuVtJF0-GtZkn983B-TI,4007
|
|
19
|
-
pycodex/prompts/models.json,sha256=
|
|
19
|
+
pycodex/prompts/models.json,sha256=m2edzANgpiRutpuw3nGJFiJQX4Y7751_omr4E4zN_uU,747802
|
|
20
20
|
pycodex/prompts/goals/budget_limit.md,sha256=RbvI03fMD3tTy-ytnzylqAsIr9b2O_Cb81CQejR1J-k,775
|
|
21
21
|
pycodex/prompts/goals/continuation.md,sha256=K7OtQKQNoCKcgne-e-SQBGJjEpnCVcVCtML7T-82bWI,6153
|
|
22
22
|
pycodex/prompts/permissions/approval_policy/never.md,sha256=QceTG6wjkaJARjYr0HYV1aPnPcpGcrkRUW-smWRr6MQ,120
|
|
@@ -62,19 +62,21 @@ pycodex/tools/write_stdin_tool.py,sha256=jvBDchLLmoDITd7g-ZVeEVXHRhWKkmnjM5laL-5
|
|
|
62
62
|
pycodex/utils/__init__.py,sha256=ih_KyZ2_bajR5YlZ1QMTWOHnuEBda-S3gQ7PwnBtLZQ,453
|
|
63
63
|
pycodex/utils/async_bridge.py,sha256=BXsKTUTUvUtPJnItQlulFRdV7opdKKDlsKLdtVTYshs,1732
|
|
64
64
|
pycodex/utils/codex_config.py,sha256=oCisEGUJcJxcZL1wIqXkon1xTShymOlz96E3VgDVTlY,3748
|
|
65
|
-
pycodex/utils/compactor.py,sha256=
|
|
65
|
+
pycodex/utils/compactor.py,sha256=qSHZpTP_hWuxuqeVt6JijbtgkXiW2act1CdTQ5wovBM,6399
|
|
66
66
|
pycodex/utils/compat.py,sha256=16FyHHlDES57mOHCasN4FWveEkGYd2aZex9-Eojlkg8,5277
|
|
67
67
|
pycodex/utils/crypto.py,sha256=HRCXF26Ft3S8CG2X0YpZwa8GMU9YJ0Loo8Q9PMPMcNw,1249
|
|
68
68
|
pycodex/utils/debug.py,sha256=5XMpWpwFSm6woyx6RGXvN2qL0afRtTQbwlOAv-LotTw,913
|
|
69
69
|
pycodex/utils/doctor.py,sha256=xhPflFEYFfmtQ4-LjnIyz-cNts0GjNtAK0inVTYfKiI,10764
|
|
70
70
|
pycodex/utils/dotenv.py,sha256=rLHBfz5zPZMbrJqyRyYPy3j4oiDwuzfrH4mDH3XRrow,1647
|
|
71
|
-
pycodex/utils/event_helpers.py,sha256=
|
|
71
|
+
pycodex/utils/event_helpers.py,sha256=ULvTSktxMd--VEL2UJA6CbuWHLsrctAcAuEk91wGLL8,12021
|
|
72
72
|
pycodex/utils/get_env.py,sha256=L4S8h84tkgxZKvrxY7ezTgePbXepG-yIigUTKeY6uuE,6094
|
|
73
|
-
pycodex/utils/history.py,sha256=
|
|
73
|
+
pycodex/utils/history.py,sha256=qgt5IxxkfCYjjpr08VJFhasICSSlqxQM7d-DjRJVjHA,3845
|
|
74
|
+
pycodex/utils/http_headers.py,sha256=4Jlnmun6QFSQ6L7javlDQfom1p2AZZQFXvcHzD3_cQk,877
|
|
74
75
|
pycodex/utils/image_utils.py,sha256=OUzUs0Cow4L8Z2np0EBeEUotAqqsCmRmhrV8AxZUXRw,2460
|
|
75
76
|
pycodex/utils/model_metadata.py,sha256=uK3iI4yC7Ge7yN4I1_gQYalQ4MYKddz2qMwsmQb-P80,1337
|
|
76
77
|
pycodex/utils/random_ids.py,sha256=jLTxZZ0MBbRdQOFDFWGVRjWzIo6FKSQ5ADXbQSLPp1s,379
|
|
77
|
-
pycodex/utils/session_persist.py,sha256=
|
|
78
|
+
pycodex/utils/session_persist.py,sha256=7JXXInvKaeO-9zz-n4LrnqrNn4BvFPEoVgZ88c9yZrM,31333
|
|
79
|
+
pycodex/utils/skill_catalog.py,sha256=3W-r6pn_fzEGyd89aKD2shGNhrUK2hLgrlwOlqYOpgU,618
|
|
78
80
|
pycodex/utils/truncation.py,sha256=5D6vAorT8EgXgjd7ASwtraAyIZdlCR-w5jKZqJxDzho,5446
|
|
79
81
|
pycodex/utils/_aes_gcm/LICENSE,sha256=KvdHagY3sYIK34GldJaRi34sNnGwMVJIIoDhbC9MRu8,2805
|
|
80
82
|
pycodex/utils/_aes_gcm/README.md,sha256=D9XGeewCgU2PVqJCO6WusUs0Mw2FbMnABCqaVktqCnE,3045
|
|
@@ -84,23 +86,23 @@ pycodex/utils/_aes_gcm/gcm.py,sha256=Z8fYHpnLpqJyTPmjDOZtryqe0xmT_93vscNuJe5ZY-w
|
|
|
84
86
|
pycodex/utils/_aes_gcm/source-sha256.json,sha256=g9uPWXuA0D9Wq9EGnduyiVanTgi8QWRFW-9T69FG-fc,215
|
|
85
87
|
responses_server/__init__.py,sha256=SOMO5Q-Z0dpaRih8yWuKUTclPl28tpy_XIPTOO_BPq0,447
|
|
86
88
|
responses_server/__main__.py,sha256=876xZTqhPeDBD2GKKr8pKX33Af8PhFTosAI8bYQsFgQ,61
|
|
87
|
-
responses_server/app.py,sha256=
|
|
88
|
-
responses_server/config.py,sha256=
|
|
89
|
-
responses_server/gemini_api.py,sha256=
|
|
90
|
-
responses_server/messages_api.py,sha256=
|
|
91
|
-
responses_server/payload_processors.py,sha256
|
|
92
|
-
responses_server/request_translation.py,sha256=
|
|
89
|
+
responses_server/app.py,sha256=6D23sAyftNUwGwmWT7WGM6aau78i7KCkhZfc16Sul3o,8600
|
|
90
|
+
responses_server/config.py,sha256=XxBRXrLEeCnaqKXGV-f_3iTtur0hPn4yqM7wLngcTFM,2931
|
|
91
|
+
responses_server/gemini_api.py,sha256=d5ChR4_fOnx2tPVSQQWWYIgXuIEcHdJUScaOptoGii4,16163
|
|
92
|
+
responses_server/messages_api.py,sha256=dDZ2z2AfE5Mfayuy0yt3tmgYp7fj11QtOBQ51gtdVCE,19613
|
|
93
|
+
responses_server/payload_processors.py,sha256=-lcw5DJ-uGiK4ZDsw373gjxpqVTapC-kWGVBXFGmr1A,3585
|
|
94
|
+
responses_server/request_translation.py,sha256=qG5rxW0bf6NS83L24YmMOuVNpPZGWnl2NVjNtQ-_GeQ,20508
|
|
93
95
|
responses_server/server.py,sha256=hFSRU3GjYa9cI1YSDxKvg2gLjp3OJ_Mh_JFyau3yzl4,2535
|
|
94
96
|
responses_server/session_store.py,sha256=nwGxQL6nUVKnDVeDHz8IzqNQ7dWk8Ybf0URekOHdxTo,1133
|
|
95
97
|
responses_server/stream_events.py,sha256=nWi5VcssytFD3SDHW5hQik5LR-US-Clk-5EEWAi3t-k,4984
|
|
96
|
-
responses_server/stream_router.py,sha256=
|
|
98
|
+
responses_server/stream_router.py,sha256=7-_KoXtaDtEISeSxGL-tJ-l6gmypbIgQ_Mxx9dtyklA,15474
|
|
97
99
|
responses_server/trajectory_dump.py,sha256=5_Wy6tslszrqx3j1JeP_boyTbzIicKy8No84PzMnmHk,5111
|
|
98
|
-
responses_server/transport.py,sha256=
|
|
100
|
+
responses_server/transport.py,sha256=PmflqUUZ-p7dO4vTFPNM4SzbQITXT0lntMqwiTrw2rw,16810
|
|
99
101
|
responses_server/tools/__init__.py,sha256=ivsBSEy0SBUhY-Uea5v1XMLXShkwHdCVl0id-1FwdZg,150
|
|
100
102
|
responses_server/tools/custom_adapter.py,sha256=leYNJKp4Ute0JWNfGpe-ntSyFqRgYCdWF4dMYQFINlk,8615
|
|
101
103
|
responses_server/tools/web_search.py,sha256=JyF6NHCS0SqoBrO18jX8cgBsiV4OYQBPz0Ky4u3juSQ,9059
|
|
102
|
-
python_codex-0.6.
|
|
103
|
-
python_codex-0.6.
|
|
104
|
-
python_codex-0.6.
|
|
105
|
-
python_codex-0.6.
|
|
106
|
-
python_codex-0.6.
|
|
104
|
+
python_codex-0.6.3.dist-info/METADATA,sha256=shh4KMFZrpoJD0vfiDk2WFzZ-5tbAni_J4nn8bevZ-g,8187
|
|
105
|
+
python_codex-0.6.3.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
|
|
106
|
+
python_codex-0.6.3.dist-info/entry_points.txt,sha256=sNUVakoVuTrzJH505ZgRTQxmtRRPUHV_EH0i6EbYTyM,45
|
|
107
|
+
python_codex-0.6.3.dist-info/licenses/LICENSE,sha256=0X8ifk312hYAORM4hlzg8wVSEXYKNmiPgWlB1YIy2Nw,10926
|
|
108
|
+
python_codex-0.6.3.dist-info/RECORD,,
|
responses_server/app.py
CHANGED
|
@@ -107,12 +107,14 @@ def launch_chat_completion_compat_server(
|
|
|
107
107
|
api_key_env: "typing.Union[str, None]" = None,
|
|
108
108
|
model_provider: "typing.Union[str, None]" = None,
|
|
109
109
|
outcomming_api: "str" = "chat_completions",
|
|
110
|
+
http_headers: "typing.Union[typing.Dict[str, str], None]" = None,
|
|
110
111
|
):
|
|
111
112
|
config = CompatServerConfig.from_base_url(
|
|
112
113
|
base_url,
|
|
113
114
|
api_key_env,
|
|
114
115
|
outcomming_api=outcomming_api,
|
|
115
116
|
model_provider=model_provider,
|
|
117
|
+
http_headers=http_headers,
|
|
116
118
|
)
|
|
117
119
|
server = ManagedResponseServer(config)
|
|
118
120
|
server.start()
|
responses_server/config.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import typing
|
|
3
3
|
import urllib.parse
|
|
4
|
-
from dataclasses import dataclass
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
5
|
|
|
6
6
|
DEFAULT_OUTCOMMING_TIMEOUT_SECONDS = 300.0
|
|
7
7
|
|
|
@@ -17,6 +17,7 @@ class CompatServerConfig:
|
|
|
17
17
|
outcomming_api_key_env: "typing.Union[str, None]" = None
|
|
18
18
|
model_provider: "typing.Union[str, None]" = None
|
|
19
19
|
timeout_seconds: "float" = DEFAULT_OUTCOMMING_TIMEOUT_SECONDS
|
|
20
|
+
outcomming_http_headers: "typing.Dict[str, str]" = field(default_factory=dict, repr=False)
|
|
20
21
|
|
|
21
22
|
def outcomming_api_key(self) -> "typing.Union[str, None]":
|
|
22
23
|
if self.outcomming_api_key_env is None:
|
|
@@ -52,6 +53,7 @@ class CompatServerConfig:
|
|
|
52
53
|
api_key_env: "typing.Union[str, None]" = None,
|
|
53
54
|
model_provider: "typing.Union[str, None]" = None,
|
|
54
55
|
outcomming_api: "str" = "chat_completions",
|
|
56
|
+
http_headers: "typing.Union[typing.Dict[str, str], None]" = None,
|
|
55
57
|
) -> "CompatServerConfig":
|
|
56
58
|
parsed = urllib.parse.urlparse(outcomming_base_url)
|
|
57
59
|
if not parsed.scheme or not parsed.netloc:
|
|
@@ -69,4 +71,5 @@ class CompatServerConfig:
|
|
|
69
71
|
outcomming_api=outcomming_api,
|
|
70
72
|
outcomming_api_key_env=api_key_env,
|
|
71
73
|
model_provider=model_provider,
|
|
74
|
+
outcomming_http_headers=dict(http_headers) if http_headers is not None else {},
|
|
72
75
|
)
|
responses_server/gemini_api.py
CHANGED
|
@@ -5,6 +5,8 @@ import re
|
|
|
5
5
|
import uuid
|
|
6
6
|
from copy import deepcopy
|
|
7
7
|
|
|
8
|
+
from .request_translation import inline_history_instructions
|
|
9
|
+
|
|
8
10
|
|
|
9
11
|
class GeminiAPIAdapterError(ValueError):
|
|
10
12
|
pass
|
|
@@ -14,7 +16,7 @@ def build_gemini_request(request):
|
|
|
14
16
|
contents = []
|
|
15
17
|
system_parts = []
|
|
16
18
|
calls = {}
|
|
17
|
-
for message in request.get("messages", []):
|
|
19
|
+
for message in inline_history_instructions(request.get("messages", [])):
|
|
18
20
|
role = message["role"]
|
|
19
21
|
if role in {"system", "developer"}:
|
|
20
22
|
system_parts.extend(_content_parts(message.get("content")))
|
|
@@ -31,6 +33,9 @@ def build_gemini_request(request):
|
|
|
31
33
|
# opaque reasoning item. Never replay a removed function call.
|
|
32
34
|
parts = [deepcopy(entry["part"]) for entry in native
|
|
33
35
|
if "call_id" not in entry or entry["call_id"] in active_call_ids]
|
|
36
|
+
# Unsigned empty text can end a stream, but is not input data.
|
|
37
|
+
parts = [part for part in parts
|
|
38
|
+
if part.get("text") != "" or "thoughtSignature" in part]
|
|
34
39
|
else:
|
|
35
40
|
parts = _content_parts(message.get("content"))
|
|
36
41
|
for call in message.get("tool_calls", []):
|
|
@@ -46,18 +51,24 @@ def build_gemini_request(request):
|
|
|
46
51
|
call_id = message["tool_call_id"]
|
|
47
52
|
if call_id not in calls:
|
|
48
53
|
raise GeminiAPIAdapterError("Gemini tool result has no matching function call")
|
|
49
|
-
|
|
54
|
+
output_parts = _content_parts(message.get("content"))
|
|
55
|
+
function_response = {
|
|
50
56
|
"name": calls[call_id], "id": call_id,
|
|
51
|
-
"response": {"
|
|
52
|
-
|
|
57
|
+
"response": {"output": "".join(
|
|
58
|
+
part["text"] for part in output_parts if "text" in part
|
|
59
|
+
)},
|
|
60
|
+
}
|
|
61
|
+
media_parts = [part for part in output_parts if "inlineData" in part]
|
|
62
|
+
if media_parts:
|
|
63
|
+
function_response["parts"] = media_parts
|
|
64
|
+
parts = [{"functionResponse": function_response}]
|
|
53
65
|
role = "user"
|
|
54
66
|
elif role == "user":
|
|
55
67
|
parts = _content_parts(message.get("content"))
|
|
56
68
|
else:
|
|
57
69
|
raise GeminiAPIAdapterError("unsupported Gemini message role: {!r}".format(role))
|
|
58
70
|
if parts:
|
|
59
|
-
# Batch
|
|
60
|
-
# in its own user content as provided by the canonical translator.
|
|
71
|
+
# Batch consecutive function responses into one user content.
|
|
61
72
|
if message["role"] == "tool" and contents and all(
|
|
62
73
|
"functionResponse" in part for part in contents[-1]["parts"]
|
|
63
74
|
):
|
responses_server/messages_api.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import typing
|
|
3
3
|
|
|
4
|
+
from .request_translation import inline_history_instructions, split_tool_images
|
|
5
|
+
|
|
4
6
|
DEFAULT_MESSAGES_MAX_TOKENS = 32000
|
|
5
7
|
|
|
6
8
|
|
|
@@ -20,12 +22,12 @@ def build_messages_request(
|
|
|
20
22
|
raw_messages = outcomming_request.get("messages") or []
|
|
21
23
|
if not isinstance(raw_messages, list):
|
|
22
24
|
raise MessagesAPIAdapterError("outcomming request `messages` must be a list")
|
|
25
|
+
if any(not isinstance(message, dict) for message in raw_messages):
|
|
26
|
+
raise MessagesAPIAdapterError("outcomming request messages must be objects")
|
|
23
27
|
|
|
24
28
|
system_blocks: "typing.List[typing.Dict[str, object]]" = []
|
|
25
29
|
messages: "typing.List[typing.Dict[str, object]]" = []
|
|
26
|
-
for raw_message in raw_messages:
|
|
27
|
-
if not isinstance(raw_message, dict):
|
|
28
|
-
raise MessagesAPIAdapterError("outcomming request messages must be objects")
|
|
30
|
+
for raw_message in split_tool_images(inline_history_instructions(raw_messages)):
|
|
29
31
|
role = str(raw_message.get("role", "")).strip()
|
|
30
32
|
if role in {"developer", "system"}:
|
|
31
33
|
text = str(raw_message.get("content", "") or "")
|
|
@@ -348,7 +350,7 @@ def _translate_tool_choice(
|
|
|
348
350
|
elif choice == "required":
|
|
349
351
|
translated = {"type": "any"}
|
|
350
352
|
elif choice == "none":
|
|
351
|
-
return
|
|
353
|
+
return {"type": "none"}
|
|
352
354
|
else:
|
|
353
355
|
raise MessagesAPIAdapterError(
|
|
354
356
|
f"unsupported tool_choice for messages API: {raw_tool_choice!r}"
|
|
@@ -430,7 +432,12 @@ def _translate_usage(raw_usage: "object") -> "typing.Dict[str, object]":
|
|
|
430
432
|
usage: "typing.Dict[str, object]" = {}
|
|
431
433
|
input_tokens = raw_usage.get("input_tokens")
|
|
432
434
|
output_tokens = raw_usage.get("output_tokens")
|
|
435
|
+
cache_creation = raw_usage.get("cache_creation_input_tokens")
|
|
436
|
+
cache_read = raw_usage.get("cache_read_input_tokens")
|
|
433
437
|
if isinstance(input_tokens, int):
|
|
438
|
+
input_tokens += sum(
|
|
439
|
+
value for value in (cache_creation, cache_read) if isinstance(value, int)
|
|
440
|
+
)
|
|
434
441
|
usage["input_tokens"] = input_tokens
|
|
435
442
|
if isinstance(output_tokens, int):
|
|
436
443
|
usage["output_tokens"] = output_tokens
|
|
@@ -441,12 +448,11 @@ def _translate_usage(raw_usage: "object") -> "typing.Dict[str, object]":
|
|
|
441
448
|
usage["total_tokens"] = input_tokens + output_tokens
|
|
442
449
|
|
|
443
450
|
input_details: "typing.Dict[str, int]" = {}
|
|
444
|
-
cache_creation = raw_usage.get("cache_creation_input_tokens")
|
|
445
451
|
if isinstance(cache_creation, int):
|
|
446
452
|
input_details["cache_creation_input_tokens"] = cache_creation
|
|
447
|
-
cache_read = raw_usage.get("cache_read_input_tokens")
|
|
448
453
|
if isinstance(cache_read, int):
|
|
449
454
|
input_details["cache_read_input_tokens"] = cache_read
|
|
455
|
+
input_details["cached_tokens"] = cache_read
|
|
450
456
|
if input_details:
|
|
451
457
|
usage["input_tokens_details"] = input_details
|
|
452
458
|
return usage
|
|
@@ -72,7 +72,7 @@ def _replace_developer_messages(
|
|
|
72
72
|
|
|
73
73
|
PAYLOAD_POST_PROCESSORS: "typing.Dict[str, PayloadPostProcessor]" = {
|
|
74
74
|
"stepfun": _replace_developer_messages,
|
|
75
|
-
"vllm":
|
|
75
|
+
"vllm": _replace_developer_messages,
|
|
76
76
|
}
|
|
77
77
|
"""Mapping from normalized `model_provider` name to payload rewrite hook."""
|
|
78
78
|
|