mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-22 09:35:07 +02:00
feat(sdk-js): export more useStream types, allow loopback clients using globals
This commit is contained in:
@@ -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,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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
export { useStream, type MessageMetadata } from "./stream.js";
|
||||
export {
|
||||
useStream,
|
||||
type MessageMetadata,
|
||||
type UseStream,
|
||||
type UseStreamOptions,
|
||||
} from "./stream.js";
|
||||
|
||||
@@ -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,
|
||||
> {
|
||||
|
||||
Reference in New Issue
Block a user