@langchain/langgraph 1.2.8 → 1.3.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.
- package/dist/graph/graph.cjs +6 -2
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.d.cts +58 -7
- package/dist/graph/graph.d.cts.map +1 -1
- package/dist/graph/graph.d.ts +58 -7
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/graph/graph.js +6 -2
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/state.cjs +3 -2
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.d.cts +14 -6
- package/dist/graph/state.d.cts.map +1 -1
- package/dist/graph/state.d.ts +14 -6
- package/dist/graph/state.d.ts.map +1 -1
- package/dist/graph/state.js +3 -2
- package/dist/graph/state.js.map +1 -1
- package/dist/index.cjs +34 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -6
- package/dist/index.d.ts +16 -6
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/prebuilt/agent_executor.d.cts +1 -1
- package/dist/prebuilt/agent_executor.d.ts +1 -1
- package/dist/pregel/algo.cjs +6 -3
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.js +6 -3
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/index.cjs +96 -25
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.d.cts +25 -3
- package/dist/pregel/index.d.cts.map +1 -1
- package/dist/pregel/index.d.ts +25 -3
- package/dist/pregel/index.d.ts.map +1 -1
- package/dist/pregel/index.js +97 -26
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +51 -10
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +51 -10
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages-v2.cjs +231 -0
- package/dist/pregel/messages-v2.cjs.map +1 -0
- package/dist/pregel/messages-v2.js +231 -0
- package/dist/pregel/messages-v2.js.map +1 -0
- package/dist/pregel/messages.cjs +14 -10
- package/dist/pregel/messages.cjs.map +1 -1
- package/dist/pregel/messages.js +14 -10
- package/dist/pregel/messages.js.map +1 -1
- package/dist/pregel/remote.cjs +15 -0
- package/dist/pregel/remote.cjs.map +1 -1
- package/dist/pregel/remote.d.cts.map +1 -1
- package/dist/pregel/remote.d.ts.map +1 -1
- package/dist/pregel/remote.js +15 -0
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/stream.cjs.map +1 -1
- package/dist/pregel/stream.d.cts +30 -0
- package/dist/pregel/stream.d.cts.map +1 -0
- package/dist/pregel/stream.d.ts +30 -1
- package/dist/pregel/stream.d.ts.map +1 -0
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/types.cjs.map +1 -1
- package/dist/pregel/types.d.cts +8 -1
- package/dist/pregel/types.d.cts.map +1 -1
- package/dist/pregel/types.d.ts +8 -1
- package/dist/pregel/types.d.ts.map +1 -1
- package/dist/pregel/types.js.map +1 -1
- package/dist/pregel/utils/config.cjs +21 -4
- package/dist/pregel/utils/config.cjs.map +1 -1
- package/dist/pregel/utils/config.d.cts.map +1 -1
- package/dist/pregel/utils/config.d.ts.map +1 -1
- package/dist/pregel/utils/config.js +21 -5
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.d.ts +0 -1
- package/dist/pregel/utils/index.d.ts.map +1 -1
- package/dist/state/index.d.ts +1 -1
- package/dist/state/schema.d.cts +1 -1
- package/dist/state/schema.d.ts +1 -1
- package/dist/stream/convert.cjs +207 -0
- package/dist/stream/convert.cjs.map +1 -0
- package/dist/stream/convert.d.cts +69 -0
- package/dist/stream/convert.d.cts.map +1 -0
- package/dist/stream/convert.d.ts +69 -0
- package/dist/stream/convert.d.ts.map +1 -0
- package/dist/stream/convert.js +206 -0
- package/dist/stream/convert.js.map +1 -0
- package/dist/stream/index.cjs +11 -0
- package/dist/stream/index.d.cts +12 -0
- package/dist/stream/index.d.ts +12 -0
- package/dist/stream/index.js +12 -0
- package/dist/stream/mux.cjs +350 -0
- package/dist/stream/mux.cjs.map +1 -0
- package/dist/stream/mux.d.cts +160 -0
- package/dist/stream/mux.d.cts.map +1 -0
- package/dist/stream/mux.d.ts +160 -0
- package/dist/stream/mux.d.ts.map +1 -0
- package/dist/stream/mux.js +345 -0
- package/dist/stream/mux.js.map +1 -0
- package/dist/stream/run-stream.cjs +439 -0
- package/dist/stream/run-stream.cjs.map +1 -0
- package/dist/stream/run-stream.d.cts +286 -0
- package/dist/stream/run-stream.d.cts.map +1 -0
- package/dist/stream/run-stream.d.ts +285 -0
- package/dist/stream/run-stream.d.ts.map +1 -0
- package/dist/stream/run-stream.js +434 -0
- package/dist/stream/run-stream.js.map +1 -0
- package/dist/stream/stream-channel.cjs +208 -0
- package/dist/stream/stream-channel.cjs.map +1 -0
- package/dist/stream/stream-channel.d.cts +129 -0
- package/dist/stream/stream-channel.d.cts.map +1 -0
- package/dist/stream/stream-channel.d.ts +129 -0
- package/dist/stream/stream-channel.d.ts.map +1 -0
- package/dist/stream/stream-channel.js +207 -0
- package/dist/stream/stream-channel.js.map +1 -0
- package/dist/stream/transformers/index.cjs +4 -0
- package/dist/stream/transformers/index.d.ts +5 -0
- package/dist/stream/transformers/index.js +5 -0
- package/dist/stream/transformers/lifecycle.cjs +326 -0
- package/dist/stream/transformers/lifecycle.cjs.map +1 -0
- package/dist/stream/transformers/lifecycle.d.cts +53 -0
- package/dist/stream/transformers/lifecycle.d.cts.map +1 -0
- package/dist/stream/transformers/lifecycle.d.ts +53 -0
- package/dist/stream/transformers/lifecycle.d.ts.map +1 -0
- package/dist/stream/transformers/lifecycle.js +325 -0
- package/dist/stream/transformers/lifecycle.js.map +1 -0
- package/dist/stream/transformers/messages.cjs +94 -0
- package/dist/stream/transformers/messages.cjs.map +1 -0
- package/dist/stream/transformers/messages.d.cts +23 -0
- package/dist/stream/transformers/messages.d.cts.map +1 -0
- package/dist/stream/transformers/messages.d.ts +23 -0
- package/dist/stream/transformers/messages.d.ts.map +1 -0
- package/dist/stream/transformers/messages.js +94 -0
- package/dist/stream/transformers/messages.js.map +1 -0
- package/dist/stream/transformers/subgraphs.cjs +125 -0
- package/dist/stream/transformers/subgraphs.cjs.map +1 -0
- package/dist/stream/transformers/subgraphs.d.cts +95 -0
- package/dist/stream/transformers/subgraphs.d.cts.map +1 -0
- package/dist/stream/transformers/subgraphs.d.ts +95 -0
- package/dist/stream/transformers/subgraphs.d.ts.map +1 -0
- package/dist/stream/transformers/subgraphs.js +124 -0
- package/dist/stream/transformers/subgraphs.js.map +1 -0
- package/dist/stream/transformers/types.d.cts +89 -0
- package/dist/stream/transformers/types.d.cts.map +1 -0
- package/dist/stream/transformers/types.d.ts +89 -0
- package/dist/stream/transformers/types.d.ts.map +1 -0
- package/dist/stream/transformers/values.cjs +39 -0
- package/dist/stream/transformers/values.cjs.map +1 -0
- package/dist/stream/transformers/values.d.cts +21 -0
- package/dist/stream/transformers/values.d.cts.map +1 -0
- package/dist/stream/transformers/values.d.ts +21 -0
- package/dist/stream/transformers/values.d.ts.map +1 -0
- package/dist/stream/transformers/values.js +39 -0
- package/dist/stream/transformers/values.js.map +1 -0
- package/dist/stream/types.cjs +11 -0
- package/dist/stream/types.cjs.map +1 -0
- package/dist/stream/types.d.cts +255 -0
- package/dist/stream/types.d.cts.map +1 -0
- package/dist/stream/types.d.ts +255 -0
- package/dist/stream/types.d.ts.map +1 -0
- package/dist/stream/types.js +11 -0
- package/dist/stream/types.js.map +1 -0
- package/dist/web.cjs +39 -9
- package/dist/web.d.cts +16 -6
- package/dist/web.d.ts +16 -6
- package/dist/web.js +10 -1
- package/package.json +9 -8
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
//#region src/stream/stream-channel.ts
|
|
2
|
+
/**
|
|
3
|
+
* StreamChannel — projection channel for local or remote streaming.
|
|
4
|
+
*
|
|
5
|
+
* A `StreamChannel<T>` is an append-only async stream with independent
|
|
6
|
+
* cursors. Local channels stay in-process only. Remote channels declare a
|
|
7
|
+
* protocol channel name; when registered with a {@link StreamMux} (via a
|
|
8
|
+
* transformer's `init()` return value), every {@link push} is automatically
|
|
9
|
+
* forwarded as a {@link ProtocolEvent} on the named channel — making the data
|
|
10
|
+
* available both in-process (via `run.extensions`) and to remote clients (via
|
|
11
|
+
* `session.subscribe("custom:<channelName>")`).
|
|
12
|
+
*
|
|
13
|
+
* Lifecycle (`close` / `fail`) is managed by the mux automatically;
|
|
14
|
+
* transformers do not need to call them.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Branded symbol placed on every {@link StreamChannel} instance.
|
|
18
|
+
*
|
|
19
|
+
* Uses `Symbol.for` so the same symbol is shared across multiple
|
|
20
|
+
* copies of this package that may coexist in a dependency graph
|
|
21
|
+
* (e.g. when a user app imports `@langchain/langgraph` directly and a
|
|
22
|
+
* wrapping library like `langchain` bundles its own copy). Using a
|
|
23
|
+
* symbol brand instead of `instanceof` lets channels created against
|
|
24
|
+
* one copy of the class be recognised by a mux from another.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
const STREAM_CHANNEL_BRAND = Symbol.for("langgraph.stream_channel");
|
|
28
|
+
/**
|
|
29
|
+
* A projection channel for {@link StreamTransformer}s.
|
|
30
|
+
*
|
|
31
|
+
* Implements `AsyncIterable<T>` so it can be iterated directly by
|
|
32
|
+
* in-process consumers via `run.extensions.<key>`. Channels created with
|
|
33
|
+
* {@link StreamChannel.remote} or `new StreamChannel(name)` are also
|
|
34
|
+
* auto-forwarded to remote clients.
|
|
35
|
+
*
|
|
36
|
+
* @typeParam T - The type of items pushed into the channel.
|
|
37
|
+
*/
|
|
38
|
+
var StreamChannel = class StreamChannel {
|
|
39
|
+
/** @internal Brand used by {@link StreamChannel.isInstance}. */
|
|
40
|
+
[STREAM_CHANNEL_BRAND] = true;
|
|
41
|
+
/** Protocol channel name used for auto-forwarded events, if remote. */
|
|
42
|
+
channelName;
|
|
43
|
+
#items = [];
|
|
44
|
+
#waiters = [];
|
|
45
|
+
#done = false;
|
|
46
|
+
#error;
|
|
47
|
+
#onPush;
|
|
48
|
+
constructor(name) {
|
|
49
|
+
this.channelName = name;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create an in-process-only channel. Values remain available through
|
|
53
|
+
* `run.extensions.<key>` but are not forwarded to remote clients.
|
|
54
|
+
*/
|
|
55
|
+
static local() {
|
|
56
|
+
return new StreamChannel();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a channel whose pushes are forwarded to remote clients under
|
|
60
|
+
* the given protocol channel name.
|
|
61
|
+
*/
|
|
62
|
+
static remote(name) {
|
|
63
|
+
return new StreamChannel(name);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Brand-based type guard that recognises any {@link StreamChannel}
|
|
67
|
+
* instance, even ones originating from a different copy of this
|
|
68
|
+
* package. Prefer this over `instanceof StreamChannel` when code
|
|
69
|
+
* may observe channels that were constructed elsewhere.
|
|
70
|
+
*/
|
|
71
|
+
static isInstance(value) {
|
|
72
|
+
return typeof value === "object" && value !== null && STREAM_CHANNEL_BRAND in value && value[STREAM_CHANNEL_BRAND] === true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Append an item to the channel. If this is a remote channel wired to a
|
|
76
|
+
* mux, the item is also injected into the main protocol event stream under
|
|
77
|
+
* {@link channelName}.
|
|
78
|
+
*/
|
|
79
|
+
push(item) {
|
|
80
|
+
this.#items.push(item);
|
|
81
|
+
this.#wake();
|
|
82
|
+
this.#onPush?.(item);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns an async iterator starting at position {@link startAt}. Each call
|
|
86
|
+
* returns an independent cursor so multiple consumers can iterate the same
|
|
87
|
+
* channel concurrently.
|
|
88
|
+
*/
|
|
89
|
+
iterate(startAt = 0) {
|
|
90
|
+
let cursor = startAt;
|
|
91
|
+
return { next: async () => {
|
|
92
|
+
while (true) {
|
|
93
|
+
if (cursor < this.#items.length) return {
|
|
94
|
+
value: this.#items[cursor++],
|
|
95
|
+
done: false
|
|
96
|
+
};
|
|
97
|
+
if (this.#done) {
|
|
98
|
+
if (this.#error) throw this.#error;
|
|
99
|
+
return {
|
|
100
|
+
value: void 0,
|
|
101
|
+
done: true
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
await new Promise((resolve) => this.#waiters.push(resolve));
|
|
105
|
+
}
|
|
106
|
+
} };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates an {@link AsyncIterable} backed by this channel, starting from
|
|
110
|
+
* {@link startAt}.
|
|
111
|
+
*/
|
|
112
|
+
toAsyncIterable(startAt = 0) {
|
|
113
|
+
return { [Symbol.asyncIterator]: () => this.iterate(startAt) };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates a web {@link ReadableStream} that emits channel items as
|
|
117
|
+
* Server-Sent Events. Useful for returning a channel directly from
|
|
118
|
+
* `new Response(channel.toEventStream())`.
|
|
119
|
+
*/
|
|
120
|
+
toEventStream(options = {}) {
|
|
121
|
+
const encoder = new TextEncoder();
|
|
122
|
+
const iterator = this.iterate(options.startAt);
|
|
123
|
+
const event = options.event ?? this.channelName;
|
|
124
|
+
const serialize = options.serialize ?? ((item) => JSON.stringify(item) ?? "null");
|
|
125
|
+
return new ReadableStream({
|
|
126
|
+
async pull(controller) {
|
|
127
|
+
try {
|
|
128
|
+
const next = await iterator.next();
|
|
129
|
+
if (next.done) {
|
|
130
|
+
controller.close();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const lines = [];
|
|
134
|
+
if (event != null) lines.push(`event: ${event}`);
|
|
135
|
+
for (const line of serialize(next.value).split(/\r\n|\r|\n/)) lines.push(`data: ${line}`);
|
|
136
|
+
controller.enqueue(encoder.encode(`${lines.join("\n")}\n\n`));
|
|
137
|
+
} catch (error) {
|
|
138
|
+
controller.error(error);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
async cancel() {
|
|
142
|
+
await iterator.return?.();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Returns the item at the given zero-based index.
|
|
148
|
+
*
|
|
149
|
+
* @throws {RangeError} If the index is out of bounds.
|
|
150
|
+
*/
|
|
151
|
+
get(index) {
|
|
152
|
+
if (index < 0 || index >= this.#items.length) throw new RangeError(`StreamChannel index ${index} out of bounds (size=${this.#items.length})`);
|
|
153
|
+
return this.#items[index];
|
|
154
|
+
}
|
|
155
|
+
/** The number of items currently buffered in the channel. */
|
|
156
|
+
get size() {
|
|
157
|
+
return this.#items.length;
|
|
158
|
+
}
|
|
159
|
+
/** Whether the channel has been closed or failed. */
|
|
160
|
+
get done() {
|
|
161
|
+
return this.#done;
|
|
162
|
+
}
|
|
163
|
+
/** Mark the channel as complete after all buffered items are consumed. */
|
|
164
|
+
close() {
|
|
165
|
+
this.#done = true;
|
|
166
|
+
this.#wake();
|
|
167
|
+
}
|
|
168
|
+
/** Mark the channel as failed after all buffered items are consumed. */
|
|
169
|
+
fail(err) {
|
|
170
|
+
this.#error = err;
|
|
171
|
+
this.#done = true;
|
|
172
|
+
this.#wake();
|
|
173
|
+
}
|
|
174
|
+
/** @internal Called by the mux to wire auto-forwarding. */
|
|
175
|
+
_wire(fn) {
|
|
176
|
+
this.#onPush = fn;
|
|
177
|
+
}
|
|
178
|
+
/** @internal Called by the mux on normal completion. */
|
|
179
|
+
_close() {
|
|
180
|
+
this.close();
|
|
181
|
+
}
|
|
182
|
+
/** @internal Called by the mux on failure. */
|
|
183
|
+
_fail(err) {
|
|
184
|
+
this.fail(err);
|
|
185
|
+
}
|
|
186
|
+
[Symbol.asyncIterator]() {
|
|
187
|
+
return this.iterate();
|
|
188
|
+
}
|
|
189
|
+
#wake() {
|
|
190
|
+
const waiters = this.#waiters.splice(0);
|
|
191
|
+
for (const w of waiters) w();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Type guard that tests whether a value is a {@link StreamChannel}.
|
|
196
|
+
*
|
|
197
|
+
* Uses a symbol brand rather than `instanceof` so channels built
|
|
198
|
+
* against a different copy of this package (e.g. one bundled by the
|
|
199
|
+
* `langchain` umbrella package) are still recognised.
|
|
200
|
+
*/
|
|
201
|
+
function isStreamChannel(value) {
|
|
202
|
+
return StreamChannel.isInstance(value);
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
exports.StreamChannel = StreamChannel;
|
|
206
|
+
exports.isStreamChannel = isStreamChannel;
|
|
207
|
+
|
|
208
|
+
//# sourceMappingURL=stream-channel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-channel.cjs","names":["#items","#wake","#onPush","#done","#error","#waiters"],"sources":["../../src/stream/stream-channel.ts"],"sourcesContent":["/**\n * StreamChannel — projection channel for local or remote streaming.\n *\n * A `StreamChannel<T>` is an append-only async stream with independent\n * cursors. Local channels stay in-process only. Remote channels declare a\n * protocol channel name; when registered with a {@link StreamMux} (via a\n * transformer's `init()` return value), every {@link push} is automatically\n * forwarded as a {@link ProtocolEvent} on the named channel — making the data\n * available both in-process (via `run.extensions`) and to remote clients (via\n * `session.subscribe(\"custom:<channelName>\")`).\n *\n * Lifecycle (`close` / `fail`) is managed by the mux automatically;\n * transformers do not need to call them.\n */\n\n/**\n * Branded symbol placed on every {@link StreamChannel} instance.\n *\n * Uses `Symbol.for` so the same symbol is shared across multiple\n * copies of this package that may coexist in a dependency graph\n * (e.g. when a user app imports `@langchain/langgraph` directly and a\n * wrapping library like `langchain` bundles its own copy). Using a\n * symbol brand instead of `instanceof` lets channels created against\n * one copy of the class be recognised by a mux from another.\n * @internal\n */\nexport const STREAM_CHANNEL_BRAND: unique symbol = Symbol.for(\n \"langgraph.stream_channel\"\n) as typeof STREAM_CHANNEL_BRAND;\n\nexport interface StreamChannelEventStreamOptions<T> {\n /**\n * SSE event name. Defaults to the channel's remote protocol name, if any.\n * Set this for local channels or when exposing the same channel under a\n * route-specific event name.\n */\n event?: string;\n /**\n * Cursor position to start streaming from. Useful for reconnects or\n * secondary subscribers that already consumed the first N buffered items and\n * only need replay from a known offset.\n */\n startAt?: number;\n /**\n * Serialize each item into the SSE `data:` field. Defaults to JSON. Use this\n * when a channel item needs a wire format other than its raw JSON shape, or\n * when the consumer expects line-oriented text payloads.\n */\n serialize?: (item: T) => string;\n}\n\n/**\n * A projection channel for {@link StreamTransformer}s.\n *\n * Implements `AsyncIterable<T>` so it can be iterated directly by\n * in-process consumers via `run.extensions.<key>`. Channels created with\n * {@link StreamChannel.remote} or `new StreamChannel(name)` are also\n * auto-forwarded to remote clients.\n *\n * @typeParam T - The type of items pushed into the channel.\n */\nexport class StreamChannel<T> implements AsyncIterable<T> {\n /** @internal Brand used by {@link StreamChannel.isInstance}. */\n readonly [STREAM_CHANNEL_BRAND] = true as const;\n\n /** Protocol channel name used for auto-forwarded events, if remote. */\n readonly channelName?: string;\n\n #items: T[] = [];\n #waiters: Array<() => void> = [];\n #done = false;\n #error: unknown;\n #onPush?: (item: T) => void;\n\n constructor(name?: string) {\n this.channelName = name;\n }\n\n /**\n * Create an in-process-only channel. Values remain available through\n * `run.extensions.<key>` but are not forwarded to remote clients.\n */\n static local<T>(): StreamChannel<T> {\n return new StreamChannel<T>();\n }\n\n /**\n * Create a channel whose pushes are forwarded to remote clients under\n * the given protocol channel name.\n */\n static remote<T>(name: string): StreamChannel<T> {\n return new StreamChannel<T>(name);\n }\n\n /**\n * Brand-based type guard that recognises any {@link StreamChannel}\n * instance, even ones originating from a different copy of this\n * package. Prefer this over `instanceof StreamChannel` when code\n * may observe channels that were constructed elsewhere.\n */\n static isInstance(value: unknown): value is StreamChannel<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n STREAM_CHANNEL_BRAND in value &&\n (value as { [STREAM_CHANNEL_BRAND]: unknown })[STREAM_CHANNEL_BRAND] ===\n true\n );\n }\n\n /**\n * Append an item to the channel. If this is a remote channel wired to a\n * mux, the item is also injected into the main protocol event stream under\n * {@link channelName}.\n */\n push(item: T): void {\n this.#items.push(item);\n this.#wake();\n this.#onPush?.(item);\n }\n\n /**\n * Returns an async iterator starting at position {@link startAt}. Each call\n * returns an independent cursor so multiple consumers can iterate the same\n * channel concurrently.\n */\n iterate(startAt = 0): AsyncIterator<T> {\n let cursor = startAt;\n return {\n next: async (): Promise<IteratorResult<T>> => {\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (cursor < this.#items.length) {\n return { value: this.#items[cursor++], done: false };\n }\n if (this.#done) {\n if (this.#error) throw this.#error;\n return { value: undefined as unknown as T, done: true };\n }\n await new Promise<void>((resolve) => this.#waiters.push(resolve));\n }\n },\n };\n }\n\n /**\n * Creates an {@link AsyncIterable} backed by this channel, starting from\n * {@link startAt}.\n */\n toAsyncIterable(startAt = 0): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]: () => this.iterate(startAt),\n };\n }\n\n /**\n * Creates a web {@link ReadableStream} that emits channel items as\n * Server-Sent Events. Useful for returning a channel directly from\n * `new Response(channel.toEventStream())`.\n */\n toEventStream(\n options: StreamChannelEventStreamOptions<T> = {}\n ): ReadableStream<Uint8Array> {\n const encoder = new TextEncoder();\n const iterator = this.iterate(options.startAt);\n const event = options.event ?? this.channelName;\n const serialize =\n options.serialize ?? ((item: T) => JSON.stringify(item) ?? \"null\");\n\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const next = await iterator.next();\n if (next.done) {\n controller.close();\n return;\n }\n\n const lines: string[] = [];\n if (event != null) {\n lines.push(`event: ${event}`);\n }\n for (const line of serialize(next.value).split(/\\r\\n|\\r|\\n/)) {\n lines.push(`data: ${line}`);\n }\n\n controller.enqueue(encoder.encode(`${lines.join(\"\\n\")}\\n\\n`));\n } catch (error) {\n controller.error(error);\n }\n },\n async cancel() {\n await iterator.return?.();\n },\n });\n }\n\n /**\n * Returns the item at the given zero-based index.\n *\n * @throws {RangeError} If the index is out of bounds.\n */\n get(index: number): T {\n if (index < 0 || index >= this.#items.length) {\n throw new RangeError(\n `StreamChannel index ${index} out of bounds (size=${this.#items.length})`\n );\n }\n return this.#items[index];\n }\n\n /** The number of items currently buffered in the channel. */\n get size(): number {\n return this.#items.length;\n }\n\n /** Whether the channel has been closed or failed. */\n get done(): boolean {\n return this.#done;\n }\n\n /** Mark the channel as complete after all buffered items are consumed. */\n close(): void {\n this.#done = true;\n this.#wake();\n }\n\n /** Mark the channel as failed after all buffered items are consumed. */\n fail(err: unknown): void {\n this.#error = err;\n this.#done = true;\n this.#wake();\n }\n\n /** @internal Called by the mux to wire auto-forwarding. */\n _wire(fn: (item: T) => void): void {\n this.#onPush = fn;\n }\n\n /** @internal Called by the mux on normal completion. */\n _close(): void {\n this.close();\n }\n\n /** @internal Called by the mux on failure. */\n _fail(err: unknown): void {\n this.fail(err);\n }\n\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this.iterate();\n }\n\n #wake(): void {\n const waiters = this.#waiters.splice(0);\n for (const w of waiters) w();\n }\n}\n\n/**\n * Type guard that tests whether a value is a {@link StreamChannel}.\n *\n * Uses a symbol brand rather than `instanceof` so channels built\n * against a different copy of this package (e.g. one bundled by the\n * `langchain` umbrella package) are still recognised.\n */\nexport function isStreamChannel(\n value: unknown\n): value is StreamChannel<unknown> {\n return StreamChannel.isInstance(value);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//#region src/stream/stream-channel.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* StreamChannel — projection channel for local or remote streaming.
|
|
4
|
+
*
|
|
5
|
+
* A `StreamChannel<T>` is an append-only async stream with independent
|
|
6
|
+
* cursors. Local channels stay in-process only. Remote channels declare a
|
|
7
|
+
* protocol channel name; when registered with a {@link StreamMux} (via a
|
|
8
|
+
* transformer's `init()` return value), every {@link push} is automatically
|
|
9
|
+
* forwarded as a {@link ProtocolEvent} on the named channel — making the data
|
|
10
|
+
* available both in-process (via `run.extensions`) and to remote clients (via
|
|
11
|
+
* `session.subscribe("custom:<channelName>")`).
|
|
12
|
+
*
|
|
13
|
+
* Lifecycle (`close` / `fail`) is managed by the mux automatically;
|
|
14
|
+
* transformers do not need to call them.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Branded symbol placed on every {@link StreamChannel} instance.
|
|
18
|
+
*
|
|
19
|
+
* Uses `Symbol.for` so the same symbol is shared across multiple
|
|
20
|
+
* copies of this package that may coexist in a dependency graph
|
|
21
|
+
* (e.g. when a user app imports `@langchain/langgraph` directly and a
|
|
22
|
+
* wrapping library like `langchain` bundles its own copy). Using a
|
|
23
|
+
* symbol brand instead of `instanceof` lets channels created against
|
|
24
|
+
* one copy of the class be recognised by a mux from another.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
declare const STREAM_CHANNEL_BRAND: unique symbol;
|
|
28
|
+
interface StreamChannelEventStreamOptions<T> {
|
|
29
|
+
/**
|
|
30
|
+
* SSE event name. Defaults to the channel's remote protocol name, if any.
|
|
31
|
+
* Set this for local channels or when exposing the same channel under a
|
|
32
|
+
* route-specific event name.
|
|
33
|
+
*/
|
|
34
|
+
event?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Cursor position to start streaming from. Useful for reconnects or
|
|
37
|
+
* secondary subscribers that already consumed the first N buffered items and
|
|
38
|
+
* only need replay from a known offset.
|
|
39
|
+
*/
|
|
40
|
+
startAt?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Serialize each item into the SSE `data:` field. Defaults to JSON. Use this
|
|
43
|
+
* when a channel item needs a wire format other than its raw JSON shape, or
|
|
44
|
+
* when the consumer expects line-oriented text payloads.
|
|
45
|
+
*/
|
|
46
|
+
serialize?: (item: T) => string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A projection channel for {@link StreamTransformer}s.
|
|
50
|
+
*
|
|
51
|
+
* Implements `AsyncIterable<T>` so it can be iterated directly by
|
|
52
|
+
* in-process consumers via `run.extensions.<key>`. Channels created with
|
|
53
|
+
* {@link StreamChannel.remote} or `new StreamChannel(name)` are also
|
|
54
|
+
* auto-forwarded to remote clients.
|
|
55
|
+
*
|
|
56
|
+
* @typeParam T - The type of items pushed into the channel.
|
|
57
|
+
*/
|
|
58
|
+
declare class StreamChannel<T> implements AsyncIterable<T> {
|
|
59
|
+
#private;
|
|
60
|
+
/** @internal Brand used by {@link StreamChannel.isInstance}. */
|
|
61
|
+
readonly [STREAM_CHANNEL_BRAND]: true;
|
|
62
|
+
/** Protocol channel name used for auto-forwarded events, if remote. */
|
|
63
|
+
readonly channelName?: string;
|
|
64
|
+
constructor(name?: string);
|
|
65
|
+
/**
|
|
66
|
+
* Create an in-process-only channel. Values remain available through
|
|
67
|
+
* `run.extensions.<key>` but are not forwarded to remote clients.
|
|
68
|
+
*/
|
|
69
|
+
static local<T>(): StreamChannel<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a channel whose pushes are forwarded to remote clients under
|
|
72
|
+
* the given protocol channel name.
|
|
73
|
+
*/
|
|
74
|
+
static remote<T>(name: string): StreamChannel<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Brand-based type guard that recognises any {@link StreamChannel}
|
|
77
|
+
* instance, even ones originating from a different copy of this
|
|
78
|
+
* package. Prefer this over `instanceof StreamChannel` when code
|
|
79
|
+
* may observe channels that were constructed elsewhere.
|
|
80
|
+
*/
|
|
81
|
+
static isInstance(value: unknown): value is StreamChannel<unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* Append an item to the channel. If this is a remote channel wired to a
|
|
84
|
+
* mux, the item is also injected into the main protocol event stream under
|
|
85
|
+
* {@link channelName}.
|
|
86
|
+
*/
|
|
87
|
+
push(item: T): void;
|
|
88
|
+
/**
|
|
89
|
+
* Returns an async iterator starting at position {@link startAt}. Each call
|
|
90
|
+
* returns an independent cursor so multiple consumers can iterate the same
|
|
91
|
+
* channel concurrently.
|
|
92
|
+
*/
|
|
93
|
+
iterate(startAt?: number): AsyncIterator<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Creates an {@link AsyncIterable} backed by this channel, starting from
|
|
96
|
+
* {@link startAt}.
|
|
97
|
+
*/
|
|
98
|
+
toAsyncIterable(startAt?: number): AsyncIterable<T>;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a web {@link ReadableStream} that emits channel items as
|
|
101
|
+
* Server-Sent Events. Useful for returning a channel directly from
|
|
102
|
+
* `new Response(channel.toEventStream())`.
|
|
103
|
+
*/
|
|
104
|
+
toEventStream(options?: StreamChannelEventStreamOptions<T>): ReadableStream<Uint8Array>;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the item at the given zero-based index.
|
|
107
|
+
*
|
|
108
|
+
* @throws {RangeError} If the index is out of bounds.
|
|
109
|
+
*/
|
|
110
|
+
get(index: number): T;
|
|
111
|
+
/** The number of items currently buffered in the channel. */
|
|
112
|
+
get size(): number;
|
|
113
|
+
/** Whether the channel has been closed or failed. */
|
|
114
|
+
get done(): boolean;
|
|
115
|
+
/** Mark the channel as complete after all buffered items are consumed. */
|
|
116
|
+
close(): void;
|
|
117
|
+
/** Mark the channel as failed after all buffered items are consumed. */
|
|
118
|
+
fail(err: unknown): void;
|
|
119
|
+
/** @internal Called by the mux to wire auto-forwarding. */
|
|
120
|
+
_wire(fn: (item: T) => void): void;
|
|
121
|
+
/** @internal Called by the mux on normal completion. */
|
|
122
|
+
_close(): void;
|
|
123
|
+
/** @internal Called by the mux on failure. */
|
|
124
|
+
_fail(err: unknown): void;
|
|
125
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export { StreamChannel };
|
|
129
|
+
//# sourceMappingURL=stream-channel.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-channel.d.cts","names":[],"sources":["../../src/stream/stream-channel.ts"],"mappings":";;AA0BA;;;;;AAIA;;;;;;;;;;;;AA+BA;;;;;;;cAnCa,oBAAA;AAAA,UAII,+BAAA;EAsE6B;;;;;EAhE5C,KAAA;EA6H2C;;;;;EAvH3C,OAAA;EA+MwC;;;;;EAzMxC,SAAA,IAAa,IAAA,EAAM,CAAA;AAAA;;;;;;;;;;;cAaR,aAAA,eAA4B,aAAA,CAAc,CAAA;EAAA;EA6BvC;EAAA,UA3BJ,oBAAA;EA2BsB;EAAA,SAxBvB,WAAA;EAQT,WAAA,CAAY,IAAA;EA0BM;;;;EAAA,OAlBX,KAAA,GAAA,CAAA,GAAY,aAAA,CAAc,CAAA;EAiC5B;;;;EAAA,OAzBE,MAAA,GAAA,CAAU,IAAA,WAAe,aAAA,CAAc,CAAA;EA2D9C;;;;;;EAAA,OAjDO,UAAA,CAAW,KAAA,YAAiB,KAAA,IAAS,aAAA;EA6D1C;;;;;EA9CF,IAAA,CAAK,IAAA,EAAM,CAAA;EAiGP;;;;;EAtFJ,OAAA,CAAQ,OAAA,YAAc,aAAA,CAAc,CAAA;EA6GnB;;;;EAtFjB,eAAA,CAAgB,OAAA,YAAc,aAAA,CAAc,CAAA;EAgGtC;;;;;EArFN,aAAA,CACE,OAAA,GAAS,+BAAA,CAAgC,CAAA,IACxC,cAAA,CAAe,UAAA;EAuFuB;;;;;EA/CzC,GAAA,CAAI,KAAA,WAAgB,CAAA;;MAUhB,IAAA,CAAA;;MAKA,IAAA,CAAA;;EAKJ,KAAA,CAAA;;EAMA,IAAA,CAAK,GAAA;;EAOL,KAAA,CAAM,EAAA,GAAK,IAAA,EAAM,CAAA;;EAKjB,MAAA,CAAA;;EAKA,KAAA,CAAM,GAAA;EAAA,CAIL,MAAA,CAAO,aAAA,KAAkB,aAAA,CAAc,CAAA;AAAA"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//#region src/stream/stream-channel.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* StreamChannel — projection channel for local or remote streaming.
|
|
4
|
+
*
|
|
5
|
+
* A `StreamChannel<T>` is an append-only async stream with independent
|
|
6
|
+
* cursors. Local channels stay in-process only. Remote channels declare a
|
|
7
|
+
* protocol channel name; when registered with a {@link StreamMux} (via a
|
|
8
|
+
* transformer's `init()` return value), every {@link push} is automatically
|
|
9
|
+
* forwarded as a {@link ProtocolEvent} on the named channel — making the data
|
|
10
|
+
* available both in-process (via `run.extensions`) and to remote clients (via
|
|
11
|
+
* `session.subscribe("custom:<channelName>")`).
|
|
12
|
+
*
|
|
13
|
+
* Lifecycle (`close` / `fail`) is managed by the mux automatically;
|
|
14
|
+
* transformers do not need to call them.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Branded symbol placed on every {@link StreamChannel} instance.
|
|
18
|
+
*
|
|
19
|
+
* Uses `Symbol.for` so the same symbol is shared across multiple
|
|
20
|
+
* copies of this package that may coexist in a dependency graph
|
|
21
|
+
* (e.g. when a user app imports `@langchain/langgraph` directly and a
|
|
22
|
+
* wrapping library like `langchain` bundles its own copy). Using a
|
|
23
|
+
* symbol brand instead of `instanceof` lets channels created against
|
|
24
|
+
* one copy of the class be recognised by a mux from another.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
declare const STREAM_CHANNEL_BRAND: unique symbol;
|
|
28
|
+
interface StreamChannelEventStreamOptions<T> {
|
|
29
|
+
/**
|
|
30
|
+
* SSE event name. Defaults to the channel's remote protocol name, if any.
|
|
31
|
+
* Set this for local channels or when exposing the same channel under a
|
|
32
|
+
* route-specific event name.
|
|
33
|
+
*/
|
|
34
|
+
event?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Cursor position to start streaming from. Useful for reconnects or
|
|
37
|
+
* secondary subscribers that already consumed the first N buffered items and
|
|
38
|
+
* only need replay from a known offset.
|
|
39
|
+
*/
|
|
40
|
+
startAt?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Serialize each item into the SSE `data:` field. Defaults to JSON. Use this
|
|
43
|
+
* when a channel item needs a wire format other than its raw JSON shape, or
|
|
44
|
+
* when the consumer expects line-oriented text payloads.
|
|
45
|
+
*/
|
|
46
|
+
serialize?: (item: T) => string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A projection channel for {@link StreamTransformer}s.
|
|
50
|
+
*
|
|
51
|
+
* Implements `AsyncIterable<T>` so it can be iterated directly by
|
|
52
|
+
* in-process consumers via `run.extensions.<key>`. Channels created with
|
|
53
|
+
* {@link StreamChannel.remote} or `new StreamChannel(name)` are also
|
|
54
|
+
* auto-forwarded to remote clients.
|
|
55
|
+
*
|
|
56
|
+
* @typeParam T - The type of items pushed into the channel.
|
|
57
|
+
*/
|
|
58
|
+
declare class StreamChannel<T> implements AsyncIterable<T> {
|
|
59
|
+
#private;
|
|
60
|
+
/** @internal Brand used by {@link StreamChannel.isInstance}. */
|
|
61
|
+
readonly [STREAM_CHANNEL_BRAND]: true;
|
|
62
|
+
/** Protocol channel name used for auto-forwarded events, if remote. */
|
|
63
|
+
readonly channelName?: string;
|
|
64
|
+
constructor(name?: string);
|
|
65
|
+
/**
|
|
66
|
+
* Create an in-process-only channel. Values remain available through
|
|
67
|
+
* `run.extensions.<key>` but are not forwarded to remote clients.
|
|
68
|
+
*/
|
|
69
|
+
static local<T>(): StreamChannel<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a channel whose pushes are forwarded to remote clients under
|
|
72
|
+
* the given protocol channel name.
|
|
73
|
+
*/
|
|
74
|
+
static remote<T>(name: string): StreamChannel<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Brand-based type guard that recognises any {@link StreamChannel}
|
|
77
|
+
* instance, even ones originating from a different copy of this
|
|
78
|
+
* package. Prefer this over `instanceof StreamChannel` when code
|
|
79
|
+
* may observe channels that were constructed elsewhere.
|
|
80
|
+
*/
|
|
81
|
+
static isInstance(value: unknown): value is StreamChannel<unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* Append an item to the channel. If this is a remote channel wired to a
|
|
84
|
+
* mux, the item is also injected into the main protocol event stream under
|
|
85
|
+
* {@link channelName}.
|
|
86
|
+
*/
|
|
87
|
+
push(item: T): void;
|
|
88
|
+
/**
|
|
89
|
+
* Returns an async iterator starting at position {@link startAt}. Each call
|
|
90
|
+
* returns an independent cursor so multiple consumers can iterate the same
|
|
91
|
+
* channel concurrently.
|
|
92
|
+
*/
|
|
93
|
+
iterate(startAt?: number): AsyncIterator<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Creates an {@link AsyncIterable} backed by this channel, starting from
|
|
96
|
+
* {@link startAt}.
|
|
97
|
+
*/
|
|
98
|
+
toAsyncIterable(startAt?: number): AsyncIterable<T>;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a web {@link ReadableStream} that emits channel items as
|
|
101
|
+
* Server-Sent Events. Useful for returning a channel directly from
|
|
102
|
+
* `new Response(channel.toEventStream())`.
|
|
103
|
+
*/
|
|
104
|
+
toEventStream(options?: StreamChannelEventStreamOptions<T>): ReadableStream<Uint8Array>;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the item at the given zero-based index.
|
|
107
|
+
*
|
|
108
|
+
* @throws {RangeError} If the index is out of bounds.
|
|
109
|
+
*/
|
|
110
|
+
get(index: number): T;
|
|
111
|
+
/** The number of items currently buffered in the channel. */
|
|
112
|
+
get size(): number;
|
|
113
|
+
/** Whether the channel has been closed or failed. */
|
|
114
|
+
get done(): boolean;
|
|
115
|
+
/** Mark the channel as complete after all buffered items are consumed. */
|
|
116
|
+
close(): void;
|
|
117
|
+
/** Mark the channel as failed after all buffered items are consumed. */
|
|
118
|
+
fail(err: unknown): void;
|
|
119
|
+
/** @internal Called by the mux to wire auto-forwarding. */
|
|
120
|
+
_wire(fn: (item: T) => void): void;
|
|
121
|
+
/** @internal Called by the mux on normal completion. */
|
|
122
|
+
_close(): void;
|
|
123
|
+
/** @internal Called by the mux on failure. */
|
|
124
|
+
_fail(err: unknown): void;
|
|
125
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export { StreamChannel };
|
|
129
|
+
//# sourceMappingURL=stream-channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-channel.d.ts","names":[],"sources":["../../src/stream/stream-channel.ts"],"mappings":";;AA0BA;;;;;AAIA;;;;;;;;;;;;AA+BA;;;;;;;cAnCa,oBAAA;AAAA,UAII,+BAAA;EAsE6B;;;;;EAhE5C,KAAA;EA6H2C;;;;;EAvH3C,OAAA;EA+MwC;;;;;EAzMxC,SAAA,IAAa,IAAA,EAAM,CAAA;AAAA;;;;;;;;;;;cAaR,aAAA,eAA4B,aAAA,CAAc,CAAA;EAAA;EA6BvC;EAAA,UA3BJ,oBAAA;EA2BsB;EAAA,SAxBvB,WAAA;EAQT,WAAA,CAAY,IAAA;EA0BM;;;;EAAA,OAlBX,KAAA,GAAA,CAAA,GAAY,aAAA,CAAc,CAAA;EAiC5B;;;;EAAA,OAzBE,MAAA,GAAA,CAAU,IAAA,WAAe,aAAA,CAAc,CAAA;EA2D9C;;;;;;EAAA,OAjDO,UAAA,CAAW,KAAA,YAAiB,KAAA,IAAS,aAAA;EA6D1C;;;;;EA9CF,IAAA,CAAK,IAAA,EAAM,CAAA;EAiGP;;;;;EAtFJ,OAAA,CAAQ,OAAA,YAAc,aAAA,CAAc,CAAA;EA6GnB;;;;EAtFjB,eAAA,CAAgB,OAAA,YAAc,aAAA,CAAc,CAAA;EAgGtC;;;;;EArFN,aAAA,CACE,OAAA,GAAS,+BAAA,CAAgC,CAAA,IACxC,cAAA,CAAe,UAAA;EAuFuB;;;;;EA/CzC,GAAA,CAAI,KAAA,WAAgB,CAAA;;MAUhB,IAAA,CAAA;;MAKA,IAAA,CAAA;;EAKJ,KAAA,CAAA;;EAMA,IAAA,CAAK,GAAA;;EAOL,KAAA,CAAM,EAAA,GAAK,IAAA,EAAM,CAAA;;EAKjB,MAAA,CAAA;;EAKA,KAAA,CAAM,GAAA;EAAA,CAIL,MAAA,CAAO,aAAA,KAAkB,aAAA,CAAc,CAAA;AAAA"}
|