@s2-dev/streamstore 0.15.7 → 0.15.9

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.
@@ -13,32 +13,37 @@ export class EventStream<T extends ServerEvent<unknown>>
13
13
  extends ReadableStream<T>
14
14
  {
15
15
  constructor(
16
- stream: ReadableStream<Uint8Array>,
16
+ responseBody: ReadableStream<Uint8Array>,
17
17
  parse: (x: ServerEvent<string>) => IteratorResult<T, undefined>,
18
18
  ) {
19
- const reader = stream.getReader();
19
+ const upstream = responseBody.getReader();
20
20
  let buffer: Uint8Array = new Uint8Array();
21
21
  super({
22
- async pull(controller) {
22
+ async pull(downstream) {
23
23
  try {
24
- const r = await reader.read();
25
- if (r.done) return controller.close();
26
- buffer = concatBuffer(buffer, r.value);
27
- for (const { chunk, remainder } of chunks(buffer)) {
28
- buffer = remainder;
29
- const item = parseChunk(chunk, parse);
30
- if (item?.value) controller.enqueue(item.value);
24
+ while (true) {
25
+ const match = findBoundary(buffer);
26
+ if (!match) {
27
+ const chunk = await upstream.read();
28
+ if (chunk.done) return downstream.close();
29
+ buffer = concatBuffer(buffer, chunk.value);
30
+ continue;
31
+ }
32
+ const message = buffer.slice(0, match.index);
33
+ buffer = buffer.slice(match.index + match.length);
34
+ const item = parseMessage(message, parse);
35
+ if (item?.value) return downstream.enqueue(item.value);
31
36
  if (item?.done) {
32
- await reader.cancel("done");
33
- return controller.close();
37
+ await upstream.cancel("done");
38
+ return downstream.close();
34
39
  }
35
40
  }
36
41
  } catch (e) {
37
- await reader.cancel(e);
38
- controller.error(e);
42
+ downstream.error(e);
43
+ await upstream.cancel(e);
39
44
  }
40
45
  },
41
- cancel: reason => reader.cancel(reason),
46
+ cancel: reason => upstream.cancel(reason),
42
47
  });
43
48
  }
44
49
 
@@ -103,22 +108,7 @@ function findBoundary(
103
108
  return null;
104
109
  }
105
110
 
106
- function* chunks(
107
- remainder: Uint8Array,
108
- ): Generator<{ chunk: Uint8Array; remainder: Uint8Array }> {
109
- while (true) {
110
- const match = findBoundary(remainder);
111
- if (!match) {
112
- yield { chunk: new Uint8Array(), remainder };
113
- return;
114
- }
115
- const chunk = remainder.slice(0, match.index);
116
- remainder = remainder.slice(match.index + match.length);
117
- yield { chunk, remainder };
118
- }
119
- }
120
-
121
- function parseChunk<T extends ServerEvent<unknown>>(
111
+ function parseMessage<T extends ServerEvent<unknown>>(
122
112
  chunk: Uint8Array,
123
113
  parse: (x: ServerEvent<string>) => IteratorResult<T, undefined>,
124
114
  ) {
@@ -19,7 +19,7 @@ const routes = buildRouteMap({
19
19
  export const app = buildApplication(routes, {
20
20
  name: "mcp",
21
21
  versionInfo: {
22
- currentVersion: "0.15.7",
22
+ currentVersion: "0.15.9",
23
23
  },
24
24
  });
25
25
 
@@ -45,7 +45,7 @@ export function createMCPServer(deps: {
45
45
  }) {
46
46
  const server = new McpServer({
47
47
  name: "S2",
48
- version: "0.15.7",
48
+ version: "0.15.9",
49
49
  });
50
50
 
51
51
  const client = new S2Core({