@@ -17,6 +17,7 @@ import { WorkspaceRouterMiddleware } from "./workspace"
1717import { InstanceMiddleware } from "./routes/instance/middleware"
1818import { WorkspaceRoutes } from "./routes/control/workspace"
1919import { ExperimentalHttpApiServer } from "./routes/instance/httpapi/server"
20+ import * as ServerRuntime from "./runtime"
2021
2122// @ts -ignore This global is needed to prevent ai-sdk from logging warnings to stdout https://github.com/vercel/ai/blob/2dc67e0ef538307f21368db32d5a12345d98831b/packages/ai/src/logger/log-warnings.ts#L85
2223globalThis . AI_SDK_LOG_WARNINGS = false
@@ -37,13 +38,38 @@ type ServerApp = {
3738 request ( input : string | URL | Request , init ?: RequestInit ) : Response | Promise < Response >
3839}
3940
40- const DefaultHono = lazy ( ( ) => createHono ( { } ) )
41- const DefaultHttpApi = lazy ( ( ) => createHttpApi ( ) )
42- export const Default = ( ) => ( Flag . OPENCODE_EXPERIMENTAL_HTTPAPI ? DefaultHttpApi ( ) : DefaultHono ( ) )
41+ const DefaultHono = lazy ( ( ) => withRuntime ( { runtime : "hono" , reason : "stable" } , createHono ( { } , { runtime : "hono" , reason : "stable" } ) ) )
42+ const DefaultHttpApi = lazy ( ( ) => createDefaultHttpApi ( ) )
43+
44+ function select ( ) {
45+ return ServerRuntime . select ( )
46+ }
47+
48+ export const runtime = select
49+
50+ export const Default = ( ) => {
51+ const selected = select ( )
52+ return selected . runtime === "effect-httpapi" ? DefaultHttpApi ( ) : DefaultHono ( )
53+ }
4354
4455function create ( opts : { cors ?: string [ ] } ) {
45- if ( Flag . OPENCODE_EXPERIMENTAL_HTTPAPI ) return createHttpApi ( )
46- return createHono ( opts )
56+ const selected = select ( )
57+ return selected . runtime === "effect-httpapi"
58+ ? withRuntime ( selected , createHttpApi ( ) )
59+ : withRuntime ( selected , createHono ( opts , selected ) )
60+ }
61+
62+ export function Legacy ( opts : { cors ?: string [ ] } = { } ) {
63+ return withRuntime ( { runtime : "hono" , reason : "explicit" } , createHono ( opts , { runtime : "hono" , reason : "explicit" } ) )
64+ }
65+
66+ function createDefaultHttpApi ( ) {
67+ return withRuntime ( select ( ) , createHttpApi ( ) )
68+ }
69+
70+ function withRuntime < T extends { app : ServerApp ; runtime : unknown } > ( selection : ServerRuntime . Selection , built : T ) {
71+ log . info ( "server runtime selected" , ServerRuntime . attributes ( selection ) )
72+ return built
4773}
4874
4975function createHttpApi ( ) {
@@ -60,11 +86,12 @@ function createHttpApi() {
6086 }
6187}
6288
63- function createHono ( opts : { cors ?: string [ ] } ) {
89+ function createHono ( opts : { cors ?: string [ ] } , selection : ServerRuntime . Selection = ServerRuntime . force ( select ( ) , "hono" ) ) {
90+ const runtimeAttributes = ServerRuntime . attributes ( selection )
6491 const app = new Hono ( )
6592 . onError ( ErrorMiddleware )
6693 . use ( AuthMiddleware )
67- . use ( LoggerMiddleware )
94+ . use ( LoggerMiddleware ( runtimeAttributes ) )
6895 . use ( CompressionMiddleware )
6996 . use ( CorsMiddleware ( opts ) )
7097 . route ( "/global" , GlobalRoutes ( ) )
0 commit comments