feat(sdk-js): export more useStream types, allow loopback clients using globals

This commit is contained in:
Tat Dat Duong
2025-04-16 17:10:44 +02:00
parent 07ba931105
commit ecb15acb80
5 changed files with 30 additions and 10 deletions
-4
View File
@@ -8,10 +8,6 @@ Defining a custom app object lets you add any routes you'd like, so you can do a
Below is an example using FastAPI.
???+ note "Python only"
We currently only support custom authentication and authorization in Python deployments with `langgraph-api>=0.0.26`.
## Create app
Starting from an **existing** LangGraph Platform application, add the following custom route code to your `webapp.py` file. If you are starting from scratch, you can create a new app from a template using the CLI.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@langchain/langgraph-sdk",
"version": "0.0.66",
"version": "0.0.67",
"description": "Client library for interacting with the LangGraph API",
"type": "module",
"packageManager": "yarn@1.22.19",
+22 -3
View File
@@ -84,18 +84,37 @@ class BaseClient {
protected defaultHeaders: Record<string, string | null | undefined>;
constructor(config?: ClientConfig) {
this.asyncCaller = new AsyncCaller({
const callerOptions = {
maxRetries: 4,
maxConcurrency: 4,
...config?.callerOptions,
});
};
let defaultApiUrl = "http://localhost:8123";
if (
!config?.apiUrl &&
typeof globalThis === "object" &&
globalThis != null
) {
const fetchSmb = Symbol.for("langgraph_api:fetch");
const urlSmb = Symbol.for("langgraph_api:url");
const global = globalThis as unknown as {
[fetchSmb]?: typeof fetch;
[urlSmb]?: string;
};
if (global[fetchSmb]) callerOptions.fetch ??= global[fetchSmb];
if (global[urlSmb]) defaultApiUrl = global[urlSmb];
}
this.asyncCaller = new AsyncCaller(callerOptions);
this.timeoutMs = config?.timeoutMs;
// default limit being capped by Chrome
// https://github.com/nodejs/undici/issues/1373
// Regex to remove trailing slash, if present
this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || "http://localhost:8123";
this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
this.defaultHeaders = config?.defaultHeaders || {};
const apiKey = getApiKey(config?.apiKey);
if (apiKey) {
+6 -1
View File
@@ -1 +1,6 @@
export { useStream, type MessageMetadata } from "./stream.js";
export {
useStream,
type MessageMetadata,
type UseStream,
type UseStreamOptions,
} from "./stream.js";
+1 -1
View File
@@ -405,7 +405,7 @@ type GetCustomEventType<Bag extends BagTemplate> = Bag extends {
? Bag["CustomEventType"]
: unknown;
interface UseStreamOptions<
export interface UseStreamOptions<
StateType extends Record<string, unknown> = Record<string, unknown>,
Bag extends BagTemplate = BagTemplate,
> {