fix(server): apply plugin pty environment (#32296)
This commit is contained in:
@@ -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 })),
|
||||
},
|
||||
}),
|
||||
)
|
||||
}),
|
||||
|
||||
16
packages/server/src/pty-environment.ts
Normal file
16
packages/server/src/pty-environment.ts
Normal 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({}),
|
||||
}),
|
||||
)
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user