@@ -13,12 +13,16 @@ import { ApiAuthRequiredError, ApiBadRequestError, ApiConflictError, ApiInternal
1313import {
1414 ApplyAllRequestSchema ,
1515 CodexAuthImportRequestSchema ,
16+ CodexAuthLoginRequestSchema ,
1617 CodexAuthLogoutRequestSchema ,
1718 CreateAgentRequestSchema ,
1819 CreateFollowRequestSchema ,
1920 CreateProjectRequestSchema ,
2021 GithubAuthLoginRequestSchema ,
2122 GithubAuthLogoutRequestSchema ,
23+ StateCommitRequestSchema ,
24+ StateInitRequestSchema ,
25+ StateSyncRequestSchema ,
2226 UpProjectRequestSchema
2327} from "./api/schema.js"
2428import { uiHtml , uiScript , uiStyles } from "./ui.js"
@@ -30,6 +34,7 @@ import {
3034 readCodexAuthStatus ,
3135 readGithubAuthStatus
3236} from "./services/auth.js"
37+ import { streamCodexAuthLogin } from "./services/auth-codex-login-stream.js"
3338import { getAgent , getAgentAttachInfo , listAgents , readAgentLogs , startAgent , stopAgent } from "./services/agents.js"
3439import { latestProjectCursor , listProjectEventsSince } from "./services/events.js"
3540import {
@@ -57,6 +62,15 @@ import {
5762 recreateProject ,
5863 upProject
5964} from "./services/projects.js"
65+ import {
66+ commitStateFromRequest ,
67+ initStateFromRequest ,
68+ pullState ,
69+ pushState ,
70+ readStatePathOutput ,
71+ readStateStatusOutput ,
72+ syncStateFromRequest
73+ } from "./services/state.js"
6074
6175const ProjectParamsSchema = Schema . Struct ( {
6276 projectId : Schema . String
@@ -159,7 +173,11 @@ const readCreateFollowRequest = () => HttpServerRequest.schemaBodyJson(CreateFol
159173const readGithubAuthLoginRequest = ( ) => HttpServerRequest . schemaBodyJson ( GithubAuthLoginRequestSchema )
160174const readGithubAuthLogoutRequest = ( ) => HttpServerRequest . schemaBodyJson ( GithubAuthLogoutRequestSchema )
161175const readCodexAuthImportRequest = ( ) => HttpServerRequest . schemaBodyJson ( CodexAuthImportRequestSchema )
176+ const readCodexAuthLoginRequest = ( ) => HttpServerRequest . schemaBodyJson ( CodexAuthLoginRequestSchema )
162177const readCodexAuthLogoutRequest = ( ) => HttpServerRequest . schemaBodyJson ( CodexAuthLogoutRequestSchema )
178+ const readStateInitRequest = ( ) => HttpServerRequest . schemaBodyJson ( StateInitRequestSchema )
179+ const readStateCommitRequest = ( ) => HttpServerRequest . schemaBodyJson ( StateCommitRequestSchema )
180+ const readStateSyncRequest = ( ) => HttpServerRequest . schemaBodyJson ( StateSyncRequestSchema )
163181const readApplyAllRequest = ( ) => HttpServerRequest . schemaBodyJson ( ApplyAllRequestSchema )
164182const readUpProjectRequest = ( ) =>
165183 HttpServerRequest . schemaBodyJson ( UpProjectRequestSchema ) . pipe (
@@ -260,6 +278,20 @@ export const makeRouter = () => {
260278 return yield * _ ( jsonResponse ( { status } , 200 ) )
261279 } ) . pipe ( Effect . catchAll ( errorResponse ) )
262280 ) ,
281+ HttpRouter . post (
282+ "/auth/codex/login" ,
283+ Effect . gen ( function * ( _ ) {
284+ const request = yield * _ ( readCodexAuthLoginRequest ( ) )
285+ const outputStream = yield * _ ( streamCodexAuthLogin ( request ) )
286+ return HttpServerResponse . stream ( outputStream , {
287+ status : 200 ,
288+ headers : {
289+ "content-type" : "text/plain; charset=utf-8" ,
290+ "cache-control" : "no-cache"
291+ }
292+ } )
293+ } ) . pipe ( Effect . catchAll ( errorResponse ) )
294+ ) ,
263295 HttpRouter . post (
264296 "/auth/codex/import" ,
265297 Effect . gen ( function * ( _ ) {
@@ -350,7 +382,62 @@ export const makeRouter = () => {
350382 )
351383 )
352384
353- const withProjects = base . pipe (
385+ const withState = base . pipe (
386+ HttpRouter . get (
387+ "/state/path" ,
388+ readStatePathOutput ( ) . pipe (
389+ Effect . flatMap ( ( output ) => jsonResponse ( { output } , 200 ) ) ,
390+ Effect . catchAll ( errorResponse )
391+ )
392+ ) ,
393+ HttpRouter . post (
394+ "/state/init" ,
395+ Effect . gen ( function * ( _ ) {
396+ const request = yield * _ ( readStateInitRequest ( ) )
397+ const output = yield * _ ( initStateFromRequest ( request ) )
398+ return yield * _ ( jsonResponse ( { output } , 200 ) )
399+ } ) . pipe ( Effect . catchAll ( errorResponse ) )
400+ ) ,
401+ HttpRouter . get (
402+ "/state/status" ,
403+ readStateStatusOutput ( ) . pipe (
404+ Effect . flatMap ( ( output ) => jsonResponse ( { output } , 200 ) ) ,
405+ Effect . catchAll ( errorResponse )
406+ )
407+ ) ,
408+ HttpRouter . post (
409+ "/state/pull" ,
410+ pullState ( ) . pipe (
411+ Effect . flatMap ( ( output ) => jsonResponse ( { output } , 200 ) ) ,
412+ Effect . catchAll ( errorResponse )
413+ )
414+ ) ,
415+ HttpRouter . post (
416+ "/state/commit" ,
417+ Effect . gen ( function * ( _ ) {
418+ const request = yield * _ ( readStateCommitRequest ( ) )
419+ const output = yield * _ ( commitStateFromRequest ( request ) )
420+ return yield * _ ( jsonResponse ( { output } , 200 ) )
421+ } ) . pipe ( Effect . catchAll ( errorResponse ) )
422+ ) ,
423+ HttpRouter . post (
424+ "/state/sync" ,
425+ Effect . gen ( function * ( _ ) {
426+ const request = yield * _ ( readStateSyncRequest ( ) )
427+ const output = yield * _ ( syncStateFromRequest ( request ) )
428+ return yield * _ ( jsonResponse ( { output } , 200 ) )
429+ } ) . pipe ( Effect . catchAll ( errorResponse ) )
430+ ) ,
431+ HttpRouter . post (
432+ "/state/push" ,
433+ pushState ( ) . pipe (
434+ Effect . flatMap ( ( output ) => jsonResponse ( { output } , 200 ) ) ,
435+ Effect . catchAll ( errorResponse )
436+ )
437+ )
438+ )
439+
440+ const withProjects = withState . pipe (
354441 HttpRouter . get (
355442 "/projects" ,
356443 listProjects ( ) . pipe (
0 commit comments