@@ -5,9 +5,9 @@ import { EventV2 } from "@opencode-ai/core/event"
55import { Installation } from "@/installation"
66import { disposeAllInstancesAndEmitGlobalDisposed } from "@/server/global-lifecycle"
77import { InstallationVersion } from "@opencode-ai/core/installation/version"
8- import { Effect , Queue , Schema } from "effect"
8+ import { Effect , Queue } from "effect"
99import * as Stream from "effect/Stream"
10- import { HttpServerRequest , HttpServerResponse } from "effect/unstable/http"
10+ import { HttpServerResponse } from "effect/unstable/http"
1111import { HttpApiBuilder } from "effect/unstable/httpapi"
1212import * as Sse from "effect/unstable/encoding/Sse"
1313import { RootHttpApi } from "../api"
@@ -22,14 +22,6 @@ function eventData(data: unknown): Sse.Event {
2222 }
2323}
2424
25- function parseBody ( body : string ) {
26- try {
27- return JSON . parse ( body || "{}" ) as unknown
28- } catch {
29- return undefined
30- }
31- }
32-
3325function eventResponse ( ) {
3426 return Effect . gen ( function * ( ) {
3527 yield * Effect . logInfo ( "global event connected" )
@@ -97,52 +89,30 @@ export const globalHandlers = HttpApiBuilder.group(RootHttpApi, "global", (handl
9789 const upgrade = Effect . fn ( "GlobalHttpApi.upgrade" ) ( function * ( ctx : { payload : typeof GlobalUpgradeInput . Type } ) {
9890 const method = yield * installation . method ( )
9991 if ( method === "unknown" ) {
100- return {
101- status : 400 ,
102- body : { success : false as const , error : "Unknown installation method" } ,
103- }
92+ return HttpServerResponse . jsonUnsafe (
93+ { success : false as const , error : "Unknown installation method" } ,
94+ { status : 400 } ,
95+ )
10496 }
105- const target = ctx . payload . target || ( yield * installation . latest ( method ) )
97+ const target = ctx . payload . target
10698 const result = yield * installation . upgrade ( method , target ) . pipe (
107- Effect . as ( { status : 200 , body : { success : true as const , version : target } } ) ,
99+ Effect . as ( { success : true as const , version : target } ) ,
108100 Effect . catch ( ( err ) =>
109101 Effect . succeed ( {
110- status : 500 ,
111- body : {
112- success : false as const ,
113- error : err instanceof Error ? err . message : String ( err ) ,
114- } ,
102+ success : false as const ,
103+ error : err instanceof Error ? err . message : String ( err ) ,
115104 } ) ,
116105 ) ,
117106 )
118- if ( ! result . body . success ) return result
107+ if ( ! result . success ) return HttpServerResponse . jsonUnsafe ( result , { status : 500 } )
119108 GlobalBus . emit ( "event" , {
120109 directory : "global" ,
121110 payload : {
122111 type : Installation . Event . Updated . type ,
123112 properties : { version : target } ,
124113 } ,
125114 } )
126- return result
127- } )
128-
129- const upgradeRaw = Effect . fn ( "GlobalHttpApi.upgradeRaw" ) ( function * ( ctx : {
130- request : HttpServerRequest . HttpServerRequest
131- } ) {
132- const body = yield * Effect . orDie ( ctx . request . text )
133- const json = parseBody ( body )
134- if ( json === undefined ) {
135- return HttpServerResponse . jsonUnsafe ( { success : false , error : "Invalid request body" } , { status : 400 } )
136- }
137- const payload = yield * Schema . decodeUnknownEffect ( GlobalUpgradeInput ) ( json ) . pipe (
138- Effect . map ( ( payload ) => ( { valid : true as const , payload } ) ) ,
139- Effect . catch ( ( ) => Effect . succeed ( { valid : false as const } ) ) ,
140- )
141- if ( ! payload . valid ) {
142- return HttpServerResponse . jsonUnsafe ( { success : false , error : "Invalid request body" } , { status : 400 } )
143- }
144- const result = yield * upgrade ( { payload : payload . payload } )
145- return HttpServerResponse . jsonUnsafe ( result . body , { status : result . status } )
115+ return HttpServerResponse . jsonUnsafe ( result )
146116 } )
147117
148118 return handlers
@@ -151,6 +121,6 @@ export const globalHandlers = HttpApiBuilder.group(RootHttpApi, "global", (handl
151121 . handle ( "configGet" , configGet )
152122 . handle ( "configUpdate" , configUpdate )
153123 . handle ( "dispose" , dispose )
154- . handleRaw ( "upgrade" , upgradeRaw )
124+ . handle ( "upgrade" , upgrade )
155125 } ) ,
156126)
0 commit comments