11import { describeRoute , resolver , validator } from "hono-openapi"
22import { Hono } from "hono"
33import type { UpgradeWebSocket } from "hono/ws"
4- import { Effect } from "effect"
4+ import { Context , Effect } from "effect"
5+ import { Flag } from "@opencode-ai/core/flag/flag"
56import z from "zod"
67import { Format } from "@/format"
78import { TuiRoutes } from "./tui"
@@ -26,10 +27,133 @@ import { EventRoutes } from "./event"
2627import { SyncRoutes } from "./sync"
2728import { InstanceMiddleware } from "./middleware"
2829import { jsonRequest } from "./trace"
30+ import { ExperimentalHttpApiServer } from "./httpapi/server"
31+ import { EventPaths } from "./httpapi/event"
32+ import { ExperimentalPaths } from "./httpapi/experimental"
33+ import { FilePaths } from "./httpapi/file"
34+ import { InstancePaths } from "./httpapi/instance"
35+ import { McpPaths } from "./httpapi/mcp"
36+ import { PtyPaths } from "./httpapi/pty"
37+ import { SessionPaths } from "./httpapi/session"
38+ import { SyncPaths } from "./httpapi/sync"
39+ import { TuiPaths } from "./httpapi/tui"
40+ import { WorkspacePaths } from "./httpapi/workspace"
2941
3042export const InstanceRoutes = ( upgrade : UpgradeWebSocket ) : Hono => {
3143 const app = new Hono ( )
3244
45+ if ( Flag . OPENCODE_EXPERIMENTAL_HTTPAPI ) {
46+ const handler = ExperimentalHttpApiServer . webHandler ( ) . handler
47+ const context = Context . empty ( ) as Context . Context < unknown >
48+ app . all ( "/api/*" , ( c ) => handler ( c . req . raw , context ) )
49+ app . get ( EventPaths . event , ( c ) => handler ( c . req . raw , context ) )
50+ app . get ( "/question" , ( c ) => handler ( c . req . raw , context ) )
51+ app . post ( "/question/:requestID/reply" , ( c ) => handler ( c . req . raw , context ) )
52+ app . post ( "/question/:requestID/reject" , ( c ) => handler ( c . req . raw , context ) )
53+ app . get ( "/permission" , ( c ) => handler ( c . req . raw , context ) )
54+ app . post ( "/permission/:requestID/reply" , ( c ) => handler ( c . req . raw , context ) )
55+ app . get ( "/config" , ( c ) => handler ( c . req . raw , context ) )
56+ app . patch ( "/config" , ( c ) => handler ( c . req . raw , context ) )
57+ app . get ( "/config/providers" , ( c ) => handler ( c . req . raw , context ) )
58+ app . get ( ExperimentalPaths . console , ( c ) => handler ( c . req . raw , context ) )
59+ app . get ( ExperimentalPaths . consoleOrgs , ( c ) => handler ( c . req . raw , context ) )
60+ app . post ( ExperimentalPaths . consoleSwitch , ( c ) => handler ( c . req . raw , context ) )
61+ app . get ( ExperimentalPaths . tool , ( c ) => handler ( c . req . raw , context ) )
62+ app . get ( ExperimentalPaths . toolIDs , ( c ) => handler ( c . req . raw , context ) )
63+ app . get ( ExperimentalPaths . worktree , ( c ) => handler ( c . req . raw , context ) )
64+ app . post ( ExperimentalPaths . worktree , ( c ) => handler ( c . req . raw , context ) )
65+ app . delete ( ExperimentalPaths . worktree , ( c ) => handler ( c . req . raw , context ) )
66+ app . post ( ExperimentalPaths . worktreeReset , ( c ) => handler ( c . req . raw , context ) )
67+ app . get ( ExperimentalPaths . session , ( c ) => handler ( c . req . raw , context ) )
68+ app . get ( ExperimentalPaths . resource , ( c ) => handler ( c . req . raw , context ) )
69+ app . get ( "/provider" , ( c ) => handler ( c . req . raw , context ) )
70+ app . get ( "/provider/auth" , ( c ) => handler ( c . req . raw , context ) )
71+ app . post ( "/provider/:providerID/oauth/authorize" , ( c ) => handler ( c . req . raw , context ) )
72+ app . post ( "/provider/:providerID/oauth/callback" , ( c ) => handler ( c . req . raw , context ) )
73+ app . get ( "/project" , ( c ) => handler ( c . req . raw , context ) )
74+ app . get ( "/project/current" , ( c ) => handler ( c . req . raw , context ) )
75+ app . post ( "/project/git/init" , ( c ) => handler ( c . req . raw , context ) )
76+ app . patch ( "/project/:projectID" , ( c ) => handler ( c . req . raw , context ) )
77+ app . get ( FilePaths . findText , ( c ) => handler ( c . req . raw , context ) )
78+ app . get ( FilePaths . findFile , ( c ) => handler ( c . req . raw , context ) )
79+ app . get ( FilePaths . findSymbol , ( c ) => handler ( c . req . raw , context ) )
80+ app . get ( FilePaths . list , ( c ) => handler ( c . req . raw , context ) )
81+ app . get ( FilePaths . content , ( c ) => handler ( c . req . raw , context ) )
82+ app . get ( FilePaths . status , ( c ) => handler ( c . req . raw , context ) )
83+ app . get ( InstancePaths . path , ( c ) => handler ( c . req . raw , context ) )
84+ app . post ( InstancePaths . dispose , ( c ) => handler ( c . req . raw , context ) )
85+ app . get ( InstancePaths . vcs , ( c ) => handler ( c . req . raw , context ) )
86+ app . get ( InstancePaths . vcsDiff , ( c ) => handler ( c . req . raw , context ) )
87+ app . get ( InstancePaths . command , ( c ) => handler ( c . req . raw , context ) )
88+ app . get ( InstancePaths . agent , ( c ) => handler ( c . req . raw , context ) )
89+ app . get ( InstancePaths . skill , ( c ) => handler ( c . req . raw , context ) )
90+ app . get ( InstancePaths . lsp , ( c ) => handler ( c . req . raw , context ) )
91+ app . get ( InstancePaths . formatter , ( c ) => handler ( c . req . raw , context ) )
92+ app . get ( McpPaths . status , ( c ) => handler ( c . req . raw , context ) )
93+ app . post ( McpPaths . status , ( c ) => handler ( c . req . raw , context ) )
94+ app . post ( McpPaths . auth , ( c ) => handler ( c . req . raw , context ) )
95+ app . post ( McpPaths . authCallback , ( c ) => handler ( c . req . raw , context ) )
96+ app . post ( McpPaths . authAuthenticate , ( c ) => handler ( c . req . raw , context ) )
97+ app . delete ( McpPaths . auth , ( c ) => handler ( c . req . raw , context ) )
98+ app . post ( McpPaths . connect , ( c ) => handler ( c . req . raw , context ) )
99+ app . post ( McpPaths . disconnect , ( c ) => handler ( c . req . raw , context ) )
100+ app . post ( SyncPaths . start , ( c ) => handler ( c . req . raw , context ) )
101+ app . post ( SyncPaths . replay , ( c ) => handler ( c . req . raw , context ) )
102+ app . post ( SyncPaths . history , ( c ) => handler ( c . req . raw , context ) )
103+ app . get ( PtyPaths . list , ( c ) => handler ( c . req . raw , context ) )
104+ app . post ( PtyPaths . create , ( c ) => handler ( c . req . raw , context ) )
105+ app . get ( PtyPaths . get , ( c ) => handler ( c . req . raw , context ) )
106+ app . put ( PtyPaths . update , ( c ) => handler ( c . req . raw , context ) )
107+ app . delete ( PtyPaths . remove , ( c ) => handler ( c . req . raw , context ) )
108+ app . get ( PtyPaths . connect , ( c ) => handler ( c . req . raw , context ) )
109+ app . get ( SessionPaths . list , ( c ) => handler ( c . req . raw , context ) )
110+ app . get ( SessionPaths . status , ( c ) => handler ( c . req . raw , context ) )
111+ app . get ( SessionPaths . get , ( c ) => handler ( c . req . raw , context ) )
112+ app . get ( SessionPaths . children , ( c ) => handler ( c . req . raw , context ) )
113+ app . get ( SessionPaths . todo , ( c ) => handler ( c . req . raw , context ) )
114+ app . get ( SessionPaths . diff , ( c ) => handler ( c . req . raw , context ) )
115+ app . get ( SessionPaths . messages , ( c ) => handler ( c . req . raw , context ) )
116+ app . get ( SessionPaths . message , ( c ) => handler ( c . req . raw , context ) )
117+ app . post ( SessionPaths . create , ( c ) => handler ( c . req . raw , context ) )
118+ app . delete ( SessionPaths . remove , ( c ) => handler ( c . req . raw , context ) )
119+ app . patch ( SessionPaths . update , ( c ) => handler ( c . req . raw , context ) )
120+ app . post ( SessionPaths . init , ( c ) => handler ( c . req . raw , context ) )
121+ app . post ( SessionPaths . fork , ( c ) => handler ( c . req . raw , context ) )
122+ app . post ( SessionPaths . abort , ( c ) => handler ( c . req . raw , context ) )
123+ app . post ( SessionPaths . share , ( c ) => handler ( c . req . raw , context ) )
124+ app . delete ( SessionPaths . share , ( c ) => handler ( c . req . raw , context ) )
125+ app . post ( SessionPaths . summarize , ( c ) => handler ( c . req . raw , context ) )
126+ app . post ( SessionPaths . prompt , ( c ) => handler ( c . req . raw , context ) )
127+ app . post ( SessionPaths . promptAsync , ( c ) => handler ( c . req . raw , context ) )
128+ app . post ( SessionPaths . command , ( c ) => handler ( c . req . raw , context ) )
129+ app . post ( SessionPaths . shell , ( c ) => handler ( c . req . raw , context ) )
130+ app . post ( SessionPaths . revert , ( c ) => handler ( c . req . raw , context ) )
131+ app . post ( SessionPaths . unrevert , ( c ) => handler ( c . req . raw , context ) )
132+ app . post ( SessionPaths . permissions , ( c ) => handler ( c . req . raw , context ) )
133+ app . delete ( SessionPaths . deleteMessage , ( c ) => handler ( c . req . raw , context ) )
134+ app . delete ( SessionPaths . deletePart , ( c ) => handler ( c . req . raw , context ) )
135+ app . patch ( SessionPaths . updatePart , ( c ) => handler ( c . req . raw , context ) )
136+ app . post ( TuiPaths . appendPrompt , ( c ) => handler ( c . req . raw , context ) )
137+ app . post ( TuiPaths . openHelp , ( c ) => handler ( c . req . raw , context ) )
138+ app . post ( TuiPaths . openSessions , ( c ) => handler ( c . req . raw , context ) )
139+ app . post ( TuiPaths . openThemes , ( c ) => handler ( c . req . raw , context ) )
140+ app . post ( TuiPaths . openModels , ( c ) => handler ( c . req . raw , context ) )
141+ app . post ( TuiPaths . submitPrompt , ( c ) => handler ( c . req . raw , context ) )
142+ app . post ( TuiPaths . clearPrompt , ( c ) => handler ( c . req . raw , context ) )
143+ app . post ( TuiPaths . executeCommand , ( c ) => handler ( c . req . raw , context ) )
144+ app . post ( TuiPaths . showToast , ( c ) => handler ( c . req . raw , context ) )
145+ app . post ( TuiPaths . publish , ( c ) => handler ( c . req . raw , context ) )
146+ app . post ( TuiPaths . selectSession , ( c ) => handler ( c . req . raw , context ) )
147+ app . get ( TuiPaths . controlNext , ( c ) => handler ( c . req . raw , context ) )
148+ app . post ( TuiPaths . controlResponse , ( c ) => handler ( c . req . raw , context ) )
149+ app . get ( WorkspacePaths . adaptors , ( c ) => handler ( c . req . raw , context ) )
150+ app . post ( WorkspacePaths . list , ( c ) => handler ( c . req . raw , context ) )
151+ app . get ( WorkspacePaths . list , ( c ) => handler ( c . req . raw , context ) )
152+ app . get ( WorkspacePaths . status , ( c ) => handler ( c . req . raw , context ) )
153+ app . delete ( WorkspacePaths . remove , ( c ) => handler ( c . req . raw , context ) )
154+ app . post ( WorkspacePaths . sessionRestore , ( c ) => handler ( c . req . raw , context ) )
155+ }
156+
33157 return app
34158 . route ( "/project" , ProjectRoutes ( ) )
35159 . route ( "/pty" , PtyRoutes ( upgrade ) )
0 commit comments