The open-source agent harness - the runtime layer that turns an LLM into a working agent.
chore: Upgrade fern generators (#939)
Chirag Jain0d15e65ebfc1
diff --git a/.github/fern/fern.config.json b/.github/fern/fern.config.jsonindex 8c4c1cf30..6197fdb90 100644--- a/.github/fern/fern.config.json+++ b/.github/fern/fern.config.json@@ -1,4 +1,4 @@{"organization": "truefoundry",- "version": "5.121.1"+ "version": "5.143.4"}diff --git a/.github/fern/generators.yml b/.github/fern/generators.ymlindex edd459b41..1ae2a2b1d 100644--- a/.github/fern/generators.yml+++ b/.github/fern/generators.yml@@ -4,8 +4,8 @@readme:apiName: TrueForgeintroduction: >- API client for the TrueForge Agent Harness Server: a self-hosted- runtime that executes agent turns and streams them over Server-Sent Events.+ API client for the TrueForge Agent Harness Server: a self-hosted runtime+ that executes agent turns and streams them over Server-Sent Events.When auth is enabled on the server, pass an ID token via the optional@@ -37,7 +37,7 @@ groups:ts-sdk:generators:- name: fernapi/fern-typescript-node-sdk- version: 3.91.0+ version: 3.98.3output:location: local-file-systempath: ../../packages/trueforge-sdk@@ -104,7 +104,7 @@ groups:python-sdk:generators:- name: fernapi/fern-python-sdk- version: 5.29.0+ version: 5.34.2output:location: local-file-systempath: ../../python/trueforge_sdkdiff --git a/packages/trueforge-sdk/README.md b/packages/trueforge-sdk/README.mdindex ccf12a982..d5b8e8edd 100644--- a/packages/trueforge-sdk/README.md+++ b/packages/trueforge-sdk/README.md@@ -514,7 +514,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.agents.list();while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying responsediff --git a/packages/trueforge-sdk/reference.md b/packages/trueforge-sdk/reference.mdindex 915278f14..57c6aa278 100644--- a/packages/trueforge-sdk/reference.md+++ b/packages/trueforge-sdk/reference.md@@ -102,7 +102,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.agents.list();while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying response@@ -936,7 +936,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.sandboxEnvironments.list();while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying response@@ -1205,7 +1205,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.schedules.list();while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying response@@ -1618,7 +1618,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.schedules.listRuns("schedule_id");while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying response@@ -1702,7 +1702,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.sessions.list();while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying response@@ -2112,7 +2112,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.sessions.listEvents("session_id");while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying response@@ -2195,7 +2195,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.sessions.listTurns("session_id");while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying response@@ -2583,7 +2583,7 @@ for await (const item of pageableResponse) {// Or you can manually iterate page-by-pagelet page = await client.sessions.listTurnEvents("session_id", "turn_id");while (page.hasNextPage()) {- page = page.getNextPage();+ page = await page.getNextPage();}// You can also access the underlying responsediff --git a/packages/trueforge-sdk/tests/mock-server/withJson.ts b/packages/trueforge-sdk/tests/mock-server/withJson.tsindex 3e8800a0c..b0e6d920d 100644--- a/packages/trueforge-sdk/tests/mock-server/withJson.ts+++ b/packages/trueforge-sdk/tests/mock-server/withJson.ts@@ -42,7 +42,9 @@ export function withJson(}const mismatches = findMismatches(actualBody, expectedBody);- const filteredMismatches = Object.keys(mismatches).filter((key) => !ignoredFields.includes(key));+ const filteredMismatches = Object.entries(mismatches).filter(+ ([key, mismatch]) => !isIgnoredMismatch(key, mismatch, ignoredFields),+ );if (filteredMismatches.length > 0) {console.error("JSON body mismatch:", toJson(mismatches, undefined, 2));return passthrough();@@ -52,6 +54,47 @@ export function withJson(};}+/**+ * A mismatch is ignored when its path is listed in ignoredFields, or when it is an object+ * that is absent from the expected body and every leaf inside it is listed in ignoredFields.+ * The latter happens when an ignored field is nested (e.g. "options.offset") and the client+ * creates the parent object to hold the next page value.+ */+function isIgnoredMismatch(+ key: string,+ mismatch: { actual: unknown; expected: unknown },+ ignoredFields: string[],+): boolean {+ if (ignoredFields.includes(key)) {+ return true;+ }+ if (mismatch.expected !== undefined || !isPlainObject(mismatch.actual)) {+ return false;+ }+ const leafPaths = collectLeafPaths(mismatch.actual, key);+ return leafPaths.length > 0 && leafPaths.every((path) => ignoredFields.includes(path));+}++function isPlainObject(value: unknown): value is Record<string, unknown> {+ return typeof value === "object" && value !== null && !Array.isArray(value);+}++function collectLeafPaths(value: Record<string, unknown>, prefix: string): string[] {+ const paths: string[] = [];+ for (const [key, child] of Object.entries(value)) {+ if (child === undefined) {+ continue;+ }+ const path = `${prefix}.${key}`;+ if (isPlainObject(child)) {+ paths.push(...collectLeafPaths(child, path));+ } else {+ paths.push(path);+ }+ }+ return paths;+}+function findMismatches(actual: any, expected: any): Record<string, { actual: any; expected: any }> {const mismatches: Record<string, { actual: any; expected: any }> = {};diff --git a/python/trueforge_sdk/pyproject.toml b/python/trueforge_sdk/pyproject.tomlindex f1965a3f3..dcbd0cb66 100644--- a/python/trueforge_sdk/pyproject.toml+++ b/python/trueforge_sdk/pyproject.toml@@ -9,7 +9,6 @@ description = ""readme = "README.md"authors = []keywords = []-classifiers = ["Intended Audience :: Developers","Programming Language :: Python",diff --git a/python/trueforge_sdk/src/trueforge_sdk/core/client_wrapper.py b/python/trueforge_sdk/src/trueforge_sdk/core/client_wrapper.pyindex 4e5dbbb1a..60720071a 100644--- a/python/trueforge_sdk/src/trueforge_sdk/core/client_wrapper.py+++ b/python/trueforge_sdk/src/trueforge_sdk/core/client_wrapper.py@@ -29,7 +29,7 @@ class BaseClientWrapper:self._max_stream_reconnection_attempts = max_stream_reconnection_attemptsself._logging = logging- def get_headers(self) -> typing.Dict[str, str]:+ def get_headers(self, *, include_token: bool = True) -> typing.Dict[str, str]:import platformheaders: typing.Dict[str, str] = {@@ -41,9 +41,10 @@ class BaseClientWrapper:"X-Fern-SDK-Version": "0.0.0",**(self.get_custom_headers() or {}),}- token = self._get_token()- if token is not None:- headers["Authorization"] = f"Bearer {token}"+ if include_token:+ token = self._get_token()+ if token is not None:+ headers["Authorization"] = f"Bearer {token}"return headersdef _get_token(self) -> typing.Optional[str]:@@ -142,7 +143,7 @@ class AsyncClientWrapper(BaseClientWrapper):)async def async_get_headers(self) -> typing.Dict[str, str]:- headers = self.get_headers()+ headers = self.get_headers(include_token=self._async_token is None)if self._async_token is not None:token = await self._async_token()headers["Authorization"] = f"Bearer {token}"diff --git a/python/trueforge_sdk/src/trueforge_sdk/core/pydantic_utilities.py b/python/trueforge_sdk/src/trueforge_sdk/core/pydantic_utilities.pyindex 6587f5e18..70816b99f 100644--- a/python/trueforge_sdk/src/trueforge_sdk/core/pydantic_utilities.py+++ b/python/trueforge_sdk/src/trueforge_sdk/core/pydantic_utilities.py@@ -5,6 +5,7 @@ import datetime as dtimport inspectimport jsonimport logging+import weakreffrom collections import defaultdictfrom dataclasses import asdictfrom typing import (@@ -184,6 +185,58 @@ def _get_type_adapter(type_: Type[Any]) -> Any:return adapter+_field_alias_cache: "weakref.WeakKeyDictionary[type, Tuple[Dict[str, str], Tuple[str, ...]]]" = (+ weakref.WeakKeyDictionary()+)+++def _get_field_aliases(model: type) -> Tuple[Dict[str, str], Tuple[str, ...]]:+ """+ Map of field name to Pydantic alias for the fields whose alias differs from their name, together with the+ keys that are ambiguous (an alias of one field and the name of another). Computed once per model class.+ """+ cached = _field_alias_cache.get(model)+ if cached is None:+ fields: Mapping[str, Any] = (+ getattr(model, "model_fields", {}) if IS_PYDANTIC_V2 else getattr(model, "__fields__", {})+ )+ name_to_alias: Dict[str, str] = {}+ for name, field in fields.items():+ alias = getattr(field, "alias", None)+ if alias is not None and alias != name:+ name_to_alias[name] = alias+ cached = (name_to_alias, tuple(alias for alias in name_to_alias.values() if alias in fields))+ _field_alias_cache[model] = cached+ return cached+++def _coerce_keys_to_aliases(model: type, data: Any) -> Any:+ """+ Accept Python field names in input by rewriting them to their Pydantic aliases,+ while avoiding silent collisions when a key could refer to multiple fields.+ """+ if not isinstance(data, Mapping):+ return data++ name_to_alias, ambiguous_keys = _get_field_aliases(model)+ for key in ambiguous_keys:+ if key in data and name_to_alias.get(key, key) not in data:+ raise ValueError(+ f"Ambiguous input key '{key}': it is both a field name and an alias. "+ "Provide the explicit alias key to disambiguate."+ )++ if not name_to_alias or not any(name in data for name in name_to_alias):+ return data if isinstance(data, dict) else dict(data)++ rewritten: Dict[str, Any] = dict(data)+ for name, alias in name_to_alias.items():+ if name in data and alias not in rewritten:+ rewritten[alias] = rewritten.pop(name)++ return rewritten++def parse_obj_as(type_: Type[T], object_: Any) -> T:# convert_and_respect_annotation_metadata is required for TypedDict aliasing.#@@ -193,20 +246,7 @@ def parse_obj_as(type_: Type[T], object_: Any) -> T:# - If the model encodes aliasing only via FieldMetadata annotations, then we MUST pre-dealias because Pydantic# will not recognize those aliases during validation.if inspect.isclass(type_) and issubclass(type_, pydantic.BaseModel):- has_pydantic_aliases = False- if IS_PYDANTIC_V2:- for field_name, field_info in getattr(type_, "model_fields", {}).items(): # type: ignore[attr-defined]- alias = getattr(field_info, "alias", None)- if alias is not None and alias != field_name:- has_pydantic_aliases = True- break- else:- for field in getattr(type_, "__fields__", {}).values():- alias = getattr(field, "alias", None)- name = getattr(field, "name", None)- if alias is not None and name is not None and alias != name:- has_pydantic_aliases = True- break+ has_pydantic_aliases = bool(_get_field_aliases(type_)[0])dealiased_object = (object_@@ -239,39 +279,7 @@ class UniversalBaseModel(pydantic.BaseModel):@pydantic.model_validator(mode="before") # type: ignore[attr-defined]@classmethoddef _coerce_field_names_to_aliases(cls, data: Any) -> Any:- """- Accept Python field names in input by rewriting them to their Pydantic aliases,- while avoiding silent collisions when a key could refer to multiple fields.- """- if not isinstance(data, Mapping):- return data-- fields = getattr(cls, "model_fields", {}) # type: ignore[attr-defined]- name_to_alias: Dict[str, str] = {}- alias_to_name: Dict[str, str] = {}-- for name, field_info in fields.items():- alias = getattr(field_info, "alias", None) or name- name_to_alias[name] = alias- if alias != name:- alias_to_name[alias] = name-- # Detect ambiguous keys: a key that is an alias for one field and a name for another.- ambiguous_keys = set(alias_to_name.keys()).intersection(set(name_to_alias.keys()))- for key in ambiguous_keys:- if key in data and name_to_alias[key] not in data:- raise ValueError(- f"Ambiguous input key '{key}': it is both a field name and an alias. "- "Provide the explicit alias key to disambiguate."- )-- original_keys = set(data.keys())- rewritten: Dict[str, Any] = dict(data)- for name, alias in name_to_alias.items():- if alias != name and name in original_keys and alias not in rewritten:- rewritten[alias] = rewritten.pop(name)-- return rewritten+ return _coerce_keys_to_aliases(cls, data)@pydantic.model_serializer(mode="plain", when_used="json") # type: ignore[attr-defined]def serialize_model(self) -> Any: # type: ignore[name-defined]@@ -287,37 +295,7 @@ class UniversalBaseModel(pydantic.BaseModel):@pydantic.root_validator(pre=True)def _coerce_field_names_to_aliases(cls, values: Any) -> Any:- """- Pydantic v1 equivalent of _coerce_field_names_to_aliases.- """- if not isinstance(values, Mapping):- return values-- fields = getattr(cls, "__fields__", {})- name_to_alias: Dict[str, str] = {}- alias_to_name: Dict[str, str] = {}-- for name, field in fields.items():- alias = getattr(field, "alias", None) or name- name_to_alias[name] = alias- if alias != name:- alias_to_name[alias] = name-- ambiguous_keys = set(alias_to_name.keys()).intersection(set(name_to_alias.keys()))- for key in ambiguous_keys:- if key in values and name_to_alias[key] not in values:- raise ValueError(- f"Ambiguous input key '{key}': it is both a field name and an alias. "- "Provide the explicit alias key to disambiguate."- )-- original_keys = set(values.keys())- rewritten: Dict[str, Any] = dict(values)- for name, alias in name_to_alias.items():- if alias != name and name in original_keys and alias not in rewritten:- rewritten[alias] = rewritten.pop(name)-- return rewritten+ return _coerce_keys_to_aliases(cls, values) # type: ignore[arg-type]@classmethoddef model_construct(cls: Type["Model"], _fields_set: Optional[Set[str]] = None, **values: Any) -> "Model":