Merge pull request #1443 from langchain-ai:dqbd/js-sdk-end-event

fix(sdk-js): support sending end events
This commit is contained in:
David Duong
2024-08-23 16:48:02 +02:00
committed by GitHub
3 changed files with 23 additions and 9 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@langchain/langgraph-sdk",
"version": "0.0.5",
"version": "0.0.6",
"description": "Client library for interacting with the LangGraph API",
"type": "module",
"packageManager": "yarn@1.22.19",
+10 -1
View File
@@ -571,6 +571,7 @@ export class RunsClient extends BaseClient {
);
let parser: EventSourceParser;
let onEndEvent: () => void;
const textDecoder = new TextDecoder();
const stream: ReadableStream<{ event: string; data: any }> = (
@@ -594,9 +595,17 @@ export class RunsClient extends BaseClient {
});
}
});
onEndEvent = () => {
ctrl.enqueue({ event: "end", data: undefined });
};
},
async transform(chunk) {
parser.feed(textDecoder.decode(chunk));
const payload = textDecoder.decode(chunk);
parser.feed(payload);
// eventsource-parser will ignore events
// that are not terminated by a newline
if (payload.trim() === "event: end") onEndEvent();
},
}),
);
+12 -7
View File
@@ -2,6 +2,16 @@ import type { JSONSchema7 } from "json-schema";
type Optional<T> = T | null | undefined;
type RunStatus =
| "pending"
| "running"
| "error"
| "success"
| "timeout"
| "interrupted";
type ThreadStatus = "idle" | "busy" | "interrupted";
export interface Config {
/**
* Tags for this call and any sub-calls (eg. a Chain calling an LLM).
@@ -80,6 +90,7 @@ export interface Thread {
created_at: string;
updated_at: string;
metadata: Metadata;
status: ThreadStatus;
}
export interface Cron {
@@ -112,12 +123,6 @@ export interface Run {
assistant_id: string;
created_at: string;
updated_at: string;
status:
| "pending"
| "running"
| "error"
| "success"
| "timeout"
| "interrupted";
status: RunStatus;
metadata: Metadata;
}