Skip to content

Commit

Permalink
Merge branch 'main' into wfh/cli_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Oct 29, 2024
2 parents 279611a + 90195af commit 21777ff
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libs/sdk-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langchain/langgraph-sdk",
"version": "0.0.18",
"version": "0.0.19",
"description": "Client library for interacting with the LangGraph API",
"type": "module",
"packageManager": "[email protected]",
Expand Down
17 changes: 16 additions & 1 deletion libs/sdk-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,27 @@ export class RunsClient extends BaseClient {
};
const endpoint =
threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
return this.fetch<ThreadState["values"]>(endpoint, {
const response = await this.fetch<ThreadState["values"]>(endpoint, {
method: "POST",
json,
timeoutMs: null,
signal: payload?.signal,
});
const raiseError =
payload?.raiseError !== undefined ? payload.raiseError : true;
if (
raiseError &&
"__error__" in response &&
typeof response.__error__ === "object" &&
response.__error__ &&
"error" in response.__error__ &&
"message" in response.__error__
) {
throw new Error(
`${response.__error__?.error}: ${response.__error__?.message}`,
);
}
return response;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion libs/sdk-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,9 @@ export interface CronsCreatePayload extends RunsCreatePayload {
schedule: string;
}

export type RunsWaitPayload = RunsStreamPayload;
export interface RunsWaitPayload extends RunsStreamPayload {
/**
* Raise errors returned by the run. Default is `true`.
*/
raiseError?: boolean;
}
19 changes: 16 additions & 3 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_client(
client = httpx.AsyncClient(
base_url=url,
transport=transport,
timeout=httpx.Timeout(connect=5, read=60, write=60, pool=5),
timeout=httpx.Timeout(connect=5, read=300, write=300, pool=5),
headers=get_headers(api_key, headers),
)
return LangGraphClient(client)
Expand Down Expand Up @@ -1515,6 +1515,7 @@ async def wait(
multitask_strategy: Optional[MultitaskStrategy] = None,
if_not_exists: Optional[IfNotExists] = None,
after_seconds: Optional[int] = None,
raise_error: bool = True,
) -> Union[list[dict], dict[str, Any]]: ...

@overload
Expand All @@ -1533,6 +1534,7 @@ async def wait(
on_completion: Optional[OnCompletionBehavior] = None,
if_not_exists: Optional[IfNotExists] = None,
after_seconds: Optional[int] = None,
raise_error: bool = True,
) -> Union[list[dict], dict[str, Any]]: ...

async def wait(
Expand All @@ -1553,6 +1555,7 @@ async def wait(
multitask_strategy: Optional[MultitaskStrategy] = None,
if_not_exists: Optional[IfNotExists] = None,
after_seconds: Optional[int] = None,
raise_error: bool = True,
) -> Union[list[dict], dict[str, Any]]:
"""Create a run, wait until it finishes and return the final state.
Expand Down Expand Up @@ -1645,9 +1648,19 @@ async def wait(
endpoint = (
f"/threads/{thread_id}/runs/wait" if thread_id is not None else "/runs/wait"
)
return await self.http.post(
response = await self.http.post(
endpoint, json={k: v for k, v in payload.items() if v is not None}
)
if (
raise_error
and isinstance(response, dict)
and "__error__" in response
and isinstance(response["__error__"], dict)
):
raise Exception(
f"{response['__error__'].get('error')}: {response['__error__'].get('message')}"
)
return response

async def list(
self, thread_id: str, *, limit: int = 10, offset: int = 0
Expand Down Expand Up @@ -2260,7 +2273,7 @@ def get_sync_client(
client = httpx.Client(
base_url=url,
transport=transport,
timeout=httpx.Timeout(connect=5, read=60, write=60, pool=5),
timeout=httpx.Timeout(connect=5, read=300, write=300, pool=5),
headers=get_headers(api_key, headers),
)
return SyncLangGraphClient(client)
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-sdk"
version = "0.1.34"
version = "0.1.35"
description = "SDK for interacting with LangGraph API"
authors = []
license = "MIT"
Expand Down

0 comments on commit 21777ff

Please sign in to comment.