From 9407dabf712ebaec8a26c8440108dae45a67dd74 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Fri, 24 Jan 2025 15:50:49 +0100 Subject: [PATCH] Auto-infer to text/plain --- libs/langgraph-cli/src/server.mts | 15 +++++++++++++++ libs/langgraph-cli/tests/api.test.mts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/langgraph-cli/src/server.mts b/libs/langgraph-cli/src/server.mts index ff512de..db2f307 100644 --- a/libs/langgraph-cli/src/server.mts +++ b/libs/langgraph-cli/src/server.mts @@ -18,6 +18,21 @@ import { store as graphStore } from "./storage/store.mjs"; const app = new Hono(); +// This is used to match the behavior of the original LangGraph API +// where the content-type is not being validated. Might be nice +// to warn about this in the future and throw an error instead. +app.use(async (c, next) => { + if ( + c.req.header("content-type")?.startsWith("text/plain") && + c.req.method !== "GET" && + c.req.method !== "OPTIONS" + ) { + c.req.raw.headers.set("content-type", "application/json"); + } + + await next(); +}); + app.use(cors()); app.use(requestLogger()); diff --git a/libs/langgraph-cli/tests/api.test.mts b/libs/langgraph-cli/tests/api.test.mts index 1eee494..1afc0b8 100644 --- a/libs/langgraph-cli/tests/api.test.mts +++ b/libs/langgraph-cli/tests/api.test.mts @@ -2240,7 +2240,7 @@ describe("multitasking", () => { }); }); -describe.only("RemoteGraph", () => { +describe("RemoteGraph", () => { it.concurrent("stream values", async () => { const graph = new RemoteGraph({ graphId: "agent",