@@ -28,6 +28,7 @@ import { installFlueObservation } from "./observability/flue.js";
2828import { installRuntimeTracing } from "./observability/platform-tracing.js" ;
2929import { threadOrbDiskRoutes } from "./orb-disk/routes.js" ;
3030import { threadOrbMemoryRoutes } from "./orb-memory/routes.js" ;
31+ import { d1Session } from "./persistence/d1-session.js" ;
3132import { portalAuthRoutes } from "./portals/auth-routes.js" ;
3233import { portalHostRouting } from "./portals/host-routing.js" ;
3334import { threadPortalRoutes } from "./portals/routes.js" ;
@@ -40,6 +41,7 @@ import {
4041} from "./settings/members/routes.js" ;
4142import { settingsRoutes } from "./settings/routes.js" ;
4243import { pluginTriggerIngressRoutes } from "./settings/triggers/routes.js" ;
44+ import { shellRoutes } from "./shell/routes.js" ;
4345import { sidebarLayoutRoutes } from "./sidebar-layout/routes.js" ;
4446import { bitbucketGitGatewayRoutes } from "./source-control/bitbucket/git-gateway.js" ;
4547import { bitbucketControlPlaneRoutes } from "./source-control/bitbucket/routes.js" ;
@@ -74,6 +76,7 @@ const app = new Hono<AppEnv>();
7476app . use ( "*" , portalHostRouting ) ;
7577app . use ( "*" , requestId ) ;
7678app . use ( "*" , requestLogging ) ;
79+ app . use ( "*" , d1Session ) ;
7780
7881app . get ( "/healthz" , healthHandler ) ;
7982app . get ( "/readyz" , readinessHandler ) ;
@@ -105,6 +108,7 @@ app.route("/v1/projects", projectRoutes);
105108app . route ( "/v1/realtime" , realtimeRoutes ) ;
106109app . route ( "/v1/settings" , settingsRoutes ) ;
107110app . route ( "/v1/shared-threads" , sharedThreadRoutes ) ;
111+ app . route ( "/v1/shell" , shellRoutes ) ;
108112app . route ( "/v1/sidebar-layout" , sidebarLayoutRoutes ) ;
109113app . route ( "/v1/thread-search" , threadSearchRoutes ) ;
110114app . use ( "/v1/threads/:threadId" , shareThreadReads ) ;
@@ -117,12 +121,11 @@ app.use("/v1/threads/:threadId/follow", authorizeThread);
117121app . route ( "/v1/threads" , threadMemberRoutes ) ;
118122app . use ( "/v1/threads/:threadId/bug-reports" , authorizeThread ) ;
119123app . route ( "/v1/threads" , threadBugReportRoutes ) ;
120- app . use ( "/v1/threads/:threadId/changes" , authorizeThread ) ;
124+ // `/changes/*` also matches `/changes`, and `/files/*` `/files`; registering
125+ // both would authorize twice, one more D1 round trip per request.
121126app . use ( "/v1/threads/:threadId/changes/*" , authorizeThread ) ;
122127app . route ( "/v1/threads" , threadChangesRoutes ) ;
123- app . use ( "/v1/threads/:threadId/files" , authorizeThread ) ;
124128app . use ( "/v1/threads/:threadId/files/*" , authorizeThread ) ;
125- app . use ( "/v1/threads/:threadId/files" , enforceThreadActive ) ;
126129app . use ( "/v1/threads/:threadId/files/*" , enforceThreadActive ) ;
127130app . route ( "/v1/threads" , threadFilesRoutes ) ;
128131app . use ( "/v1/threads/:threadId/files-sandbox" , authorizeThread ) ;
@@ -132,8 +135,9 @@ app.route("/v1/threads", threadSandboxFileRoutes);
132135// while the Thread is archived. `/storage/*` also matches `/storage`.
133136app . use ( "/v1/threads/:threadId/storage/*" , authorizeThread ) ;
134137app . route ( "/v1/threads" , threadStorageRoutes ) ;
135- app . use ( "/v1/threads/:threadId/terminal" , authorizeThread ) ;
136- app . use ( "/v1/threads/:threadId/terminal" , enforceThreadActive ) ;
138+ // `/terminal/*` also matches `/terminal`: the attach and its warm-up.
139+ app . use ( "/v1/threads/:threadId/terminal/*" , authorizeThread ) ;
140+ app . use ( "/v1/threads/:threadId/terminal/*" , enforceThreadActive ) ;
137141app . route ( "/v1/threads" , threadTerminalRoutes ) ;
138142// `/portals/*` also matches `/portals`; authorizing twice would see the
139143// owner a contributor is impersonating.
0 commit comments