@langchain/langgraph-sdk 0.0.9 → 0.0.10-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/client.d.ts +1 -1
  2. package/client.js +1 -1
  3. package/dist/client.cjs +677 -0
  4. package/dist/{client.d.mts → client.d.ts} +2 -2
  5. package/dist/{client.mjs → client.js} +3 -3
  6. package/dist/index.cjs +5 -0
  7. package/dist/{index.d.mts → index.d.ts} +1 -1
  8. package/dist/index.js +1 -0
  9. package/dist/types.cjs +2 -0
  10. package/dist/utils/async_caller.cjs +195 -0
  11. package/dist/utils/eventsource-parser/index.cjs +7 -0
  12. package/dist/utils/eventsource-parser/index.d.ts +2 -0
  13. package/dist/utils/eventsource-parser/index.js +3 -0
  14. package/dist/utils/eventsource-parser/parse.cjs +150 -0
  15. package/dist/utils/eventsource-parser/parse.d.ts +18 -0
  16. package/dist/utils/eventsource-parser/parse.js +146 -0
  17. package/dist/utils/eventsource-parser/stream.cjs +34 -0
  18. package/dist/utils/eventsource-parser/stream.d.ts +17 -0
  19. package/dist/utils/eventsource-parser/stream.js +30 -0
  20. package/dist/utils/eventsource-parser/types.cjs +2 -0
  21. package/dist/utils/eventsource-parser/types.d.ts +81 -0
  22. package/dist/utils/eventsource-parser/types.js +1 -0
  23. package/dist/utils/stream.cjs +115 -0
  24. package/dist/utils/{stream.d.mts → stream.d.ts} +1 -0
  25. package/dist/utils/{stream.mjs → stream.js} +5 -0
  26. package/index.d.ts +1 -1
  27. package/index.js +1 -1
  28. package/package.json +1 -2
  29. package/dist/index.mjs +0 -1
  30. /package/dist/{types.d.mts → types.d.ts} +0 -0
  31. /package/dist/{types.mjs → types.js} +0 -0
  32. /package/dist/utils/{async_caller.d.mts → async_caller.d.ts} +0 -0
  33. /package/dist/utils/{async_caller.mjs → async_caller.js} +0 -0
@@ -0,0 +1,81 @@
1
+ /**
2
+ * EventSource parser instance.
3
+ *
4
+ * Needs to be reset between reconnections/when switching data source, using the `reset()` method.
5
+ *
6
+ * @public
7
+ */
8
+ export interface EventSourceParser {
9
+ /**
10
+ * Feeds the parser another chunk. The method _does not_ return a parsed message.
11
+ * Instead, if the chunk was a complete message (or completed a previously incomplete message),
12
+ * it will invoke the `onParse` callback used to create the parsers.
13
+ *
14
+ * @param chunk - The chunk to parse. Can be a partial, eg in the case of streaming messages.
15
+ * @public
16
+ */
17
+ feed(chunk: string): void;
18
+ /**
19
+ * Resets the parser state. This is required when you have a new stream of messages -
20
+ * for instance in the case of a client being disconnected and reconnecting.
21
+ *
22
+ * @public
23
+ */
24
+ reset(): void;
25
+ }
26
+ /**
27
+ * A parsed EventSource event
28
+ *
29
+ * @public
30
+ */
31
+ export interface ParsedEvent {
32
+ /**
33
+ * Differentiates the type from reconnection intervals and other types of messages
34
+ * Not to be confused with `event`.
35
+ */
36
+ type: "event";
37
+ /**
38
+ * The event type sent from the server. Note that this differs from the browser `EventSource`
39
+ * implementation in that browsers will default this to `message`, whereas this parser will
40
+ * leave this as `undefined` if not explicitly declared.
41
+ */
42
+ event?: string;
43
+ /**
44
+ * ID of the message, if any was provided by the server. Can be used by clients to keep the
45
+ * last received message ID in sync when reconnecting.
46
+ */
47
+ id?: string;
48
+ /**
49
+ * The data received for this message
50
+ */
51
+ data: string;
52
+ }
53
+ /**
54
+ * An event emitted from the parser when the server sends a value in the `retry` field,
55
+ * indicating how many seconds the client should wait before attempting to reconnect.
56
+ *
57
+ * @public
58
+ */
59
+ export interface ReconnectInterval {
60
+ /**
61
+ * Differentiates the type from `event` and other types of messages
62
+ */
63
+ type: "reconnect-interval";
64
+ /**
65
+ * Number of seconds to wait before reconnecting. Note that the parser does not care about
66
+ * this value at all - it only emits the value for clients to use.
67
+ */
68
+ value: number;
69
+ }
70
+ /**
71
+ * The different types of messages the parsed can emit to the `onParse` callback
72
+ *
73
+ * @public
74
+ */
75
+ export type ParseEvent = ParsedEvent | ReconnectInterval;
76
+ /**
77
+ * Callback passed as the `onParse` callback to a parser
78
+ *
79
+ * @public
80
+ */
81
+ export type EventSourceParseCallback = (event: ParseEvent) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IterableReadableStream = void 0;
4
+ /*
5
+ * Support async iterator syntax for ReadableStreams in all environments.
6
+ * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
7
+ */
8
+ class IterableReadableStream extends ReadableStream {
9
+ constructor() {
10
+ super(...arguments);
11
+ Object.defineProperty(this, "reader", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ }
18
+ ensureReader() {
19
+ if (!this.reader) {
20
+ this.reader = this.getReader();
21
+ }
22
+ }
23
+ async next() {
24
+ this.ensureReader();
25
+ try {
26
+ const result = await this.reader.read();
27
+ if (result.done) {
28
+ this.reader.releaseLock(); // release lock when stream becomes closed
29
+ return {
30
+ done: true,
31
+ value: undefined,
32
+ };
33
+ }
34
+ else {
35
+ return {
36
+ done: false,
37
+ value: result.value,
38
+ };
39
+ }
40
+ }
41
+ catch (e) {
42
+ this.reader.releaseLock(); // release lock when stream becomes errored
43
+ throw e;
44
+ }
45
+ }
46
+ async return() {
47
+ this.ensureReader();
48
+ // If wrapped in a Node stream, cancel is already called.
49
+ if (this.locked) {
50
+ const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
51
+ this.reader.releaseLock(); // release lock first
52
+ await cancelPromise; // now await it
53
+ }
54
+ return { done: true, value: undefined };
55
+ }
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ async throw(e) {
58
+ this.ensureReader();
59
+ if (this.locked) {
60
+ const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
61
+ this.reader.releaseLock(); // release lock first
62
+ await cancelPromise; // now await it
63
+ }
64
+ throw e;
65
+ }
66
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
68
+ async [Symbol.asyncDispose]() {
69
+ await this.return();
70
+ }
71
+ [Symbol.asyncIterator]() {
72
+ return this;
73
+ }
74
+ static fromReadableStream(stream) {
75
+ // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream
76
+ const reader = stream.getReader();
77
+ return new IterableReadableStream({
78
+ start(controller) {
79
+ return pump();
80
+ function pump() {
81
+ return reader.read().then(({ done, value }) => {
82
+ // When no more data needs to be consumed, close the stream
83
+ if (done) {
84
+ controller.close();
85
+ return;
86
+ }
87
+ // Enqueue the next data chunk into our target stream
88
+ controller.enqueue(value);
89
+ return pump();
90
+ });
91
+ }
92
+ },
93
+ cancel() {
94
+ reader.releaseLock();
95
+ },
96
+ });
97
+ }
98
+ static fromAsyncGenerator(generator) {
99
+ return new IterableReadableStream({
100
+ async pull(controller) {
101
+ const { value, done } = await generator.next();
102
+ // When no more data needs to be consumed, close the stream
103
+ if (done) {
104
+ controller.close();
105
+ }
106
+ // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled
107
+ controller.enqueue(value);
108
+ },
109
+ async cancel(reason) {
110
+ await generator.return(reason);
111
+ },
112
+ });
113
+ }
114
+ }
115
+ exports.IterableReadableStream = IterableReadableStream;
@@ -5,6 +5,7 @@ export declare class IterableReadableStream<T> extends ReadableStream<T> impleme
5
5
  next(): Promise<IteratorResult<T>>;
6
6
  return(): Promise<IteratorResult<T>>;
7
7
  throw(e: any): Promise<IteratorResult<T>>;
8
+ [Symbol.asyncDispose](): Promise<void>;
8
9
  [Symbol.asyncIterator](): this;
9
10
  static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
10
11
  static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
@@ -60,6 +60,11 @@ export class IterableReadableStream extends ReadableStream {
60
60
  }
61
61
  throw e;
62
62
  }
63
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
64
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
65
+ async [Symbol.asyncDispose]() {
66
+ await this.return();
67
+ }
63
68
  [Symbol.asyncIterator]() {
64
69
  return this;
65
70
  }
package/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/index.mjs'
1
+ export * from './dist/index.js'
package/index.js CHANGED
@@ -1 +1 @@
1
- export * from './dist/index.mjs'
1
+ export * from './dist/index.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.10-rc.0",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",
@@ -17,7 +17,6 @@
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
19
  "@types/json-schema": "^7.0.15",
20
- "eventsource-parser": "^1.1.2",
21
20
  "p-queue": "^6.6.2",
22
21
  "p-retry": "4",
23
22
  "uuid": "^9.0.0"
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- export { Client } from "./client.mjs";
File without changes
File without changes