diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71a918c..b654550 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,14 @@ name: CI on: push: - branches-ignore: - - 'generated' - - 'codegen/**' - - 'integrated/**' - - 'stl-preview-head/**' - - 'stl-preview-base/**' + branches: + - '**' + - '!integrated/**' + - '!stl-preview-head/**' + - '!stl-preview-base/**' + - '!generated' + - '!codegen/**' + - 'codegen/stl/**' pull_request: branches-ignore: - 'stl-preview-head/**' @@ -55,14 +57,18 @@ jobs: run: uv build - name: Get GitHub OIDC Token - if: github.repository == 'stainless-sdks/warp-api-python' + if: |- + github.repository == 'stainless-sdks/warp-api-python' && + !startsWith(github.ref, 'refs/heads/stl/') id: github-oidc uses: actions/github-script@v8 with: script: core.setOutput('github_token', await core.getIDToken()); - name: Upload tarball - if: github.repository == 'stainless-sdks/warp-api-python' + if: |- + github.repository == 'stainless-sdks/warp-api-python' && + !startsWith(github.ref, 'refs/heads/stl/') env: URL: https://pkg.stainless.com/s AUTH: ${{ steps.github-oidc.outputs.github_token }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6d78745..091cfb1 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.9.0" + ".": "0.10.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 26fe290..7dd01bc 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 14 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/warp-bnavetta%2Fwarp-api-39e18bbb8b0af73eca7a880f56afbdecd69e3e5bab82a04c4d6429c32d7e6727.yml -openapi_spec_hash: 7a0de988bb37416d6e80f4a4bbe9d0d0 -config_hash: 0884847870200ee9d34bb00ce94aaa8e +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/warp-bnavetta%2Fwarp-api-6c175d34cab49d79dbb24289ae516867404c42f3097264bbae171aced72ecc49.yml +openapi_spec_hash: 5abb55a1fc2836207bc88d4815f47f24 +config_hash: a4b1ffc5b2e162efb3d557c7461153c1 diff --git a/CHANGELOG.md b/CHANGELOG.md index bd2fe52..ad87243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,29 @@ # Changelog +## 0.10.0 (2026-03-19) + +Full Changelog: [v0.9.0...v0.10.0](https://github.com/warpdotdev/oz-sdk-python/compare/v0.9.0...v0.10.0) + +### Features + +* **api:** error and error_code as types ([9766f85](https://github.com/warpdotdev/oz-sdk-python/commit/9766f85585ff3553f1f366476a3a6806f2534b22)) +* **api:** fix ScheduledAgentHistoryItem name ([ac75431](https://github.com/warpdotdev/oz-sdk-python/commit/ac754319e41b73d323cf9a36cbcf1c4dce2902bb)) +* **api:** fix schema version issues ([9c2f6a3](https://github.com/warpdotdev/oz-sdk-python/commit/9c2f6a32fa06812860efa1d76893dd8d2b60d176)) +* **api:** sorting ([0cc041e](https://github.com/warpdotdev/oz-sdk-python/commit/0cc041edf53d26c4f38c64faa7fd065d7a6760ab)) + + +### Bug Fixes + +* **deps:** bump minimum typing-extensions version ([4f3ec38](https://github.com/warpdotdev/oz-sdk-python/commit/4f3ec385748655ca8fde2457ffe402f8bf30db56)) +* **pydantic:** do not pass `by_alias` unless set ([45e0377](https://github.com/warpdotdev/oz-sdk-python/commit/45e0377a495aa67b0ee7d4415cbf13b526dbbf7e)) +* sanitize endpoint path params ([da2a124](https://github.com/warpdotdev/oz-sdk-python/commit/da2a124f15c2b69f67905cfe4b75b52d90ece562)) + + +### Chores + +* **ci:** skip uploading artifacts on stainless-internal branches ([1ef523c](https://github.com/warpdotdev/oz-sdk-python/commit/1ef523caca4d137def551560de8c8a75c761d0f9)) +* **internal:** tweak CI branches ([21f9e2e](https://github.com/warpdotdev/oz-sdk-python/commit/21f9e2e8065a3202a149b3a2440c5adb7d084681)) + ## 0.9.0 (2026-03-03) Full Changelog: [v0.8.0...v0.9.0](https://github.com/warpdotdev/oz-sdk-python/compare/v0.8.0...v0.9.0) diff --git a/api.md b/api.md index a28b73a..19e78a3 100644 --- a/api.md +++ b/api.md @@ -7,6 +7,8 @@ from oz_agent_sdk.types import ( AgentSkill, AmbientAgentConfig, CloudEnvironmentConfig, + Error, + ErrorCode, McpServerConfig, Scope, UserProfile, diff --git a/pyproject.toml b/pyproject.toml index add485e..38478e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "oz-agent-sdk" -version = "0.9.0" +version = "0.10.0" description = "The official Python library for the oz-api API" dynamic = ["readme"] license = "Apache-2.0" @@ -11,7 +11,7 @@ authors = [ dependencies = [ "httpx>=0.23.0, <1", "pydantic>=1.9.0, <3", - "typing-extensions>=4.10, <5", + "typing-extensions>=4.14, <5", "anyio>=3.5.0, <5", "distro>=1.7.0, <2", "sniffio", diff --git a/src/oz_agent_sdk/_compat.py b/src/oz_agent_sdk/_compat.py index 786ff42..e6690a4 100644 --- a/src/oz_agent_sdk/_compat.py +++ b/src/oz_agent_sdk/_compat.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload from datetime import date, datetime -from typing_extensions import Self, Literal +from typing_extensions import Self, Literal, TypedDict import pydantic from pydantic.fields import FieldInfo @@ -131,6 +131,10 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str: return model.model_dump_json(indent=indent) +class _ModelDumpKwargs(TypedDict, total=False): + by_alias: bool + + def model_dump( model: pydantic.BaseModel, *, @@ -142,6 +146,9 @@ def model_dump( by_alias: bool | None = None, ) -> dict[str, Any]: if (not PYDANTIC_V1) or hasattr(model, "model_dump"): + kwargs: _ModelDumpKwargs = {} + if by_alias is not None: + kwargs["by_alias"] = by_alias return model.model_dump( mode=mode, exclude=exclude, @@ -149,7 +156,7 @@ def model_dump( exclude_defaults=exclude_defaults, # warnings are not supported in Pydantic v1 warnings=True if PYDANTIC_V1 else warnings, - by_alias=by_alias, + **kwargs, ) return cast( "dict[str, Any]", diff --git a/src/oz_agent_sdk/_utils/__init__.py b/src/oz_agent_sdk/_utils/__init__.py index dc64e29..10cb66d 100644 --- a/src/oz_agent_sdk/_utils/__init__.py +++ b/src/oz_agent_sdk/_utils/__init__.py @@ -1,3 +1,4 @@ +from ._path import path_template as path_template from ._sync import asyncify as asyncify from ._proxy import LazyProxy as LazyProxy from ._utils import ( diff --git a/src/oz_agent_sdk/_utils/_path.py b/src/oz_agent_sdk/_utils/_path.py new file mode 100644 index 0000000..4d6e1e4 --- /dev/null +++ b/src/oz_agent_sdk/_utils/_path.py @@ -0,0 +1,127 @@ +from __future__ import annotations + +import re +from typing import ( + Any, + Mapping, + Callable, +) +from urllib.parse import quote + +# Matches '.' or '..' where each dot is either literal or percent-encoded (%2e / %2E). +_DOT_SEGMENT_RE = re.compile(r"^(?:\.|%2[eE]){1,2}$") + +_PLACEHOLDER_RE = re.compile(r"\{(\w+)\}") + + +def _quote_path_segment_part(value: str) -> str: + """Percent-encode `value` for use in a URI path segment. + + Considers characters not in `pchar` set from RFC 3986 §3.3 to be unsafe. + https://datatracker.ietf.org/doc/html/rfc3986#section-3.3 + """ + # quote() already treats unreserved characters (letters, digits, and -._~) + # as safe, so we only need to add sub-delims, ':', and '@'. + # Notably, unlike the default `safe` for quote(), / is unsafe and must be quoted. + return quote(value, safe="!$&'()*+,;=:@") + + +def _quote_query_part(value: str) -> str: + """Percent-encode `value` for use in a URI query string. + + Considers &, = and characters not in `query` set from RFC 3986 §3.4 to be unsafe. + https://datatracker.ietf.org/doc/html/rfc3986#section-3.4 + """ + return quote(value, safe="!$'()*+,;:@/?") + + +def _quote_fragment_part(value: str) -> str: + """Percent-encode `value` for use in a URI fragment. + + Considers characters not in `fragment` set from RFC 3986 §3.5 to be unsafe. + https://datatracker.ietf.org/doc/html/rfc3986#section-3.5 + """ + return quote(value, safe="!$&'()*+,;=:@/?") + + +def _interpolate( + template: str, + values: Mapping[str, Any], + quoter: Callable[[str], str], +) -> str: + """Replace {name} placeholders in `template`, quoting each value with `quoter`. + + Placeholder names are looked up in `values`. + + Raises: + KeyError: If a placeholder is not found in `values`. + """ + # re.split with a capturing group returns alternating + # [text, name, text, name, ..., text] elements. + parts = _PLACEHOLDER_RE.split(template) + + for i in range(1, len(parts), 2): + name = parts[i] + if name not in values: + raise KeyError(f"a value for placeholder {{{name}}} was not provided") + val = values[name] + if val is None: + parts[i] = "null" + elif isinstance(val, bool): + parts[i] = "true" if val else "false" + else: + parts[i] = quoter(str(values[name])) + + return "".join(parts) + + +def path_template(template: str, /, **kwargs: Any) -> str: + """Interpolate {name} placeholders in `template` from keyword arguments. + + Args: + template: The template string containing {name} placeholders. + **kwargs: Keyword arguments to interpolate into the template. + + Returns: + The template with placeholders interpolated and percent-encoded. + + Safe characters for percent-encoding are dependent on the URI component. + Placeholders in path and fragment portions are percent-encoded where the `segment` + and `fragment` sets from RFC 3986 respectively are considered safe. + Placeholders in the query portion are percent-encoded where the `query` set from + RFC 3986 §3.3 is considered safe except for = and & characters. + + Raises: + KeyError: If a placeholder is not found in `kwargs`. + ValueError: If resulting path contains /./ or /../ segments (including percent-encoded dot-segments). + """ + # Split the template into path, query, and fragment portions. + fragment_template: str | None = None + query_template: str | None = None + + rest = template + if "#" in rest: + rest, fragment_template = rest.split("#", 1) + if "?" in rest: + rest, query_template = rest.split("?", 1) + path_template = rest + + # Interpolate each portion with the appropriate quoting rules. + path_result = _interpolate(path_template, kwargs, _quote_path_segment_part) + + # Reject dot-segments (. and ..) in the final assembled path. The check + # runs after interpolation so that adjacent placeholders or a mix of static + # text and placeholders that together form a dot-segment are caught. + # Also reject percent-encoded dot-segments to protect against incorrectly + # implemented normalization in servers/proxies. + for segment in path_result.split("/"): + if _DOT_SEGMENT_RE.match(segment): + raise ValueError(f"Constructed path {path_result!r} contains dot-segment {segment!r} which is not allowed") + + result = path_result + if query_template is not None: + result += "?" + _interpolate(query_template, kwargs, _quote_query_part) + if fragment_template is not None: + result += "#" + _interpolate(fragment_template, kwargs, _quote_fragment_part) + + return result diff --git a/src/oz_agent_sdk/_version.py b/src/oz_agent_sdk/_version.py index 39f67b8..fdf4152 100644 --- a/src/oz_agent_sdk/_version.py +++ b/src/oz_agent_sdk/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "oz_agent_sdk" -__version__ = "0.9.0" # x-release-please-version +__version__ = "0.10.0" # x-release-please-version diff --git a/src/oz_agent_sdk/resources/agent/agent.py b/src/oz_agent_sdk/resources/agent/agent.py index d4f0a9f..4adaca9 100644 --- a/src/oz_agent_sdk/resources/agent/agent.py +++ b/src/oz_agent_sdk/resources/agent/agent.py @@ -17,7 +17,7 @@ ) from ...types import agent_run_params, agent_list_params from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from .sessions import ( SessionsResource, AsyncSessionsResource, @@ -178,7 +178,7 @@ def get_artifact( if not artifact_uid: raise ValueError(f"Expected a non-empty value for `artifact_uid` but received {artifact_uid!r}") return self._get( - f"/agent/artifacts/{artifact_uid}", + path_template("/agent/artifacts/{artifact_uid}", artifact_uid=artifact_uid), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -392,7 +392,7 @@ async def get_artifact( if not artifact_uid: raise ValueError(f"Expected a non-empty value for `artifact_uid` but received {artifact_uid!r}") return await self._get( - f"/agent/artifacts/{artifact_uid}", + path_template("/agent/artifacts/{artifact_uid}", artifact_uid=artifact_uid), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/oz_agent_sdk/resources/agent/runs.py b/src/oz_agent_sdk/resources/agent/runs.py index 3b4d1d2..440bdcf 100644 --- a/src/oz_agent_sdk/resources/agent/runs.py +++ b/src/oz_agent_sdk/resources/agent/runs.py @@ -9,7 +9,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -77,7 +77,7 @@ def retrieve( if not run_id: raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}") return self._get( - f"/agent/runs/{run_id}", + path_template("/agent/runs/{run_id}", run_id=run_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -100,6 +100,8 @@ def list( schedule_id: str | Omit = omit, skill: str | Omit = omit, skill_spec: str | Omit = omit, + sort_by: Literal["updated_at", "created_at", "title", "agent"] | Omit = omit, + sort_order: Literal["asc", "desc"] | Omit = omit, source: RunSourceType | Omit = omit, state: List[RunState] | Omit = omit, updated_after: Union[str, datetime] | Omit = omit, @@ -112,8 +114,8 @@ def list( ) -> RunListResponse: """Retrieve a paginated list of agent runs with optional filtering. - Results are - ordered by creation time (newest first). + Results default + to `sort_by=updated_at` and `sort_order=desc`. Args: artifact_type: Filter runs by artifact type (PLAN or PULL_REQUEST) @@ -143,6 +145,15 @@ def list( skill_spec: Filter runs by skill spec (e.g., "owner/repo:path/to/SKILL.md") + sort_by: Sort field for results. + + - `updated_at`: Sort by last update timestamp (default) + - `created_at`: Sort by creation timestamp + - `title`: Sort alphabetically by run title + - `agent`: Sort alphabetically by skill. Runs without a skill are grouped last. + + sort_order: Sort direction + source: Filter by run source type state: Filter by run state. Can be specified multiple times to match any of the given @@ -180,6 +191,8 @@ def list( "schedule_id": schedule_id, "skill": skill, "skill_spec": skill_spec, + "sort_by": sort_by, + "sort_order": sort_order, "source": source, "state": state, "updated_after": updated_after, @@ -222,7 +235,7 @@ def cancel( if not run_id: raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}") return self._post( - f"/agent/runs/{run_id}/cancel", + path_template("/agent/runs/{run_id}/cancel", run_id=run_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -279,7 +292,7 @@ async def retrieve( if not run_id: raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}") return await self._get( - f"/agent/runs/{run_id}", + path_template("/agent/runs/{run_id}", run_id=run_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -302,6 +315,8 @@ async def list( schedule_id: str | Omit = omit, skill: str | Omit = omit, skill_spec: str | Omit = omit, + sort_by: Literal["updated_at", "created_at", "title", "agent"] | Omit = omit, + sort_order: Literal["asc", "desc"] | Omit = omit, source: RunSourceType | Omit = omit, state: List[RunState] | Omit = omit, updated_after: Union[str, datetime] | Omit = omit, @@ -314,8 +329,8 @@ async def list( ) -> RunListResponse: """Retrieve a paginated list of agent runs with optional filtering. - Results are - ordered by creation time (newest first). + Results default + to `sort_by=updated_at` and `sort_order=desc`. Args: artifact_type: Filter runs by artifact type (PLAN or PULL_REQUEST) @@ -345,6 +360,15 @@ async def list( skill_spec: Filter runs by skill spec (e.g., "owner/repo:path/to/SKILL.md") + sort_by: Sort field for results. + + - `updated_at`: Sort by last update timestamp (default) + - `created_at`: Sort by creation timestamp + - `title`: Sort alphabetically by run title + - `agent`: Sort alphabetically by skill. Runs without a skill are grouped last. + + sort_order: Sort direction + source: Filter by run source type state: Filter by run state. Can be specified multiple times to match any of the given @@ -382,6 +406,8 @@ async def list( "schedule_id": schedule_id, "skill": skill, "skill_spec": skill_spec, + "sort_by": sort_by, + "sort_order": sort_order, "source": source, "state": state, "updated_after": updated_after, @@ -424,7 +450,7 @@ async def cancel( if not run_id: raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}") return await self._post( - f"/agent/runs/{run_id}/cancel", + path_template("/agent/runs/{run_id}/cancel", run_id=run_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/oz_agent_sdk/resources/agent/schedules.py b/src/oz_agent_sdk/resources/agent/schedules.py index ff36da2..a4b5592 100644 --- a/src/oz_agent_sdk/resources/agent/schedules.py +++ b/src/oz_agent_sdk/resources/agent/schedules.py @@ -5,7 +5,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -137,7 +137,7 @@ def retrieve( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return self._get( - f"/agent/schedules/{schedule_id}", + path_template("/agent/schedules/{schedule_id}", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -188,7 +188,7 @@ def update( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return self._put( - f"/agent/schedules/{schedule_id}", + path_template("/agent/schedules/{schedule_id}", schedule_id=schedule_id), body=maybe_transform( { "cron_schedule": cron_schedule, @@ -255,7 +255,7 @@ def delete( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return self._delete( - f"/agent/schedules/{schedule_id}", + path_template("/agent/schedules/{schedule_id}", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -290,7 +290,7 @@ def pause( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return self._post( - f"/agent/schedules/{schedule_id}/pause", + path_template("/agent/schedules/{schedule_id}/pause", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -325,7 +325,7 @@ def resume( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return self._post( - f"/agent/schedules/{schedule_id}/resume", + path_template("/agent/schedules/{schedule_id}/resume", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -446,7 +446,7 @@ async def retrieve( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return await self._get( - f"/agent/schedules/{schedule_id}", + path_template("/agent/schedules/{schedule_id}", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -497,7 +497,7 @@ async def update( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return await self._put( - f"/agent/schedules/{schedule_id}", + path_template("/agent/schedules/{schedule_id}", schedule_id=schedule_id), body=await async_maybe_transform( { "cron_schedule": cron_schedule, @@ -564,7 +564,7 @@ async def delete( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return await self._delete( - f"/agent/schedules/{schedule_id}", + path_template("/agent/schedules/{schedule_id}", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -599,7 +599,7 @@ async def pause( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return await self._post( - f"/agent/schedules/{schedule_id}/pause", + path_template("/agent/schedules/{schedule_id}/pause", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -634,7 +634,7 @@ async def resume( if not schedule_id: raise ValueError(f"Expected a non-empty value for `schedule_id` but received {schedule_id!r}") return await self._post( - f"/agent/schedules/{schedule_id}/resume", + path_template("/agent/schedules/{schedule_id}/resume", schedule_id=schedule_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/oz_agent_sdk/resources/agent/sessions.py b/src/oz_agent_sdk/resources/agent/sessions.py index 0c1bd41..0beb811 100644 --- a/src/oz_agent_sdk/resources/agent/sessions.py +++ b/src/oz_agent_sdk/resources/agent/sessions.py @@ -5,6 +5,7 @@ import httpx from ..._types import Body, Query, Headers, NotGiven, not_given +from ..._utils import path_template from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -69,7 +70,7 @@ def check_redirect( if not session_uuid: raise ValueError(f"Expected a non-empty value for `session_uuid` but received {session_uuid!r}") return self._get( - f"/agent/sessions/{session_uuid}/redirect", + path_template("/agent/sessions/{session_uuid}/redirect", session_uuid=session_uuid), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -127,7 +128,7 @@ async def check_redirect( if not session_uuid: raise ValueError(f"Expected a non-empty value for `session_uuid` but received {session_uuid!r}") return await self._get( - f"/agent/sessions/{session_uuid}/redirect", + path_template("/agent/sessions/{session_uuid}/redirect", session_uuid=session_uuid), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/oz_agent_sdk/types/__init__.py b/src/oz_agent_sdk/types/__init__.py index 5398f2d..f4d2daa 100644 --- a/src/oz_agent_sdk/types/__init__.py +++ b/src/oz_agent_sdk/types/__init__.py @@ -3,6 +3,7 @@ from __future__ import annotations from .scope import Scope as Scope +from .error_code import ErrorCode as ErrorCode from .agent_skill import AgentSkill as AgentSkill from .user_profile import UserProfile as UserProfile from .agent_run_params import AgentRunParams as AgentRunParams diff --git a/src/oz_agent_sdk/types/agent/run_item.py b/src/oz_agent_sdk/types/agent/run_item.py index b486acf..014ab6b 100644 --- a/src/oz_agent_sdk/types/agent/run_item.py +++ b/src/oz_agent_sdk/types/agent/run_item.py @@ -2,11 +2,11 @@ from typing import List, Optional from datetime import datetime -from typing_extensions import Literal from ..scope import Scope from ..._models import BaseModel from .run_state import RunState +from ..error_code import ErrorCode from ..user_profile import UserProfile from .artifact_item import ArtifactItem from .run_source_type import RunSourceType @@ -69,26 +69,7 @@ class StatusMessage(BaseModel): message: str """Human-readable status message""" - error_code: Optional[ - Literal[ - "insufficient_credits", - "feature_not_available", - "external_authentication_required", - "not_authorized", - "invalid_request", - "resource_not_found", - "budget_exceeded", - "integration_disabled", - "integration_not_configured", - "operation_not_supported", - "environment_setup_failed", - "content_policy_violation", - "conflict", - "authentication_required", - "resource_unavailable", - "internal_error", - ] - ] = None + error_code: Optional[ErrorCode] = None """ Machine-readable error code identifying the problem type. Used in the `type` URI of Error responses and in the `error_code` field of RunStatusMessage. diff --git a/src/oz_agent_sdk/types/agent/run_list_params.py b/src/oz_agent_sdk/types/agent/run_list_params.py index d0c89d9..cb662bc 100644 --- a/src/oz_agent_sdk/types/agent/run_list_params.py +++ b/src/oz_agent_sdk/types/agent/run_list_params.py @@ -56,6 +56,18 @@ class RunListParams(TypedDict, total=False): skill_spec: str """Filter runs by skill spec (e.g., "owner/repo:path/to/SKILL.md")""" + sort_by: Literal["updated_at", "created_at", "title", "agent"] + """Sort field for results. + + - `updated_at`: Sort by last update timestamp (default) + - `created_at`: Sort by creation timestamp + - `title`: Sort alphabetically by run title + - `agent`: Sort alphabetically by skill. Runs without a skill are grouped last. + """ + + sort_order: Literal["asc", "desc"] + """Sort direction""" + source: RunSourceType """Filter by run source type""" diff --git a/src/oz_agent_sdk/types/error_code.py b/src/oz_agent_sdk/types/error_code.py new file mode 100644 index 0000000..5732142 --- /dev/null +++ b/src/oz_agent_sdk/types/error_code.py @@ -0,0 +1,24 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing_extensions import Literal, TypeAlias + +__all__ = ["ErrorCode"] + +ErrorCode: TypeAlias = Literal[ + "insufficient_credits", + "feature_not_available", + "external_authentication_required", + "not_authorized", + "invalid_request", + "resource_not_found", + "budget_exceeded", + "integration_disabled", + "integration_not_configured", + "operation_not_supported", + "environment_setup_failed", + "content_policy_violation", + "conflict", + "authentication_required", + "resource_unavailable", + "internal_error", +] diff --git a/tests/api_resources/agent/test_runs.py b/tests/api_resources/agent/test_runs.py index 04ec55d..480564c 100644 --- a/tests/api_resources/agent/test_runs.py +++ b/tests/api_resources/agent/test_runs.py @@ -83,6 +83,8 @@ def test_method_list_with_all_params(self, client: OzAPI) -> None: schedule_id="schedule_id", skill="skill", skill_spec="skill_spec", + sort_by="updated_at", + sort_order="asc", source="LINEAR", state=["QUEUED"], updated_after=parse_datetime("2019-12-27T18:11:19.117Z"), @@ -224,6 +226,8 @@ async def test_method_list_with_all_params(self, async_client: AsyncOzAPI) -> No schedule_id="schedule_id", skill="skill", skill_spec="skill_spec", + sort_by="updated_at", + sort_order="asc", source="LINEAR", state=["QUEUED"], updated_after=parse_datetime("2019-12-27T18:11:19.117Z"), diff --git a/tests/test_utils/test_path.py b/tests/test_utils/test_path.py new file mode 100644 index 0000000..6d9039f --- /dev/null +++ b/tests/test_utils/test_path.py @@ -0,0 +1,89 @@ +from __future__ import annotations + +from typing import Any + +import pytest + +from oz_agent_sdk._utils._path import path_template + + +@pytest.mark.parametrize( + "template, kwargs, expected", + [ + ("/v1/{id}", dict(id="abc"), "/v1/abc"), + ("/v1/{a}/{b}", dict(a="x", b="y"), "/v1/x/y"), + ("/v1/{a}{b}/path/{c}?val={d}#{e}", dict(a="x", b="y", c="z", d="u", e="v"), "/v1/xy/path/z?val=u#v"), + ("/{w}/{w}", dict(w="echo"), "/echo/echo"), + ("/v1/static", {}, "/v1/static"), + ("", {}, ""), + ("/v1/?q={n}&count=10", dict(n=42), "/v1/?q=42&count=10"), + ("/v1/{v}", dict(v=None), "/v1/null"), + ("/v1/{v}", dict(v=True), "/v1/true"), + ("/v1/{v}", dict(v=False), "/v1/false"), + ("/v1/{v}", dict(v=".hidden"), "/v1/.hidden"), # dot prefix ok + ("/v1/{v}", dict(v="file.txt"), "/v1/file.txt"), # dot in middle ok + ("/v1/{v}", dict(v="..."), "/v1/..."), # triple dot ok + ("/v1/{a}{b}", dict(a=".", b="txt"), "/v1/.txt"), # dot var combining with adjacent to be ok + ("/items?q={v}#{f}", dict(v=".", f=".."), "/items?q=.#.."), # dots in query/fragment are fine + ( + "/v1/{a}?query={b}", + dict(a="../../other/endpoint", b="a&bad=true"), + "/v1/..%2F..%2Fother%2Fendpoint?query=a%26bad%3Dtrue", + ), + ("/v1/{val}", dict(val="a/b/c"), "/v1/a%2Fb%2Fc"), + ("/v1/{val}", dict(val="a/b/c?query=value"), "/v1/a%2Fb%2Fc%3Fquery=value"), + ("/v1/{val}", dict(val="a/b/c?query=value&bad=true"), "/v1/a%2Fb%2Fc%3Fquery=value&bad=true"), + ("/v1/{val}", dict(val="%20"), "/v1/%2520"), # escapes escape sequences in input + # Query: slash and ? are safe, # is not + ("/items?q={v}", dict(v="a/b"), "/items?q=a/b"), + ("/items?q={v}", dict(v="a?b"), "/items?q=a?b"), + ("/items?q={v}", dict(v="a#b"), "/items?q=a%23b"), + ("/items?q={v}", dict(v="a b"), "/items?q=a%20b"), + # Fragment: slash and ? are safe + ("/docs#{v}", dict(v="a/b"), "/docs#a/b"), + ("/docs#{v}", dict(v="a?b"), "/docs#a?b"), + # Path: slash, ? and # are all encoded + ("/v1/{v}", dict(v="a/b"), "/v1/a%2Fb"), + ("/v1/{v}", dict(v="a?b"), "/v1/a%3Fb"), + ("/v1/{v}", dict(v="a#b"), "/v1/a%23b"), + # same var encoded differently by component + ( + "/v1/{v}?q={v}#{v}", + dict(v="a/b?c#d"), + "/v1/a%2Fb%3Fc%23d?q=a/b?c%23d#a/b?c%23d", + ), + ("/v1/{val}", dict(val="x?admin=true"), "/v1/x%3Fadmin=true"), # query injection + ("/v1/{val}", dict(val="x#admin"), "/v1/x%23admin"), # fragment injection + ], +) +def test_interpolation(template: str, kwargs: dict[str, Any], expected: str) -> None: + assert path_template(template, **kwargs) == expected + + +def test_missing_kwarg_raises_key_error() -> None: + with pytest.raises(KeyError, match="org_id"): + path_template("/v1/{org_id}") + + +@pytest.mark.parametrize( + "template, kwargs", + [ + ("{a}/path", dict(a=".")), + ("{a}/path", dict(a="..")), + ("/v1/{a}", dict(a=".")), + ("/v1/{a}", dict(a="..")), + ("/v1/{a}/path", dict(a=".")), + ("/v1/{a}/path", dict(a="..")), + ("/v1/{a}{b}", dict(a=".", b=".")), # adjacent vars → ".." + ("/v1/{a}.", dict(a=".")), # var + static → ".." + ("/v1/{a}{b}", dict(a="", b=".")), # empty + dot → "." + ("/v1/%2e/{x}", dict(x="ok")), # encoded dot in static text + ("/v1/%2e./{x}", dict(x="ok")), # mixed encoded ".." in static + ("/v1/.%2E/{x}", dict(x="ok")), # mixed encoded ".." in static + ("/v1/{v}?q=1", dict(v="..")), + ("/v1/{v}#frag", dict(v="..")), + ], +) +def test_dot_segment_rejected(template: str, kwargs: dict[str, Any]) -> None: + with pytest.raises(ValueError, match="dot-segment"): + path_template(template, **kwargs) diff --git a/uv.lock b/uv.lock index 5fc85f8..816e22a 100644 --- a/uv.lock +++ b/uv.lock @@ -830,7 +830,7 @@ requires-dist = [ { name = "httpx-aiohttp", marker = "extra == 'aiohttp'", specifier = ">=0.1.9" }, { name = "pydantic", specifier = ">=1.9.0,<3" }, { name = "sniffio" }, - { name = "typing-extensions", specifier = ">=4.10,<5" }, + { name = "typing-extensions", specifier = ">=4.14,<5" }, ] provides-extras = ["aiohttp"]