@standardagents/builder 0.17.1 → 0.17.3

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
@@ -917,7 +917,7 @@ function resolvePlatformRouting(providerName, env) {
917
917
  var DEFAULT_PLATFORM_PROXY_ORIGIN, PROVIDER_BASE_PATHS;
918
918
  var init_platform_routing = __esm({
919
919
  "src/agents/providers/platform-routing.ts"() {
920
- DEFAULT_PLATFORM_PROXY_ORIGIN = "https://proxy.standardagents.ai";
920
+ DEFAULT_PLATFORM_PROXY_ORIGIN = "https://api.standardagents.ai";
921
921
  PROVIDER_BASE_PATHS = {
922
922
  cloudflare: "/ai/v1"
923
923
  };
@@ -19696,8 +19696,9 @@ import { isThreadEndpoint } from "@standardagents/spec";
19696
19696
  const PUBLIC_ROUTES = [
19697
19697
  '/api/auth/bootstrap',
19698
19698
  '/api/auth/login',
19699
- '/api/auth/bootstrap',
19700
19699
  '/api/auth/config',
19700
+ '/api/auth/sa/start', // Login with Standard Agents (OAuth) \u2014 unauthenticated entry
19701
+ '/api/auth/sa/callback', // OAuth callback (sets the session cookie)
19701
19702
  '/api/config',
19702
19703
  '/api/auth/oauth/github',
19703
19704
  '/api/auth/oauth/google',
@@ -19710,15 +19711,31 @@ const PUBLIC_ROUTES = [
19710
19711
  '/api/hooks' // Hook metadata is safe to expose publicly
19711
19712
  ];
19712
19713
 
19714
+ // True when the platform deployed this instance (injects STANDARD_AGENTS_HOSTED).
19715
+ // Hosted instances are internet-reachable and multi-tenant, so the thread data
19716
+ // API and event/stream WebSockets must NOT be anonymously public the way they
19717
+ // are in single-user local dev \u2014 they require a session (admin) or API key (SDK).
19718
+ function isHostedInstance(env) {
19719
+ const value = env && env.STANDARD_AGENTS_HOSTED;
19720
+ if (typeof value === 'string') {
19721
+ const trimmed = value.trim().toLowerCase();
19722
+ return trimmed !== '' && trimmed !== '0' && trimmed !== 'false';
19723
+ }
19724
+ return Boolean(value);
19725
+ }
19726
+
19713
19727
  // Check if a route is public (no auth required)
19714
- function isPublicRoute(routePath) {
19728
+ function isPublicRoute(routePath, hosted) {
19715
19729
  // Exact match for auth routes
19716
19730
  if (PUBLIC_ROUTES.includes(routePath)) {
19717
19731
  return true;
19718
19732
  }
19719
19733
 
19720
- // Thread routes are always public
19721
- if (routePath.startsWith('/api/threads/') || routePath === '/api/threads') {
19734
+ // Thread routes (REST + message/log stream WebSockets) are public in local
19735
+ // single-user dev, but on a hosted deployment they require auth \u2014 requireAuth
19736
+ // accepts the admin's session (cookie or token) or the SDK's API key, so this
19737
+ // only blocks anonymous access to another tenant's threads/messages/files.
19738
+ if (!hosted && (routePath.startsWith('/api/threads/') || routePath === '/api/threads')) {
19722
19739
  return true;
19723
19740
  }
19724
19741
 
@@ -19820,7 +19837,7 @@ ${packedThreadRouteCode}
19820
19837
 
19821
19838
  if (routeMatch) {
19822
19839
  // Check if authentication is required for this route
19823
- const publicRoute = isPublicRoute(routePath);
19840
+ const publicRoute = isPublicRoute(routePath, isHostedInstance(env));
19824
19841
  const isApiRoute = routePath.startsWith('/api/');
19825
19842
 
19826
19843
  let authContext = null;
@@ -20573,6 +20590,19 @@ async function hashToken(token) {
20573
20590
  const hashArray = new Uint8Array(hashBuffer);
20574
20591
  return Array.from(hashArray, (byte) => byte.toString(16).padStart(2, "0")).join("");
20575
20592
  }
20593
+ var SESSION_COOKIE_NAME = "agtuser_session";
20594
+ function readSessionCookie(request) {
20595
+ const header = request.headers.get("Cookie");
20596
+ if (!header) return null;
20597
+ for (const part of header.split(";")) {
20598
+ const eq = part.indexOf("=");
20599
+ if (eq === -1) continue;
20600
+ if (part.slice(0, eq).trim() === SESSION_COOKIE_NAME) {
20601
+ return decodeURIComponent(part.slice(eq + 1).trim()) || null;
20602
+ }
20603
+ }
20604
+ return null;
20605
+ }
20576
20606
  function isValidUserToken(token) {
20577
20607
  return token.startsWith("agtuser_") && token.length > 10;
20578
20608
  }
@@ -20646,6 +20676,10 @@ function extractBearerToken(request) {
20646
20676
  if (authHeader && authHeader.startsWith("Bearer ")) {
20647
20677
  return authHeader.substring(7);
20648
20678
  }
20679
+ const cookieToken = readSessionCookie(request);
20680
+ if (cookieToken) {
20681
+ return cookieToken;
20682
+ }
20649
20683
  const isWebSocket = request.headers.get("upgrade")?.toLowerCase() === "websocket";
20650
20684
  if (isWebSocket) {
20651
20685
  try {