Files
codex/sdk/python/src/openai_codex/_inputs.py
T
rka-oai 20431d49a0 [sdk/python] Stop advertising HTTP image URLs (#29464)
## Summary

- use generated image data URLs in the Python SDK examples and notebook
- document HTTP and HTTPS image URLs as deprecated and recommend
`LocalImageInput`
- replace the remote-URL integration test with data-URL coverage

`ImageInput` remains available for data URLs. The SDK does not duplicate
app-server URL validation.

## Testing

- `uv run --frozen --no-sync ruff check --output-format=full .`
- `uv run --frozen --no-sync ruff format --check .`
- full Python SDK test suite with an isolated writable
`CODEX_SQLITE_HOME` (119 passed, 38 skipped)
2026-06-22 11:34:14 -07:00

74 lines
1.7 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from .models import JsonObject
@dataclass(slots=True)
class TextInput:
"""Text supplied to a turn or steering request."""
text: str
@dataclass(slots=True)
class ImageInput:
"""Image data URL supplied as turn input."""
url: str
@dataclass(slots=True)
class LocalImageInput:
"""Local image path supplied as turn input."""
path: str
@dataclass(slots=True)
class SkillInput:
"""Named skill reference supplied as turn input."""
name: str
path: str
@dataclass(slots=True)
class MentionInput:
"""Named resource mention supplied as turn input."""
name: str
path: str
InputItem = TextInput | ImageInput | LocalImageInput | SkillInput | MentionInput
Input = list[InputItem] | InputItem
RunInput = Input | str
def _to_wire_item(item: InputItem) -> JsonObject:
if isinstance(item, TextInput):
return {"type": "text", "text": item.text}
if isinstance(item, ImageInput):
return {"type": "image", "url": item.url}
if isinstance(item, LocalImageInput):
return {"type": "localImage", "path": item.path}
if isinstance(item, SkillInput):
return {"type": "skill", "name": item.name, "path": item.path}
if isinstance(item, MentionInput):
return {"type": "mention", "name": item.name, "path": item.path}
raise TypeError(f"unsupported input item: {type(item)!r}")
def _to_wire_input(input: Input) -> list[JsonObject]:
if isinstance(input, list):
return [_to_wire_item(i) for i in input]
return [_to_wire_item(input)]
def _normalize_run_input(input: RunInput) -> Input:
if isinstance(input, str):
return TextInput(input)
return input