fix(server): apply plugin pty environment (#32296)

This commit is contained in:
Shoubhit Dash
2026-06-14 16:47:48 +05:30
committed by GitHub
parent 8cc2276dba
commit 7ad68f8150
8 changed files with 135 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ import { CorsConfig, isAllowedRequestOrigin } from "../cors"
import { ForbiddenError, PtyNotFoundError } from "../errors"
import { PTY_CONNECT_TICKET_QUERY, PTY_CONNECT_TOKEN_HEADER, PTY_CONNECT_TOKEN_HEADER_VALUE } from "../groups/pty"
import { response } from "../groups/location"
import { PtyEnvironment } from "../pty-environment"
const ticketScope = Effect.gen(function* () {
const location = yield* Location.Service
@@ -21,6 +22,7 @@ export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) =>
Effect.gen(function* () {
const tickets = yield* PtyTicket.Service
const cors = yield* CorsConfig
const environment = yield* PtyEnvironment.Service
return handlers
.handle(
@@ -33,11 +35,17 @@ export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) =>
"pty.create",
Effect.fn(function* (ctx) {
const pty = yield* Pty.Service
const location = yield* Location.Service
const cwd = ctx.payload.cwd || location.directory
return yield* response(
pty.create({
...ctx.payload,
args: ctx.payload.args ? [...ctx.payload.args] : undefined,
env: ctx.payload.env ? { ...ctx.payload.env } : undefined,
cwd,
env: {
...ctx.payload.env,
...(yield* environment.get({ directory: location.directory, cwd })),
},
}),
)
}),

View File

@@ -0,0 +1,16 @@
export * as PtyEnvironment from "./pty-environment"
import { Context, Effect, Layer } from "effect"
export interface Interface {
readonly get: (input: { directory: string; cwd: string }) => Effect.Effect<Record<string, string>>
}
export class Service extends Context.Service<Service, Interface>()("@opencode/ServerPtyEnvironment") {}
export const defaultLayer = Layer.succeed(
Service,
Service.of({
get: () => Effect.succeed({}),
}),
)

View File

@@ -9,10 +9,12 @@ import { ServerAuth } from "./auth"
import { handlers } from "./handlers"
import { authorizationLayer } from "./middleware/authorization"
import { schemaErrorLayer } from "./middleware/schema-error"
import { PtyEnvironment } from "./pty-environment"
export function createRoutes(password?: string) {
return HttpApiBuilder.layer(Api, { openapiPath: "/openapi.json" }).pipe(
Layer.provide(handlers),
Layer.provide(PtyEnvironment.defaultLayer),
Layer.provide(authorizationLayer),
Layer.provide(schemaErrorLayer),
Layer.provide(