@threadbase-sh/streamer 1.25.0 → 1.26.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/index.d.cts CHANGED
@@ -307,6 +307,7 @@ interface ServerConfig {
307
307
  logMenubarRequests?: boolean;
308
308
  browseRoot?: string;
309
309
  publicUrl?: string;
310
+ browserCors?: string;
310
311
  disableDb?: boolean;
311
312
  scanProfiles?: Array<{
312
313
  id: string;
@@ -717,6 +718,7 @@ type ApiDeps = {
717
718
  };
718
719
  publicUrl: string | null;
719
720
  browseRoot: string | null;
721
+ browserCors: string | undefined;
720
722
  ptyManager: LiveSessionManager;
721
723
  sessionStore: SessionStore;
722
724
  wsHub: WSHub;
@@ -893,6 +895,7 @@ declare class StreamerServer {
893
895
  private disableDb;
894
896
  private browseRoot;
895
897
  private publicUrl;
898
+ private browserCors;
896
899
  private pairTokens;
897
900
  private exchangeAttempts;
898
901
  private sessionStartAttempts;
package/dist/index.d.ts CHANGED
@@ -307,6 +307,7 @@ interface ServerConfig {
307
307
  logMenubarRequests?: boolean;
308
308
  browseRoot?: string;
309
309
  publicUrl?: string;
310
+ browserCors?: string;
310
311
  disableDb?: boolean;
311
312
  scanProfiles?: Array<{
312
313
  id: string;
@@ -717,6 +718,7 @@ type ApiDeps = {
717
718
  };
718
719
  publicUrl: string | null;
719
720
  browseRoot: string | null;
721
+ browserCors: string | undefined;
720
722
  ptyManager: LiveSessionManager;
721
723
  sessionStore: SessionStore;
722
724
  wsHub: WSHub;
@@ -893,6 +895,7 @@ declare class StreamerServer {
893
895
  private disableDb;
894
896
  private browseRoot;
895
897
  private publicUrl;
898
+ private browserCors;
896
899
  private pairTokens;
897
900
  private exchangeAttempts;
898
901
  private sessionStartAttempts;
package/dist/index.js CHANGED
@@ -324,6 +324,15 @@ function loadPublicUrl() {
324
324
  }
325
325
  return void 0;
326
326
  }
327
+ function loadBrowserCors() {
328
+ try {
329
+ const content = readFileSync(configFile(), "utf-8");
330
+ const match = content.match(/browser_cors:\s*(.+)/);
331
+ if (match?.[1]) return match[1].trim();
332
+ } catch {
333
+ }
334
+ return void 0;
335
+ }
327
336
  function loadCacheDir() {
328
337
  try {
329
338
  const content = readFileSync(configFile(), "utf-8");
@@ -2574,25 +2583,55 @@ var authMiddleware = (deps) => async (c, next) => {
2574
2583
  };
2575
2584
 
2576
2585
  // src/api/middleware/cors.middleware.ts
2577
- var ALLOWED_ORIGINS = /* @__PURE__ */ new Set([
2586
+ var DEFAULT_DEV_ORIGINS = [
2578
2587
  "http://localhost:8081",
2579
2588
  "http://localhost:19006",
2580
2589
  "http://localhost:3000"
2581
- ]);
2582
- var corsMiddleware = () => async (c, next) => {
2583
- const origin = c.req.header("origin");
2584
- const allowedOrigin = origin && ALLOWED_ORIGINS.has(origin) ? origin : null;
2585
- if (allowedOrigin) {
2586
- c.res.headers.set("Access-Control-Allow-Origin", allowedOrigin);
2587
- c.res.headers.set("Vary", "Origin");
2588
- c.res.headers.set("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS");
2589
- c.res.headers.set("Access-Control-Allow-Headers", "Authorization, Content-Type, If-None-Match");
2590
- c.res.headers.set("Access-Control-Expose-Headers", "ETag");
2591
- }
2592
- if (c.req.method === "OPTIONS") {
2593
- return c.newResponse(null, allowedOrigin ? 204 : 403);
2594
- }
2595
- await next();
2590
+ ];
2591
+ function resolveAllowedOrigins(raw) {
2592
+ if (!raw) return null;
2593
+ const trimmed = raw.trim();
2594
+ const lower = trimmed.toLowerCase();
2595
+ if (lower === "0" || lower === "false" || lower === "no" || lower === "off" || trimmed === "") {
2596
+ return null;
2597
+ }
2598
+ const origins = new Set(DEFAULT_DEV_ORIGINS);
2599
+ if (!["1", "true", "yes", "on"].includes(lower)) {
2600
+ for (const o of trimmed.split(",")) {
2601
+ const origin = o.trim();
2602
+ if (origin) origins.add(origin);
2603
+ }
2604
+ }
2605
+ return origins;
2606
+ }
2607
+ var corsMiddleware = (configValue) => {
2608
+ const allowedOrigins = resolveAllowedOrigins(
2609
+ process.env.THREADBASE_ALLOW_BROWSER_CORS ?? configValue
2610
+ );
2611
+ return async (c, next) => {
2612
+ const origin = c.req.header("origin");
2613
+ const allowedOrigin = allowedOrigins && origin && allowedOrigins.has(origin) ? origin : null;
2614
+ if (allowedOrigin) {
2615
+ const raw = c.env.outgoing;
2616
+ raw.setHeader("Access-Control-Allow-Origin", allowedOrigin);
2617
+ raw.setHeader("Vary", "Origin");
2618
+ raw.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS");
2619
+ raw.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, If-None-Match");
2620
+ raw.setHeader("Access-Control-Expose-Headers", "ETag");
2621
+ c.res.headers.set("Access-Control-Allow-Origin", allowedOrigin);
2622
+ c.res.headers.set("Vary", "Origin");
2623
+ c.res.headers.set("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS");
2624
+ c.res.headers.set(
2625
+ "Access-Control-Allow-Headers",
2626
+ "Authorization, Content-Type, If-None-Match"
2627
+ );
2628
+ c.res.headers.set("Access-Control-Expose-Headers", "ETag");
2629
+ }
2630
+ if (c.req.method === "OPTIONS") {
2631
+ return c.newResponse(null, allowedOrigin ? 204 : 403);
2632
+ }
2633
+ await next();
2634
+ };
2596
2635
  };
2597
2636
 
2598
2637
  // src/api/middleware/error.middleware.ts
@@ -3007,7 +3046,7 @@ var createHonoApp = (deps, upgradeWebSocket) => {
3007
3046
  event: "http.request"
3008
3047
  });
3009
3048
  });
3010
- app.use("*", corsMiddleware());
3049
+ app.use("*", corsMiddleware(deps.browserCors));
3011
3050
  app.use("*", authMiddleware(deps));
3012
3051
  app.onError(errorMiddleware);
3013
3052
  app.route("/healthz", createHealthRoutes());
@@ -5062,6 +5101,7 @@ var StreamerServer = class {
5062
5101
  disableDb = false;
5063
5102
  browseRoot = null;
5064
5103
  publicUrl = null;
5104
+ browserCors;
5065
5105
  pairTokens = new PairTokenStore();
5066
5106
  exchangeAttempts = /* @__PURE__ */ new Map();
5067
5107
  sessionStartAttempts = /* @__PURE__ */ new Map();
@@ -5147,6 +5187,7 @@ var StreamerServer = class {
5147
5187
  this.log.warn(`Warning: ${result.error}`, { error: result.error });
5148
5188
  }
5149
5189
  }
5190
+ this.browserCors = config.browserCors ?? loadBrowserCors();
5150
5191
  this.sessionStore = new SessionStore();
5151
5192
  this.wsHub = new WSHub();
5152
5193
  this.fileWatcher = new ConversationWatcher({
@@ -5301,6 +5342,7 @@ var StreamerServer = class {
5301
5342
  rotateApiKey: () => this.rotateApiKey(),
5302
5343
  publicUrl: this.publicUrl,
5303
5344
  browseRoot: this.browseRoot,
5345
+ browserCors: this.browserCors,
5304
5346
  ptyManager: this.ptyManager,
5305
5347
  sessionStore: this.sessionStore,
5306
5348
  wsHub: this.wsHub,