|
27 | 27 |
|
28 | 28 | logger = logging.getLogger(__name__) |
29 | 29 |
|
| 30 | +# Shorthand payload shapes, spelled out so every schema node carries a concrete |
| 31 | +# ``type``: strict function-schema validators reject an untyped property, and |
| 32 | +# ``Any`` would degrade to ``string`` and reject nested rows instead. |
| 33 | +_Scalar = str | int | float | bool |
| 34 | +_Rows = list[list[_Scalar] | dict[str, Any]] |
| 35 | +_JsonArray = list[dict[str, Any] | list[_Scalar] | _Scalar] |
| 36 | + |
30 | 37 | _WRITER_SRC = writer_src() |
31 | 38 | _DOC_EXTS = {"docx", "xlsx", "pptx"} |
32 | 39 | _TEXT_EXTS = {"txt", "md", "csv", "tsv", "json", "jsonl", "html", "htm"} |
@@ -210,8 +217,8 @@ def desugar_text_shorthand( |
210 | 217 | *, |
211 | 218 | ops: list[dict[str, Any]] | str | None, |
212 | 219 | content: str | None, |
213 | | - rows: list[Any] | str | None, |
214 | | - data: dict[str, Any] | list[Any] | str | None, |
| 220 | + rows: _Rows | str | None, |
| 221 | + data: dict[str, Any] | _JsonArray | str | None, |
215 | 222 | overwrite: bool = False, |
216 | 223 | ) -> tuple[list[dict[str, Any]] | str | None, str]: |
217 | 224 | """Fold a top-level ``content``/``rows``/``data`` into one ``create`` op. |
@@ -258,8 +265,8 @@ async def create_file( |
258 | 265 | path: str, |
259 | 266 | ops: list[dict[str, Any]] | str | None = None, |
260 | 267 | content: str | None = None, |
261 | | - rows: list[Any] | str | None = None, |
262 | | - data: dict[str, Any] | list[Any] | str | None = None, |
| 268 | + rows: _Rows | str | None = None, |
| 269 | + data: dict[str, Any] | _JsonArray | str | None = None, |
263 | 270 | overwrite: bool = False, |
264 | 271 | ) -> str: |
265 | 272 | """Create or edit a deliverable file in the sandbox — office (docx/xlsx/pptx) |
@@ -547,11 +554,3 @@ async def create_file( |
547 | 554 | ) |
548 | 555 | return result.stdout or "(no output)" |
549 | 556 |
|
550 | | - |
551 | | -# The schema generator maps ``Any`` to ``{"type": "string"}``, which would make |
552 | | -# schema-aware providers reject nested csv rows and JSON arrays. Items of these |
553 | | -# shorthand arrays are genuinely open. |
554 | | -for _name in ("rows", "data"): |
555 | | - for _option in create_file.parameters["properties"][_name].get("anyOf", []): |
556 | | - if _option.get("type") == "array": |
557 | | - _option["items"] = {} |
0 commit comments