|
9 | 9 | from codex.app_server.transports import JsonObject |
10 | 10 | from codex.protocol import types as protocol |
11 | 11 |
|
12 | | -JsonValue = str | int | float | bool | None | list["JsonValue"] | dict[str, "JsonValue"] |
13 | 12 | InputItem = ( |
14 | 13 | str |
15 | 14 | | Mapping[str, Any] |
@@ -50,11 +49,13 @@ def request_id(message: BaseModel) -> str | int: |
50 | 49 | def serialize_value(value: object) -> object: |
51 | 50 | if isinstance(value, BaseModel): |
52 | 51 | return value.model_dump(mode="json", by_alias=True, exclude_none=True) |
| 52 | + if isinstance(value, type) and issubclass(value, BaseModel): |
| 53 | + return value.model_json_schema() |
53 | 54 | if isinstance(value, list): |
54 | 55 | return [serialize_value(item) for item in value] |
55 | 56 | if isinstance(value, tuple): |
56 | 57 | return [serialize_value(item) for item in value] |
57 | | - if isinstance(value, dict): |
| 58 | + if isinstance(value, Mapping): |
58 | 59 | return {key: serialize_value(item) for key, item in value.items()} |
59 | 60 | return value |
60 | 61 |
|
@@ -94,6 +95,14 @@ def merge_params( |
94 | 95 | return payload |
95 | 96 |
|
96 | 97 |
|
| 98 | +def has_output_schema(params: BaseModel | Mapping[str, Any] | None) -> bool: |
| 99 | + if params is None: |
| 100 | + return False |
| 101 | + if isinstance(params, BaseModel): |
| 102 | + return getattr(params, "outputSchema", None) is not None |
| 103 | + return params.get("outputSchema") is not None or params.get("output_schema") is not None |
| 104 | + |
| 105 | + |
97 | 106 | def parse_result(result: object, result_model: type[BaseModel]) -> BaseModel: |
98 | 107 | if isinstance(result, result_model): |
99 | 108 | return result |
|
0 commit comments