@sylphx/lens-server 4.1.4 → 4.1.5

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/index.js CHANGED
@@ -1045,9 +1045,28 @@ class LensServerImpl {
1045
1045
  headers: baseHeaders
1046
1046
  });
1047
1047
  }
1048
- const isSseRequest = url.searchParams.get("_sse") === "1" || request.headers.get("accept") === "text/event-stream";
1049
- if (request.method === "GET" && isSseRequest) {
1050
- const path = pathname.replace(/^\//, "");
1048
+ if (request.method === "GET" && pathname.endsWith("/__lens/sse")) {
1049
+ const path = url.searchParams.get("path");
1050
+ if (!path) {
1051
+ const encoder = new TextEncoder;
1052
+ const errorStream = new ReadableStream({
1053
+ start(controller) {
1054
+ const data = `event: error
1055
+ data: ${JSON.stringify({ error: "Missing path parameter" })}
1056
+
1057
+ `;
1058
+ controller.enqueue(encoder.encode(data));
1059
+ controller.close();
1060
+ }
1061
+ });
1062
+ return new Response(errorStream, {
1063
+ headers: {
1064
+ "Content-Type": "text/event-stream",
1065
+ "Cache-Control": "no-cache",
1066
+ Connection: "keep-alive"
1067
+ }
1068
+ });
1069
+ }
1051
1070
  const inputParam = url.searchParams.get("input");
1052
1071
  let input;
1053
1072
  if (inputParam) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sylphx/lens-server",
3
- "version": "4.1.4",
3
+ "version": "4.1.5",
4
4
  "description": "Server runtime for Lens API framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1276,14 +1276,30 @@ class LensServerImpl<
1276
1276
  });
1277
1277
  }
1278
1278
 
1279
- // SSE: GET /{path}?_sse=1&input={...}
1280
- // Client uses EventSource which sends GET requests with path in URL
1281
- const isSseRequest =
1282
- url.searchParams.get("_sse") === "1" || request.headers.get("accept") === "text/event-stream";
1283
-
1284
- if (request.method === "GET" && isSseRequest) {
1285
- // Extract path from URL (strip leading slash)
1286
- const path = pathname.replace(/^\//, "");
1279
+ // SSE: GET /__lens/sse?path={path}&input={...}
1280
+ // Dedicated endpoint with path in query param - consistent with POST body format
1281
+ // This avoids base path parsing issues when server is mounted at /api etc.
1282
+ if (request.method === "GET" && pathname.endsWith("/__lens/sse")) {
1283
+ const path = url.searchParams.get("path");
1284
+
1285
+ // Validate path parameter
1286
+ if (!path) {
1287
+ const encoder = new TextEncoder();
1288
+ const errorStream = new ReadableStream({
1289
+ start(controller) {
1290
+ const data = `event: error\ndata: ${JSON.stringify({ error: "Missing path parameter" })}\n\n`;
1291
+ controller.enqueue(encoder.encode(data));
1292
+ controller.close();
1293
+ },
1294
+ });
1295
+ return new Response(errorStream, {
1296
+ headers: {
1297
+ "Content-Type": "text/event-stream",
1298
+ "Cache-Control": "no-cache",
1299
+ Connection: "keep-alive",
1300
+ },
1301
+ });
1302
+ }
1287
1303
 
1288
1304
  // Parse input from query params
1289
1305
  const inputParam = url.searchParams.get("input");