Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Remove client pty input streaming

Tomas Valenta9899afc1c78c
diff --git a/packages/js-sdk/src/connectionConfig.ts b/packages/js-sdk/src/connectionConfig.ts
index caf476fb7..a4f908038 100644
--- a/packages/js-sdk/src/connectionConfig.ts
+++ b/packages/js-sdk/src/connectionConfig.ts
@@ -2,7 +2,6 @@ import { Logger } from './logs'
import { getEnvVar } from './api/metadata'
const REQUEST_TIMEOUT_MS = 30_000 // 30s
-export const KEEPALIVE_INTERVAL = 90_000 // 90s
export interface ConnectionOpts {
apiKey?: string
diff --git a/packages/js-sdk/src/sandbox/pty.ts b/packages/js-sdk/src/sandbox/pty.ts
index 5297d4dc5..14db75dc3 100644
--- a/packages/js-sdk/src/sandbox/pty.ts
+++ b/packages/js-sdk/src/sandbox/pty.ts
@@ -5,15 +5,13 @@ import {
PromiseClient,
Transport,
} from '@connectrpc/connect'
-import { PartialMessage } from '@bufbuild/protobuf'
import { Process as ProcessService } from '../envd/process/process_connect'
import {
Signal,
StartResponse,
- StreamInputRequest,
} from '../envd/process/process_pb'
-import { ConnectionConfig, ConnectionOpts, KEEPALIVE_INTERVAL, Username } from '../connectionConfig'
+import { ConnectionConfig, ConnectionOpts, Username } from '../connectionConfig'
import { ProcessHandle } from './process/processHandle'
import { authenticationHeader, handleRpcError } from '../envd/rpc'
@@ -105,69 +103,6 @@ export class Pty {
}
}
- async streamInput(pid: number, opts?: Pick<ConnectionOpts, 'requestTimeoutMs'> & { timeout?: number }) {
- const requestTimeoutMs = opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs
-
- const controller = new AbortController()
-
- const reqTimeout = setTimeout(() => {
- controller.abort()
- }, requestTimeoutMs)
-
- const events = new AsyncQueue<PartialMessage<StreamInputRequest>>()
-
- this.rpc.streamInput(events, {
- signal: controller.signal,
- timeoutMs: opts?.timeout ?? 60_000,
- })
-
- clearTimeout(reqTimeout)
-
- events.enqueue({
- event: {
- case: 'start',
- value: {
- process: {
- selector: {
- case: 'pid',
- value: pid,
- },
- },
- },
- },
- })
-
- const keepaliveInterval = setInterval(() => {
- events.enqueue({
- event: {
- case: 'keepalive',
- value: {},
- }
- })
- }, KEEPALIVE_INTERVAL)
-
- return {
- stop: () => {
- controller.abort()
- events.stop()
- clearInterval(keepaliveInterval)
- },
- sendData: (data: Uint8Array) => events.enqueue({
- event: {
- case: 'data',
- value: {
- input: {
- input: {
- case: 'pty',
- value: data,
- },
- },
- },
- },
- }),
- }
- }
-
async resize(
pid: number,
size: {
@@ -217,39 +152,3 @@ export class Pty {
}
}
}
-
-class AsyncQueue<T> {
- private readonly resolvers: ((value: T) => void)[] = []
- private readonly promises: Promise<T>[] = []
-
- private stopped = false
-
- stop() {
- this.stopped = true
- }
-
- enqueue(t: T) {
- if (!this.resolvers.length) this.add()
- this.resolvers.shift()!(t)
- }
-
- async *[Symbol.asyncIterator]() {
- while (!this.stopped) {
- const event = await this.dequeue()
- if (event) {
- yield event
- }
- }
- }
-
- private dequeue() {
- if (!this.promises.length) this.add()
- return this.promises.shift()
- }
-
- private add() {
- this.promises.push(new Promise(resolve => {
- this.resolvers.push(resolve)
- }))
- }
-}