Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.6.0"
".": "2.6.1"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/mozilla%2Ftabstack-5e6e6508dca15391d72cbea74ec33838c511cbc17e046699142f97d1573b069a.yml
openapi_spec_hash: b73b5922a495fd375736896912815d18
config_hash: 57c64e5e8fe99c1bd7af536d82af4ad9
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/mozilla/tabstack-c97fe4d7e39fd2f35a75dc7fdeb6d3f19aab2f9b56d4983c3376a5433dc9e268.yml
openapi_spec_hash: 8a4612fa101f82893c6edca118a86a2d
config_hash: 5827ec0cdbbac0e7c5db2f5456f67dca
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 2.6.1 (2026-05-05)

Full Changelog: [v2.6.0...v2.6.1](https://github.com/Mozilla-Ocho/tabstack-python/compare/v2.6.0...v2.6.1)

### Features

* **api:** add endpoint specfic timeouts ([15bcc6b](https://github.com/Mozilla-Ocho/tabstack-python/commit/15bcc6b29cf0e64fa5bf544f099471dac26d9cea))
* **api:** manual updates ([e89cb7a](https://github.com/Mozilla-Ocho/tabstack-python/commit/e89cb7a58d7e139cb46d54f15fbb26515a54f205))
* **automate:** emit task:trace_context SSE event with trace ID ([20d3ff3](https://github.com/Mozilla-Ocho/tabstack-python/commit/20d3ff3b4c5e8d7d287ef9807ecbc33c522bed37))
* support setting headers via env ([4699481](https://github.com/Mozilla-Ocho/tabstack-python/commit/4699481aee8341952e2cae287bc0ff0fc629a292))


### Bug Fixes

* use correct field name format for multipart file arrays ([a10a1ed](https://github.com/Mozilla-Ocho/tabstack-python/commit/a10a1ed1298179229f69dc3c12b899f6242ed1b4))


### Chores

* **internal:** reformat pyproject.toml ([c909f52](https://github.com/Mozilla-Ocho/tabstack-python/commit/c909f52bf36e746213c2cb8b316e6eb1909a2e80))

## 2.6.0 (2026-04-24)

Full Changelog: [v2.5.0...v2.6.0](https://github.com/Mozilla-Ocho/tabstack-python/compare/v2.5.0...v2.6.0)
Expand Down
14 changes: 13 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Shared Types

```python
from tabstack.types import GeotargetGeoTarget
```

# Agent

Types:

```python
from tabstack.types import AutomateEvent, ResearchEvent, AgentAutomateInputResponse
from tabstack.types import (
AutomateEvent,
ResearchEvent,
V1GlobalBuffer,
V1ResearchQuestionAssessment,
AgentAutomateInputResponse,
)
```

Methods:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tabstack"
version = "2.6.0"
version = "2.6.1"
description = "The official Python library for the tabstack API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -154,7 +154,7 @@ show_error_codes = true
#
# We also exclude our `tests` as mypy doesn't always infer
# types correctly and Pyright will still catch any type errors.
exclude = ['src/tabstack/_files.py', '_dev/.*.py', 'tests/.*']
exclude = ["src/tabstack/_files.py", "_dev/.*.py", "tests/.*"]

strict_equality = true
implicit_reexport = true
Expand Down
24 changes: 23 additions & 1 deletion src/tabstack/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
RequestOptions,
not_given,
)
from ._utils import is_given, get_async_library
from ._utils import (
is_given,
is_mapping_t,
get_async_library,
)
from ._compat import cached_property
from ._version import __version__
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
Expand Down Expand Up @@ -92,6 +96,15 @@ def __init__(
if base_url is None:
base_url = f"https://api.tabstack.ai/v1"

custom_headers_env = os.environ.get("TABSTACK_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down Expand Up @@ -278,6 +291,15 @@ def __init__(
if base_url is None:
base_url = f"https://api.tabstack.ai/v1"

custom_headers_env = os.environ.get("TABSTACK_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down
8 changes: 2 additions & 6 deletions src/tabstack/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

from typing import Any, List, Tuple, Union, Mapping, TypeVar
from urllib.parse import parse_qs, urlencode
from typing_extensions import Literal, get_args
from typing_extensions import get_args

from ._types import NotGiven, not_given
from ._types import NotGiven, ArrayFormat, NestedFormat, not_given
from ._utils import flatten

_T = TypeVar("_T")


ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]

PrimitiveData = Union[str, int, float, bool, None]
# this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"]
# https://github.com/microsoft/pyright/issues/3555
Expand Down
3 changes: 3 additions & 0 deletions src/tabstack/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
ModelT = TypeVar("ModelT", bound=pydantic.BaseModel)
_T = TypeVar("_T")

ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]


# Approximates httpx internal ProxiesTypes and RequestFiles types
# while adding support for `PathLike` instances
Expand Down
42 changes: 34 additions & 8 deletions src/tabstack/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
)
from pathlib import Path
from datetime import date, datetime
from typing_extensions import TypeGuard
from typing_extensions import TypeGuard, get_args

import sniffio

from .._types import Omit, NotGiven, FileTypes, HeadersLike
from .._types import Omit, NotGiven, FileTypes, ArrayFormat, HeadersLike

_T = TypeVar("_T")
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
Expand All @@ -40,25 +40,45 @@ def extract_files(
query: Mapping[str, object],
*,
paths: Sequence[Sequence[str]],
array_format: ArrayFormat = "brackets",
) -> list[tuple[str, FileTypes]]:
"""Recursively extract files from the given dictionary based on specified paths.

A path may look like this ['foo', 'files', '<array>', 'data'].

``array_format`` controls how ``<array>`` segments contribute to the emitted
field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and
``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``).

Note: this mutates the given dictionary.
"""
files: list[tuple[str, FileTypes]] = []
for path in paths:
files.extend(_extract_items(query, path, index=0, flattened_key=None))
files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format))
return files


def _array_suffix(array_format: ArrayFormat, array_index: int) -> str:
if array_format == "brackets":
return "[]"
if array_format == "indices":
return f"[{array_index}]"
if array_format == "repeat" or array_format == "comma":
# Both repeat the bare field name for each file part; there is no
# meaningful way to comma-join binary parts.
return ""
raise NotImplementedError(
f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
)


def _extract_items(
obj: object,
path: Sequence[str],
*,
index: int,
flattened_key: str | None,
array_format: ArrayFormat,
) -> list[tuple[str, FileTypes]]:
try:
key = path[index]
Expand All @@ -75,9 +95,11 @@ def _extract_items(

if is_list(obj):
files: list[tuple[str, FileTypes]] = []
for entry in obj:
assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "")
files.append((flattened_key + "[]", cast(FileTypes, entry)))
for array_index, entry in enumerate(obj):
suffix = _array_suffix(array_format, array_index)
emitted_key = (flattened_key + suffix) if flattened_key else suffix
assert_is_file_content(entry, key=emitted_key)
files.append((emitted_key, cast(FileTypes, entry)))
return files

assert_is_file_content(obj, key=flattened_key)
Expand Down Expand Up @@ -106,6 +128,7 @@ def _extract_items(
path,
index=index,
flattened_key=flattened_key,
array_format=array_format,
)
elif is_list(obj):
if key != "<array>":
Expand All @@ -117,9 +140,12 @@ def _extract_items(
item,
path,
index=index,
flattened_key=flattened_key + "[]" if flattened_key is not None else "[]",
flattened_key=(
(flattened_key if flattened_key is not None else "") + _array_suffix(array_format, array_index)
),
array_format=array_format,
)
for item in obj
for array_index, item in enumerate(obj)
]
)

Expand Down
2 changes: 1 addition & 1 deletion src/tabstack/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "tabstack"
__version__ = "2.6.0" # x-release-please-version
__version__ = "2.6.1" # x-release-please-version
16 changes: 13 additions & 3 deletions src/tabstack/resources/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ..types import agent_automate_params, agent_research_params, agent_automate_input_params
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from .._utils import path_template, maybe_transform, async_maybe_transform
from .._utils import is_given, path_template, maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
Expand All @@ -18,11 +18,13 @@
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from .._constants import DEFAULT_TIMEOUT
from .._streaming import Stream, AsyncStream
from .._base_client import make_request_options
from ..types.automate_event import AutomateEvent
from ..types.research_event import ResearchEvent
from ..types.agent_automate_input_response import AgentAutomateInputResponse
from ..types.shared_params.geotarget_geo_target import GeotargetGeoTarget

__all__ = ["AgentResource", "AsyncAgentResource"]

Expand Down Expand Up @@ -52,7 +54,7 @@ def automate(
*,
task: str,
data: object | Omit = omit,
geo_target: agent_automate_params.GeoTarget | Omit = omit,
geo_target: GeotargetGeoTarget | Omit = omit,
guardrails: str | Omit = omit,
interactive: bool | Omit = omit,
max_iterations: int | Omit = omit,
Expand Down Expand Up @@ -112,6 +114,8 @@ def automate(

timeout: Override the client-level default timeout for this request, in seconds
"""
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
return self._post(
"/automate",
Expand Down Expand Up @@ -250,6 +254,8 @@ def research(

timeout: Override the client-level default timeout for this request, in seconds
"""
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
return self._post(
"/research",
Expand Down Expand Up @@ -300,7 +306,7 @@ async def automate(
*,
task: str,
data: object | Omit = omit,
geo_target: agent_automate_params.GeoTarget | Omit = omit,
geo_target: GeotargetGeoTarget | Omit = omit,
guardrails: str | Omit = omit,
interactive: bool | Omit = omit,
max_iterations: int | Omit = omit,
Expand Down Expand Up @@ -360,6 +366,8 @@ async def automate(

timeout: Override the client-level default timeout for this request, in seconds
"""
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
return await self._post(
"/automate",
Expand Down Expand Up @@ -498,6 +506,8 @@ async def research(

timeout: Override the client-level default timeout for this request, in seconds
"""
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
return await self._post(
"/research",
Expand Down
Loading
Loading