circle-codex 0.154.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.
- circle_codex-0.154.1.dist-info/METADATA +148 -0
- circle_codex-0.154.1.dist-info/RECORD +25 -0
- circle_codex-0.154.1.dist-info/WHEEL +4 -0
- openai_codex/__init__.py +95 -0
- openai_codex/_approval_mode.py +51 -0
- openai_codex/_goal.py +448 -0
- openai_codex/_initialize_metadata.py +54 -0
- openai_codex/_inputs.py +103 -0
- openai_codex/_login.py +172 -0
- openai_codex/_message_router.py +389 -0
- openai_codex/_run.py +135 -0
- openai_codex/_runtime_requirements.py +64 -0
- openai_codex/_sandbox.py +78 -0
- openai_codex/_version.py +36 -0
- openai_codex/api.py +901 -0
- openai_codex/async_client.py +413 -0
- openai_codex/client.py +924 -0
- openai_codex/errors.py +121 -0
- openai_codex/generated/__init__.py +1 -0
- openai_codex/generated/notification_registry.py +314 -0
- openai_codex/generated/v2_all.py +14112 -0
- openai_codex/models.py +76 -0
- openai_codex/py.typed +0 -0
- openai_codex/retry.py +41 -0
- openai_codex/types.py +81 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Runtime version and checkout-schema requirements for newer SDK options."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import subprocess
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from functools import cached_property
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from tempfile import TemporaryDirectory
|
|
10
|
+
|
|
11
|
+
from packaging.version import InvalidVersion, Version
|
|
12
|
+
|
|
13
|
+
MINIMUM_RUNTIME_VERSION = "0.151.0"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def require_runtime_version(version: str | None) -> None:
|
|
17
|
+
"""Reject unknown or unsupported versions, including prereleases at the minimum."""
|
|
18
|
+
# CLI alpha hotfixes use 0.154.0-alpha.1.2; PEP 440 spells that a1.post2.
|
|
19
|
+
normalized = re.sub(r"-alpha\.(\d+)\.(\d+)$", r"a\1.post\2", version or "")
|
|
20
|
+
try:
|
|
21
|
+
if Version(normalized) >= Version(MINIMUM_RUNTIME_VERSION):
|
|
22
|
+
return
|
|
23
|
+
except InvalidVersion:
|
|
24
|
+
pass
|
|
25
|
+
raise ValueError(
|
|
26
|
+
f"Codex CLI {MINIMUM_RUNTIME_VERSION} or newer is required; "
|
|
27
|
+
f"reported version is {version or 'unknown'!r}"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class CheckoutCapabilities:
|
|
33
|
+
"""Lazily inspect the same executable and configuration as a running checkout."""
|
|
34
|
+
|
|
35
|
+
command: tuple[str, ...]
|
|
36
|
+
cwd: str | None
|
|
37
|
+
env: dict[str, str]
|
|
38
|
+
|
|
39
|
+
@cached_property
|
|
40
|
+
def fields(self) -> dict[str, frozenset[str]]:
|
|
41
|
+
try:
|
|
42
|
+
with TemporaryDirectory(prefix="codex-sdk-schema-") as directory:
|
|
43
|
+
subprocess.run(
|
|
44
|
+
[*self.command, "generate-json-schema", "--experimental", "--out", directory],
|
|
45
|
+
cwd=self.cwd,
|
|
46
|
+
env=self.env,
|
|
47
|
+
capture_output=True,
|
|
48
|
+
check=True,
|
|
49
|
+
timeout=30,
|
|
50
|
+
)
|
|
51
|
+
result = {}
|
|
52
|
+
for method, name in (
|
|
53
|
+
("turn/start", "TurnStartParams"),
|
|
54
|
+
("thread/resume", "ThreadResumeParams"),
|
|
55
|
+
("thread/fork", "ThreadForkParams"),
|
|
56
|
+
):
|
|
57
|
+
schema = json.loads((Path(directory) / "v2" / f"{name}.json").read_text())
|
|
58
|
+
properties = schema.get("properties") if isinstance(schema, dict) else None
|
|
59
|
+
if not isinstance(properties, dict):
|
|
60
|
+
raise ValueError(f"Missing properties in {name} schema")
|
|
61
|
+
result[method] = frozenset(properties)
|
|
62
|
+
return result
|
|
63
|
+
except (OSError, subprocess.SubprocessError, ValueError) as exc:
|
|
64
|
+
raise ValueError("Could not inspect the unversioned CLI's experimental schema") from exc
|
openai_codex/_sandbox.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import NoReturn
|
|
5
|
+
|
|
6
|
+
from .generated.v2_all import (
|
|
7
|
+
DangerFullAccessSandboxPolicy,
|
|
8
|
+
ReadOnlySandboxPolicy,
|
|
9
|
+
SandboxMode,
|
|
10
|
+
SandboxPolicy,
|
|
11
|
+
WorkspaceWriteSandboxPolicy,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Sandbox(str, Enum):
|
|
16
|
+
"""Preset filesystem access levels for threads and turns.
|
|
17
|
+
|
|
18
|
+
`read_only` allows file reads without writes. `workspace_write` is the
|
|
19
|
+
normal default for projects with a recorded trust decision and allows
|
|
20
|
+
writes inside the workspace and configured writable roots. `full_access`
|
|
21
|
+
removes filesystem access restrictions.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
read_only = "read-only"
|
|
25
|
+
workspace_write = "workspace-write"
|
|
26
|
+
full_access = "full-access"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _require_sandbox(sandbox: Sandbox) -> None:
|
|
30
|
+
if isinstance(sandbox, Sandbox):
|
|
31
|
+
return
|
|
32
|
+
options = ", ".join(f"Sandbox.{value.name}" for value in Sandbox)
|
|
33
|
+
raise ValueError(f"sandbox must be one of: {options}")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _sandbox_mode(sandbox: Sandbox | None) -> SandboxMode | None:
|
|
37
|
+
"""Translate a public preset to the thread lifecycle wire mode."""
|
|
38
|
+
if sandbox is None:
|
|
39
|
+
return None
|
|
40
|
+
_require_sandbox(sandbox)
|
|
41
|
+
|
|
42
|
+
match sandbox:
|
|
43
|
+
case Sandbox.read_only:
|
|
44
|
+
return SandboxMode.read_only
|
|
45
|
+
case Sandbox.workspace_write:
|
|
46
|
+
return SandboxMode.workspace_write
|
|
47
|
+
case Sandbox.full_access:
|
|
48
|
+
return SandboxMode.danger_full_access
|
|
49
|
+
case _:
|
|
50
|
+
return _assert_never_sandbox(sandbox)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _sandbox_policy(sandbox: Sandbox | None) -> SandboxPolicy | None:
|
|
54
|
+
"""Translate a public preset to the turn override wire policy."""
|
|
55
|
+
if sandbox is None:
|
|
56
|
+
return None
|
|
57
|
+
_require_sandbox(sandbox)
|
|
58
|
+
|
|
59
|
+
match sandbox:
|
|
60
|
+
case Sandbox.read_only:
|
|
61
|
+
return SandboxPolicy(
|
|
62
|
+
root=ReadOnlySandboxPolicy(type="readOnly"),
|
|
63
|
+
)
|
|
64
|
+
case Sandbox.workspace_write:
|
|
65
|
+
return SandboxPolicy(
|
|
66
|
+
root=WorkspaceWriteSandboxPolicy(type="workspaceWrite"),
|
|
67
|
+
)
|
|
68
|
+
case Sandbox.full_access:
|
|
69
|
+
return SandboxPolicy(
|
|
70
|
+
root=DangerFullAccessSandboxPolicy(type="dangerFullAccess"),
|
|
71
|
+
)
|
|
72
|
+
case _:
|
|
73
|
+
return _assert_never_sandbox(sandbox)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _assert_never_sandbox(sandbox: NoReturn) -> NoReturn:
|
|
77
|
+
"""Make sandbox mapping exhaustive for static type checkers."""
|
|
78
|
+
raise AssertionError(f"Unhandled sandbox: {sandbox!r}")
|
openai_codex/_version.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from importlib.metadata import PackageNotFoundError, version as distribution_version
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
DISTRIBUTION_NAME = "circle-codex"
|
|
8
|
+
UNKNOWN_VERSION = "0+unknown"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def package_version() -> str:
|
|
12
|
+
source_version = _source_tree_project_version()
|
|
13
|
+
if source_version is not None:
|
|
14
|
+
return source_version
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
return distribution_version(DISTRIBUTION_NAME)
|
|
18
|
+
except PackageNotFoundError:
|
|
19
|
+
return UNKNOWN_VERSION
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _source_tree_project_version() -> str | None:
|
|
23
|
+
pyproject_path = Path(__file__).resolve().parents[2] / "pyproject.toml"
|
|
24
|
+
if not pyproject_path.exists():
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
match = re.search(
|
|
28
|
+
r'(?m)^version = "([^"]+)"$',
|
|
29
|
+
pyproject_path.read_text(encoding="utf-8"),
|
|
30
|
+
)
|
|
31
|
+
if match is None:
|
|
32
|
+
return None
|
|
33
|
+
return match.group(1)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
__version__ = package_version()
|