2026-05-15 00:00:52 +00:00
|
|
|
import { Config as EffectConfig, Context, Effect, Layer } from "effect"
|
2026-05-14 03:21:26 +00:00
|
|
|
import { NodePath } from "@effect/platform-node"
|
2026-05-09 02:20:50 +00:00
|
|
|
import { HttpApiBuilder, OpenApi } from "effect/unstable/httpapi"
|
2026-05-09 02:21:54 +00:00
|
|
|
import {
|
|
|
|
|
FetchHttpClient,
|
|
|
|
|
HttpClient,
|
|
|
|
|
HttpMiddleware,
|
|
|
|
|
HttpRouter,
|
|
|
|
|
HttpServer,
|
|
|
|
|
HttpServerResponse,
|
|
|
|
|
} from "effect/unstable/http"
|
2026-04-29 20:50:54 +00:00
|
|
|
import * as Socket from "effect/unstable/socket/Socket"
|
2026-04-30 22:49:54 +00:00
|
|
|
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
2026-05-14 17:13:29 +00:00
|
|
|
import { Global } from "@opencode-ai/core/global"
|
2026-05-13 21:39:45 +00:00
|
|
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Account } from "@/account/account"
|
2026-05-14 03:21:26 +00:00
|
|
|
import { AccountRepo } from "@/account/repo"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Agent } from "@/agent/agent"
|
|
|
|
|
import { Auth } from "@/auth"
|
2026-04-27 01:17:48 +00:00
|
|
|
import { Bus } from "@/bus"
|
2026-05-14 03:21:26 +00:00
|
|
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Config } from "@/config/config"
|
|
|
|
|
import { Command } from "@/command"
|
2026-04-27 18:33:33 +00:00
|
|
|
import * as Observability from "@opencode-ai/core/effect/observability"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { File } from "@/file"
|
2026-05-02 04:02:52 +00:00
|
|
|
import { FileWatcher } from "@/file/watcher"
|
2026-05-14 03:21:26 +00:00
|
|
|
import { Git } from "@/git"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Ripgrep } from "@/file/ripgrep"
|
|
|
|
|
import { Format } from "@/format"
|
2026-05-14 22:21:29 +00:00
|
|
|
import { RuntimeFlags } from "@/effect/runtime-flags"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { LSP } from "@/lsp/lsp"
|
|
|
|
|
import { MCP } from "@/mcp"
|
2026-05-14 17:13:29 +00:00
|
|
|
import { McpAuth } from "@/mcp/auth"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Permission } from "@/permission"
|
|
|
|
|
import { Installation } from "@/installation"
|
2026-05-03 00:39:20 +00:00
|
|
|
import { InstanceLayer } from "@/project/instance-layer"
|
2026-05-14 03:21:26 +00:00
|
|
|
import { Npm } from "@opencode-ai/core/npm"
|
|
|
|
|
import { Env } from "@/env"
|
2026-05-02 04:02:52 +00:00
|
|
|
import { Plugin } from "@/plugin"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Project } from "@/project/project"
|
|
|
|
|
import { ProviderAuth } from "@/provider/auth"
|
2026-05-14 00:58:24 +00:00
|
|
|
import { ModelsDev } from "@opencode-ai/core/models"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Provider } from "@/provider/provider"
|
2026-04-27 01:05:16 +00:00
|
|
|
import { Pty } from "@/pty"
|
2026-05-04 02:56:14 +00:00
|
|
|
import { PtyTicket } from "@/pty/ticket"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Question } from "@/question"
|
2026-04-27 18:33:33 +00:00
|
|
|
import { Session } from "@/session/session"
|
2026-04-30 17:53:26 +00:00
|
|
|
import { SessionCompaction } from "@/session/compaction"
|
|
|
|
|
import { SessionPrompt } from "@/session/prompt"
|
2026-05-14 17:13:29 +00:00
|
|
|
import { SessionProcessor } from "@/session/processor"
|
|
|
|
|
import { Instruction } from "@/session/instruction"
|
2026-04-30 17:53:26 +00:00
|
|
|
import { SessionRevert } from "@/session/revert"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { SessionRunState } from "@/session/run-state"
|
|
|
|
|
import { SessionStatus } from "@/session/status"
|
|
|
|
|
import { SessionSummary } from "@/session/summary"
|
|
|
|
|
import { Todo } from "@/session/todo"
|
2026-04-30 17:53:26 +00:00
|
|
|
import { SessionShare } from "@/share/session"
|
2026-05-02 04:02:52 +00:00
|
|
|
import { ShareNext } from "@/share/share-next"
|
2026-05-15 00:50:23 +00:00
|
|
|
import { EventV2Bridge } from "@/event-v2-bridge"
|
2026-05-14 17:13:29 +00:00
|
|
|
import { LLM } from "@/session/llm"
|
|
|
|
|
import { SystemPrompt } from "@/session/system"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Skill } from "@/skill"
|
2026-05-14 17:13:29 +00:00
|
|
|
import { Discovery } from "@/skill/discovery"
|
2026-05-02 04:02:52 +00:00
|
|
|
import { Snapshot } from "@/snapshot"
|
2026-05-14 17:13:29 +00:00
|
|
|
import { Storage } from "@/storage/storage"
|
2026-04-30 20:45:26 +00:00
|
|
|
import { SyncEvent } from "@/sync"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { ToolRegistry } from "@/tool/registry"
|
2026-05-14 17:13:29 +00:00
|
|
|
import { Truncate } from "@/tool/truncate"
|
2026-04-16 02:50:22 +00:00
|
|
|
import { lazy } from "@/util/lazy"
|
2026-04-28 20:31:45 +00:00
|
|
|
import { Vcs } from "@/project/vcs"
|
|
|
|
|
import { Worktree } from "@/worktree"
|
2026-04-30 17:57:25 +00:00
|
|
|
import { Workspace } from "@/control-plane/workspace"
|
2026-05-13 21:39:45 +00:00
|
|
|
import { SimulationFileSystem } from "@/testing/simulation/filesystem"
|
2026-05-14 00:02:16 +00:00
|
|
|
import { SimulationNetwork } from "@/testing/simulation/network"
|
2026-05-14 03:21:26 +00:00
|
|
|
import { SimulationNetworkRoutes } from "@/testing/simulation/network-routes"
|
2026-05-14 13:12:43 +00:00
|
|
|
import { SimulationProvider } from "@/testing/simulation/provider"
|
2026-05-15 19:27:44 +00:00
|
|
|
import { SimulationSpawner } from "@/testing/simulation/spawner"
|
2026-05-14 03:32:50 +00:00
|
|
|
import { Simulation } from "@/testing/simulation/service"
|
2026-05-04 02:56:14 +00:00
|
|
|
import { CorsConfig, isAllowedCorsOrigin, type CorsOptions } from "@/server/cors"
|
2026-05-03 12:58:34 +00:00
|
|
|
import { serveUIEffect } from "@/server/shared/ui"
|
2026-05-03 13:58:31 +00:00
|
|
|
import { ServerAuth } from "@/server/auth"
|
2026-04-29 13:34:50 +00:00
|
|
|
import { InstanceHttpApi, RootHttpApi } from "./api"
|
2026-05-15 19:27:44 +00:00
|
|
|
import { InMemoryFs } from "just-bash"
|
2026-05-09 02:20:50 +00:00
|
|
|
import { PublicApi } from "./public"
|
2026-05-03 13:58:31 +00:00
|
|
|
import { authorizationLayer, authorizationRouterMiddleware } from "./middleware/authorization"
|
2026-05-14 03:41:17 +00:00
|
|
|
import { EventApi } from "./groups/event"
|
|
|
|
|
import { eventHandlers } from "./handlers/event"
|
2026-04-29 13:34:50 +00:00
|
|
|
import { configHandlers } from "./handlers/config"
|
|
|
|
|
import { controlHandlers } from "./handlers/control"
|
|
|
|
|
import { experimentalHandlers } from "./handlers/experimental"
|
|
|
|
|
import { fileHandlers } from "./handlers/file"
|
|
|
|
|
import { globalHandlers } from "./handlers/global"
|
|
|
|
|
import { instanceHandlers } from "./handlers/instance"
|
|
|
|
|
import { mcpHandlers } from "./handlers/mcp"
|
|
|
|
|
import { permissionHandlers } from "./handlers/permission"
|
|
|
|
|
import { projectHandlers } from "./handlers/project"
|
|
|
|
|
import { providerHandlers } from "./handlers/provider"
|
|
|
|
|
import { ptyConnectRoute, ptyHandlers } from "./handlers/pty"
|
|
|
|
|
import { questionHandlers } from "./handlers/question"
|
|
|
|
|
import { sessionHandlers } from "./handlers/session"
|
|
|
|
|
import { syncHandlers } from "./handlers/sync"
|
|
|
|
|
import { tuiHandlers } from "./handlers/tui"
|
2026-05-03 02:09:48 +00:00
|
|
|
import { v2Handlers } from "./handlers/v2"
|
2026-04-29 13:34:50 +00:00
|
|
|
import { workspaceHandlers } from "./handlers/workspace"
|
2026-04-29 20:50:54 +00:00
|
|
|
import { instanceContextLayer, instanceRouterMiddleware } from "./middleware/instance-context"
|
|
|
|
|
import { workspaceRouterMiddleware, workspaceRoutingLayer } from "./middleware/workspace-routing"
|
2026-04-25 19:24:07 +00:00
|
|
|
import { disposeMiddleware } from "./lifecycle"
|
2026-05-14 03:32:50 +00:00
|
|
|
import { simulationRoute } from "./simulation"
|
2026-04-25 17:29:52 +00:00
|
|
|
import { memoMap } from "@opencode-ai/core/effect/memo-map"
|
2026-05-09 03:06:00 +00:00
|
|
|
import { compressionLayer } from "./middleware/compression"
|
2026-05-09 03:17:47 +00:00
|
|
|
import { corsVaryFix } from "./middleware/cors-vary"
|
2026-05-04 22:29:00 +00:00
|
|
|
import { errorLayer } from "./middleware/error"
|
2026-05-09 02:45:54 +00:00
|
|
|
import { fenceLayer } from "./middleware/fence"
|
2026-05-10 16:21:32 +00:00
|
|
|
import { schemaErrorLayer } from "./middleware/schema-error"
|
2026-04-15 21:28:01 +00:00
|
|
|
|
2026-04-30 02:22:32 +00:00
|
|
|
export const context = Context.makeUnsafe<unknown>(new Map())
|
2026-04-28 15:02:35 +00:00
|
|
|
|
2026-05-01 01:26:32 +00:00
|
|
|
const cors = (corsOptions?: CorsOptions) =>
|
|
|
|
|
HttpRouter.middleware(
|
|
|
|
|
HttpMiddleware.cors({
|
|
|
|
|
allowedOrigins: (origin) => isAllowedCorsOrigin(origin, corsOptions),
|
|
|
|
|
maxAge: 86_400,
|
|
|
|
|
}),
|
|
|
|
|
{ global: true },
|
|
|
|
|
)
|
2026-04-30 15:07:00 +00:00
|
|
|
|
2026-05-08 17:06:00 +00:00
|
|
|
// Route tree:
|
|
|
|
|
// - rootApiRoutes: typed /global/* and control routes; auth is declared by RootHttpApi.
|
|
|
|
|
// - eventApiRoutes/rawInstanceRoutes: raw instance routes; auth and workspace routing happen as router middleware.
|
|
|
|
|
// - instanceApiRoutes: schema routes; auth is declared on each group and workspace context is provided below.
|
|
|
|
|
// - uiRoute: raw catch-all fallback; auth is router middleware so public static assets can bypass it.
|
|
|
|
|
const authOnlyRouterLayer = authorizationRouterMiddleware.layer.pipe(Layer.provide(ServerAuth.Config.defaultLayer))
|
|
|
|
|
const httpApiAuthLayer = authorizationLayer.pipe(Layer.provide(ServerAuth.Config.defaultLayer))
|
2026-05-08 16:39:11 +00:00
|
|
|
const rootApiRoutes = HttpApiBuilder.layer(RootHttpApi).pipe(
|
|
|
|
|
Layer.provide([controlHandlers, globalHandlers]),
|
2026-05-10 16:21:32 +00:00
|
|
|
Layer.provide(schemaErrorLayer),
|
2026-05-08 17:06:00 +00:00
|
|
|
Layer.provide(httpApiAuthLayer),
|
2026-05-08 16:39:11 +00:00
|
|
|
)
|
2026-05-01 00:02:46 +00:00
|
|
|
const instanceRouterLayer = authorizationRouterMiddleware
|
|
|
|
|
.combine(instanceRouterMiddleware)
|
|
|
|
|
.combine(workspaceRouterMiddleware)
|
2026-05-03 13:58:31 +00:00
|
|
|
.layer.pipe(Layer.provide(Socket.layerWebSocketConstructorGlobal), Layer.provide(ServerAuth.Config.defaultLayer))
|
2026-05-01 00:02:46 +00:00
|
|
|
const eventApiRoutes = HttpApiBuilder.layer(EventApi).pipe(
|
|
|
|
|
Layer.provide(eventHandlers),
|
|
|
|
|
Layer.provide(instanceRouterLayer),
|
|
|
|
|
)
|
2026-04-29 13:34:50 +00:00
|
|
|
const instanceApiRoutes = HttpApiBuilder.layer(InstanceHttpApi).pipe(
|
|
|
|
|
Layer.provide([
|
|
|
|
|
configHandlers,
|
|
|
|
|
experimentalHandlers,
|
|
|
|
|
fileHandlers,
|
|
|
|
|
instanceHandlers,
|
|
|
|
|
mcpHandlers,
|
|
|
|
|
projectHandlers,
|
|
|
|
|
ptyHandlers,
|
|
|
|
|
questionHandlers,
|
|
|
|
|
permissionHandlers,
|
|
|
|
|
providerHandlers,
|
|
|
|
|
sessionHandlers,
|
|
|
|
|
syncHandlers,
|
2026-05-03 02:09:48 +00:00
|
|
|
v2Handlers,
|
2026-04-29 13:34:50 +00:00
|
|
|
tuiHandlers,
|
|
|
|
|
workspaceHandlers,
|
|
|
|
|
]),
|
2026-04-28 20:31:45 +00:00
|
|
|
)
|
|
|
|
|
|
2026-05-01 00:03:55 +00:00
|
|
|
const rawInstanceRoutes = Layer.mergeAll(ptyConnectRoute).pipe(Layer.provide(instanceRouterLayer))
|
2026-04-29 13:34:50 +00:00
|
|
|
const instanceRoutes = Layer.mergeAll(rawInstanceRoutes, instanceApiRoutes).pipe(
|
2026-04-29 20:50:54 +00:00
|
|
|
Layer.provide([
|
2026-05-08 17:06:00 +00:00
|
|
|
httpApiAuthLayer,
|
2026-04-29 20:50:54 +00:00
|
|
|
workspaceRoutingLayer.pipe(Layer.provide(Socket.layerWebSocketConstructorGlobal)),
|
|
|
|
|
instanceContextLayer,
|
2026-05-10 16:21:32 +00:00
|
|
|
schemaErrorLayer,
|
2026-04-29 20:50:54 +00:00
|
|
|
]),
|
2026-04-28 20:31:45 +00:00
|
|
|
)
|
|
|
|
|
|
2026-05-09 03:41:20 +00:00
|
|
|
// `OpenApi.fromApi` is non-trivial; defer until /doc is actually hit so
|
|
|
|
|
// processes that never serve it (CLI, scripts) don't pay at module load.
|
|
|
|
|
// `HttpServerResponse.jsonUnsafe` runs JSON.stringify eagerly, so caching
|
|
|
|
|
// the response also caches the serialized body — every /doc request reuses
|
|
|
|
|
// the same Uint8Array instead of re-stringifying the spec.
|
|
|
|
|
const docResponse = lazy(() => HttpServerResponse.jsonUnsafe(OpenApi.fromApi(PublicApi)))
|
2026-05-09 02:20:50 +00:00
|
|
|
|
2026-05-09 03:42:23 +00:00
|
|
|
const docRoute = HttpRouter.use((router) => router.add("GET", "/doc", () => Effect.succeed(docResponse()))).pipe(
|
|
|
|
|
Layer.provide(authOnlyRouterLayer),
|
|
|
|
|
)
|
2026-05-09 02:20:50 +00:00
|
|
|
|
2026-04-30 23:36:57 +00:00
|
|
|
const uiRoute = HttpRouter.use((router) =>
|
2026-04-30 23:24:10 +00:00
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const fs = yield* AppFileSystem.Service
|
|
|
|
|
const client = yield* HttpClient.HttpClient
|
2026-05-14 22:21:29 +00:00
|
|
|
const flags = yield* RuntimeFlags.Service
|
|
|
|
|
yield* router.add("*", "/*", (request) =>
|
|
|
|
|
serveUIEffect(request, { fs, client, disableEmbeddedWebUi: flags.disableEmbeddedWebUi }),
|
|
|
|
|
)
|
2026-04-30 23:24:10 +00:00
|
|
|
}),
|
2026-05-08 17:06:00 +00:00
|
|
|
).pipe(Layer.provide(authOnlyRouterLayer))
|
2026-04-30 21:43:18 +00:00
|
|
|
|
2026-05-15 19:27:44 +00:00
|
|
|
const simulationShareNextLayer = Layer.succeed(
|
|
|
|
|
ShareNext.Service,
|
|
|
|
|
ShareNext.Service.of({
|
|
|
|
|
init: () => Effect.void,
|
|
|
|
|
url: () => Effect.succeed("https://opncd.ai"),
|
|
|
|
|
request: () =>
|
|
|
|
|
Effect.succeed({
|
|
|
|
|
headers: {},
|
|
|
|
|
baseUrl: "https://opncd.ai",
|
|
|
|
|
api: {
|
|
|
|
|
create: "/api/shares",
|
|
|
|
|
sync: (shareID) => `/api/shares/${shareID}/sync`,
|
|
|
|
|
remove: (shareID) => `/api/shares/${shareID}`,
|
|
|
|
|
data: (shareID) => `/api/shares/${shareID}/data`,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
create: () => Effect.succeed({ id: "", url: "", secret: "" }),
|
|
|
|
|
remove: () => Effect.void,
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-15 00:00:52 +00:00
|
|
|
type RouteRequirements =
|
|
|
|
|
| HttpRouter.HttpRouter
|
|
|
|
|
| HttpRouter.Request<"Error", unknown>
|
|
|
|
|
| HttpRouter.Request<"GlobalError", unknown>
|
|
|
|
|
| HttpRouter.Request<"Requires", unknown>
|
|
|
|
|
| HttpRouter.Request<"GlobalRequires", never>
|
|
|
|
|
|
2026-05-14 03:21:26 +00:00
|
|
|
function createProductionRoutes(
|
2026-05-15 00:00:52 +00:00
|
|
|
corsOptions?: CorsOptions,
|
|
|
|
|
): Layer.Layer<never, EffectConfig.ConfigError, RouteRequirements> {
|
2026-05-09 02:20:50 +00:00
|
|
|
return Layer.mergeAll(rootApiRoutes, eventApiRoutes, instanceRoutes, docRoute, uiRoute).pipe(
|
2026-05-01 01:26:32 +00:00
|
|
|
Layer.provide([
|
2026-05-04 22:29:00 +00:00
|
|
|
errorLayer,
|
2026-05-09 03:06:00 +00:00
|
|
|
compressionLayer,
|
2026-05-09 03:17:47 +00:00
|
|
|
corsVaryFix,
|
2026-05-09 02:45:54 +00:00
|
|
|
fenceLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
cors(corsOptions),
|
|
|
|
|
Account.defaultLayer,
|
|
|
|
|
Agent.defaultLayer,
|
|
|
|
|
Auth.defaultLayer,
|
|
|
|
|
Command.defaultLayer,
|
|
|
|
|
Config.defaultLayer,
|
|
|
|
|
File.defaultLayer,
|
2026-05-02 04:02:52 +00:00
|
|
|
FileWatcher.defaultLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
Format.defaultLayer,
|
|
|
|
|
LSP.defaultLayer,
|
|
|
|
|
Installation.defaultLayer,
|
|
|
|
|
MCP.defaultLayer,
|
2026-05-02 17:59:08 +00:00
|
|
|
ModelsDev.defaultLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
Permission.defaultLayer,
|
2026-05-02 04:02:52 +00:00
|
|
|
Plugin.defaultLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
Project.defaultLayer,
|
|
|
|
|
ProviderAuth.defaultLayer,
|
|
|
|
|
Provider.defaultLayer,
|
|
|
|
|
Pty.defaultLayer,
|
2026-05-04 02:56:14 +00:00
|
|
|
PtyTicket.defaultLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
Question.defaultLayer,
|
|
|
|
|
Ripgrep.defaultLayer,
|
2026-05-14 22:21:29 +00:00
|
|
|
RuntimeFlags.defaultLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
Session.defaultLayer,
|
|
|
|
|
SessionCompaction.defaultLayer,
|
|
|
|
|
SessionPrompt.defaultLayer,
|
|
|
|
|
SessionRevert.defaultLayer,
|
|
|
|
|
SessionShare.defaultLayer,
|
|
|
|
|
SessionRunState.defaultLayer,
|
|
|
|
|
SessionStatus.defaultLayer,
|
|
|
|
|
SessionSummary.defaultLayer,
|
2026-05-02 04:02:52 +00:00
|
|
|
ShareNext.defaultLayer,
|
|
|
|
|
Snapshot.defaultLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
SyncEvent.defaultLayer,
|
2026-05-15 00:50:23 +00:00
|
|
|
EventV2Bridge.defaultLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
Skill.defaultLayer,
|
|
|
|
|
Todo.defaultLayer,
|
|
|
|
|
ToolRegistry.defaultLayer,
|
|
|
|
|
Vcs.defaultLayer,
|
|
|
|
|
Workspace.defaultLayer,
|
2026-05-03 00:39:20 +00:00
|
|
|
Worktree.appLayer,
|
2026-05-01 01:26:32 +00:00
|
|
|
Bus.layer,
|
2026-05-14 03:21:26 +00:00
|
|
|
AppFileSystem.defaultLayer,
|
|
|
|
|
FetchHttpClient.layer,
|
2026-05-01 01:26:32 +00:00
|
|
|
HttpServer.layerServices,
|
|
|
|
|
]),
|
2026-05-15 00:00:52 +00:00
|
|
|
Layer.provide(Layer.succeed(CorsConfig)(corsOptions)),
|
|
|
|
|
Layer.provide(InstanceLayer.layer),
|
|
|
|
|
Layer.provide(Observability.layer),
|
2026-05-01 01:26:32 +00:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 03:21:26 +00:00
|
|
|
export function createSimulatedRoutes(corsOptions?: CorsOptions): ReturnType<typeof createProductionRoutes> {
|
2026-05-15 19:27:44 +00:00
|
|
|
const fs = new InMemoryFs()
|
2026-05-14 03:21:26 +00:00
|
|
|
const simulationBoundary = Layer.mergeAll(
|
2026-05-15 19:27:44 +00:00
|
|
|
SimulationFileSystem.layer({ root: "/opencode", fs }),
|
|
|
|
|
SimulationSpawner.layer({ root: "/opencode", fs }),
|
2026-05-14 03:21:26 +00:00
|
|
|
SimulationNetwork.layer({ entries: SimulationNetworkRoutes.defaults(), allowLoopback: true }),
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-15 19:27:44 +00:00
|
|
|
const simulatedRoutes = Layer.mergeAll(
|
|
|
|
|
rootApiRoutes,
|
|
|
|
|
eventApiRoutes,
|
|
|
|
|
instanceRoutes,
|
|
|
|
|
docRoute,
|
|
|
|
|
uiRoute,
|
|
|
|
|
simulationRoute,
|
|
|
|
|
)
|
2026-05-14 17:13:29 +00:00
|
|
|
|
|
|
|
|
const withRouteAndLeafServices = simulatedRoutes.pipe(
|
|
|
|
|
Layer.provideMerge(errorLayer),
|
|
|
|
|
Layer.provideMerge(compressionLayer),
|
|
|
|
|
Layer.provideMerge(corsVaryFix),
|
|
|
|
|
Layer.provideMerge(fenceLayer),
|
|
|
|
|
Layer.provideMerge(cors(corsOptions)),
|
|
|
|
|
Layer.provideMerge(runtime),
|
|
|
|
|
Layer.provideMerge(File.layer),
|
|
|
|
|
Layer.provideMerge(FileWatcher.layer),
|
|
|
|
|
Layer.provideMerge(Installation.layer),
|
|
|
|
|
Layer.provideMerge(ModelsDev.layer),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const withEndpointServices = withRouteAndLeafServices.pipe(
|
|
|
|
|
Layer.provideMerge(ProviderAuth.layer),
|
|
|
|
|
Layer.provideMerge(Pty.layer),
|
|
|
|
|
Layer.provideMerge(PtyTicket.layer),
|
|
|
|
|
Layer.provideMerge(SessionShare.layer),
|
2026-05-15 19:27:44 +00:00
|
|
|
Layer.provideMerge(simulationShareNextLayer),
|
2026-05-14 17:13:29 +00:00
|
|
|
Layer.provideMerge(Workspace.layer),
|
|
|
|
|
Layer.provideMerge(Worktree.layer),
|
|
|
|
|
Layer.provideMerge(HttpServer.layerServices),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const withSessionAndToolConsumers = withEndpointServices.pipe(
|
|
|
|
|
Layer.provideMerge(Project.layer),
|
|
|
|
|
Layer.provideMerge(SessionPrompt.layer),
|
|
|
|
|
Layer.provideMerge(SessionRevert.layer),
|
|
|
|
|
Layer.provideMerge(ToolRegistry.layer),
|
|
|
|
|
Layer.provideMerge(SessionCompaction.layer),
|
|
|
|
|
Layer.provideMerge(SessionProcessor.layer),
|
|
|
|
|
Layer.provideMerge(SessionSummary.layer),
|
|
|
|
|
Layer.provideMerge(Agent.layer),
|
|
|
|
|
Layer.provideMerge(Command.layer),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const withToolDependencies = withSessionAndToolConsumers.pipe(
|
|
|
|
|
Layer.provideMerge(Vcs.layer),
|
|
|
|
|
Layer.provideMerge(Ripgrep.layer),
|
|
|
|
|
Layer.provideMerge(Format.layer),
|
|
|
|
|
Layer.provideMerge(Todo.layer),
|
|
|
|
|
Layer.provideMerge(Question.layer),
|
|
|
|
|
Layer.provideMerge(Truncate.layer),
|
|
|
|
|
Layer.provideMerge(Instruction.layer),
|
|
|
|
|
Layer.provideMerge(Snapshot.layer),
|
|
|
|
|
Layer.provideMerge(LSP.layer),
|
|
|
|
|
Layer.provideMerge(MCP.layer),
|
|
|
|
|
Layer.provideMerge(SyncEvent.layer),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const withSessionProviderDependencies = withToolDependencies.pipe(
|
|
|
|
|
Layer.provideMerge(McpAuth.layer),
|
|
|
|
|
Layer.provideMerge(SessionRunState.layer),
|
|
|
|
|
Layer.provideMerge(SessionStatus.layer),
|
|
|
|
|
Layer.provideMerge(Session.layer),
|
|
|
|
|
Layer.provideMerge(Storage.layer),
|
|
|
|
|
Layer.provideMerge(LLM.layer),
|
|
|
|
|
Layer.provideMerge(SystemPrompt.layer),
|
|
|
|
|
Layer.provideMerge(Skill.layer),
|
|
|
|
|
Layer.provideMerge(Discovery.layer),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const withCoreAppServices = withSessionProviderDependencies.pipe(
|
|
|
|
|
Layer.provideMerge(Plugin.layer),
|
|
|
|
|
Layer.provideMerge(Permission.layer),
|
|
|
|
|
Layer.provideMerge(SimulationProvider.layer),
|
|
|
|
|
Layer.provideMerge(Simulation.layer),
|
|
|
|
|
Layer.provideMerge(Config.layer),
|
|
|
|
|
Layer.provideMerge(Account.layer),
|
|
|
|
|
Layer.provideMerge(Auth.layer),
|
2026-05-14 03:21:26 +00:00
|
|
|
Layer.provideMerge(AccountRepo.layer),
|
2026-05-14 17:13:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return withCoreAppServices.pipe(
|
2026-05-14 03:21:26 +00:00
|
|
|
Layer.provideMerge(Git.layer),
|
|
|
|
|
Layer.provideMerge(Npm.layer),
|
|
|
|
|
Layer.provideMerge(Env.layer),
|
2026-05-14 17:13:29 +00:00
|
|
|
Layer.provideMerge(Bus.layer),
|
|
|
|
|
Layer.provideMerge(Global.layer),
|
|
|
|
|
Layer.provideMerge(NodePath.layer),
|
2026-05-14 03:21:26 +00:00
|
|
|
Layer.provideMerge(simulationBoundary),
|
|
|
|
|
Layer.provideMerge(Layer.succeed(CorsConfig)(corsOptions)),
|
|
|
|
|
Layer.provideMerge(InstanceLayer.layer),
|
|
|
|
|
Layer.provideMerge(Observability.layer),
|
|
|
|
|
) as ReturnType<typeof createProductionRoutes>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createRoutes(corsOptions?: CorsOptions) {
|
2026-05-14 17:13:29 +00:00
|
|
|
if (Flag.OPENCODE_SIMULATION_BACKEND) {
|
2026-05-14 03:21:26 +00:00
|
|
|
return createSimulatedRoutes(corsOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return createProductionRoutes(corsOptions)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-01 01:26:32 +00:00
|
|
|
export const routes = createRoutes()
|
2026-04-15 21:28:01 +00:00
|
|
|
|
2026-05-15 00:00:52 +00:00
|
|
|
export const webHandler = lazy(() =>
|
2026-04-17 01:01:24 +00:00
|
|
|
HttpRouter.toWebHandler(routes, {
|
2026-05-15 00:00:52 +00:00
|
|
|
disableLogger: true,
|
2026-04-17 01:01:24 +00:00
|
|
|
memoMap,
|
2026-04-25 19:24:07 +00:00
|
|
|
middleware: disposeMiddleware,
|
2026-04-17 01:01:24 +00:00
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-15 00:00:52 +00:00
|
|
|
export * as HttpApiApp from "./server"
|