@@ -16,20 +16,15 @@ import {
1616 PTY_CONNECT_TOKEN_HEADER_VALUE ,
1717} from "@opencode/protocol/groups/pty"
1818import { locationErrors , requestRef , response } from "../location"
19- import { PtyEnvironment } from "../pty-environment"
2019import { type Outbound , runPtySocket } from "./pty-socket"
2120
22- const ticketScope = Effect . gen ( function * ( ) {
23- const location = yield * Location . Service
24- return { directory : location . directory as string , workspaceID : location . workspaceID }
25- } )
21+ const notFound = ( ptyID : Pty . ID ) => new PtyNotFoundError ( { ptyID, message : `PTY session not found: ${ ptyID } ` } )
2622
2723export const PtyHandler = HttpApiBuilder . group ( Api , "server.pty" , ( handlers ) =>
2824 Effect . gen ( function * ( ) {
2925 const locations = yield * LocationServiceMap . Service
3026 const tickets = yield * PtyTicket . Service
3127 const cors = yield * CorsConfig
32- const environment = yield * PtyEnvironment . Service
3328
3429 return handlers
3530 . handle (
@@ -44,16 +39,10 @@ export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) =>
4439 Effect . fn ( function * ( ctx ) {
4540 const pty = yield * Pty . Service
4641 const location = yield * Location . Service
47- const cwd = ctx . payload . cwd || location . directory
4842 return yield * response (
4943 pty . create ( {
5044 ...ctx . payload ,
51- args : ctx . payload . args ? [ ...ctx . payload . args ] : undefined ,
52- cwd,
53- env : {
54- ...ctx . payload . env ,
55- ...( yield * environment . get ( { directory : location . directory , cwd } ) ) ,
56- } ,
45+ cwd : ctx . payload . cwd || location . directory ,
5746 } ) ,
5847 )
5948 } ) ,
@@ -63,16 +52,7 @@ export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) =>
6352 Effect . fn ( function * ( ctx ) {
6453 const pty = yield * Pty . Service
6554 return yield * response (
66- pty . get ( ctx . params . ptyID ) . pipe (
67- Effect . catchTag (
68- "Pty.NotFoundError" ,
69- ( ) =>
70- new PtyNotFoundError ( {
71- ptyID : ctx . params . ptyID ,
72- message : `PTY session not found: ${ ctx . params . ptyID } ` ,
73- } ) ,
74- ) ,
75- ) ,
55+ pty . get ( ctx . params . ptyID ) . pipe ( Effect . catchTag ( "Pty.NotFoundError" , ( ) => notFound ( ctx . params . ptyID ) ) ) ,
7656 )
7757 } ) ,
7858 )
@@ -82,37 +62,18 @@ export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) =>
8262 const pty = yield * Pty . Service
8363 return yield * response (
8464 pty
85- . update ( ctx . params . ptyID , {
86- ...ctx . payload ,
87- size : ctx . payload . size ? { ...ctx . payload . size } : undefined ,
88- } )
89- . pipe (
90- Effect . catchTag (
91- "Pty.NotFoundError" ,
92- ( ) =>
93- new PtyNotFoundError ( {
94- ptyID : ctx . params . ptyID ,
95- message : `PTY session not found: ${ ctx . params . ptyID } ` ,
96- } ) ,
97- ) ,
98- ) ,
65+ . update ( ctx . params . ptyID , ctx . payload )
66+ . pipe ( Effect . catchTag ( "Pty.NotFoundError" , ( ) => notFound ( ctx . params . ptyID ) ) ) ,
9967 )
10068 } ) ,
10169 )
10270 . handle (
10371 "pty.remove" ,
10472 Effect . fn ( function * ( ctx ) {
10573 const pty = yield * Pty . Service
106- yield * pty . remove ( ctx . params . ptyID ) . pipe (
107- Effect . catchTag (
108- "Pty.NotFoundError" ,
109- ( ) =>
110- new PtyNotFoundError ( {
111- ptyID : ctx . params . ptyID ,
112- message : `PTY session not found: ${ ctx . params . ptyID } ` ,
113- } ) ,
114- ) ,
115- )
74+ yield * pty
75+ . remove ( ctx . params . ptyID )
76+ . pipe ( Effect . catchTag ( "Pty.NotFoundError" , ( ) => notFound ( ctx . params . ptyID ) ) )
11677 return HttpApiSchema . NoContent . make ( )
11778 } ) ,
11879 )
@@ -128,17 +89,15 @@ export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) =>
12889 )
12990 return yield * new ForbiddenError ( { message : "Invalid PTY connect token request" } )
13091 const pty = yield * Pty . Service
131- yield * pty . get ( ctx . params . ptyID ) . pipe (
132- Effect . catchTag (
133- "Pty.NotFoundError" ,
134- ( ) =>
135- new PtyNotFoundError ( {
136- ptyID : ctx . params . ptyID ,
137- message : `PTY session not found: ${ ctx . params . ptyID } ` ,
138- } ) ,
139- ) ,
92+ const location = yield * Location . Service
93+ yield * pty . get ( ctx . params . ptyID ) . pipe ( Effect . catchTag ( "Pty.NotFoundError" , ( ) => notFound ( ctx . params . ptyID ) ) )
94+ return yield * response (
95+ tickets . issue ( {
96+ ptyID : ctx . params . ptyID ,
97+ directory : location . directory ,
98+ workspaceID : location . workspaceID ,
99+ } ) ,
140100 )
141- return yield * response ( tickets . issue ( { ptyID : ctx . params . ptyID , ...( yield * ticketScope ) } ) )
142101 } ) ,
143102 )
144103 . handleRaw (
0 commit comments