MCPcopy Index your code
hub / github.com/TanStack/ai / constructor

Method constructor

packages/ai-sandbox-docker/src/handle.ts:82–161  ·  view source on GitHub ↗
(deps: DockerHandleDeps)

Source from the content-addressed store, hash-verified

80 private readonly envVars: Record<string, string> = {}
81
82 constructor(deps: DockerHandleDeps) {
83 this.docker = deps.docker
84 this.container = deps.container
85 this.workdir = deps.workdir
86 this.workspaceRoot = deps.workdir
87 this.deps = deps
88 this.id = deps.container.id
89
90 this.process = {
91 exec: (command, opts) => this.exec(command, opts),
92 spawn: (command, opts) => this.spawnProcess(command, opts),
93 }
94
95 this.fs = {
96 read: async (p) => {
97 const r = await this.exec(`base64 ${q(this.abs(p))}`)
98 if (r.exitCode !== 0) throw new Error(`read failed: ${r.stderr.trim()}`)
99 return Buffer.from(r.stdout, 'base64').toString('utf8')
100 },
101 readBytes: async (p) => {
102 const r = await this.exec(`base64 ${q(this.abs(p))}`)
103 if (r.exitCode !== 0) throw new Error(`read failed: ${r.stderr.trim()}`)
104 return new Uint8Array(Buffer.from(r.stdout, 'base64'))
105 },
106 write: async (p, data) => {
107 const abs = this.abs(p)
108 const b64 = Buffer.from(
109 typeof data === 'string' ? Buffer.from(data, 'utf8') : data,
110 ).toString('base64')
111 const dir = abs.replace(/\/[^/]*$/, '') || '/'
112 const r = await this.exec(
113 `mkdir -p ${q(dir)} && printf %s ${q(b64)} | base64 -d > ${q(abs)}`,
114 )
115 if (r.exitCode !== 0)
116 throw new Error(`write failed: ${r.stderr.trim()}`)
117 },
118 list: async (p) => {
119 const r = await this.exec(`ls -1Ap ${q(this.abs(p))}`)
120 if (r.exitCode !== 0) throw new Error(`list failed: ${r.stderr.trim()}`)
121 return r.stdout
122 .split('\n')
123 .filter((line) => line.trim() !== '')
124 .map((entry) => {
125 const isDir = entry.endsWith('/')
126 const name = isDir ? entry.slice(0, -1) : entry
127 return {
128 name,
129 path: `${p.replace(/\/$/, '')}/${name}`,
130 type: isDir ? ('dir' as const) : ('file' as const),
131 }
132 })
133 },
134 mkdir: async (p) => {
135 await this.exec(`mkdir -p ${q(this.abs(p))}`)
136 },
137 remove: async (p) => {
138 await this.exec(`rm -rf ${q(this.abs(p))}`)
139 },

Callers

nothing calls this directly

Calls 10

execMethod · 0.95
spawnProcessMethod · 0.95
absMethod · 0.95
connectPortMethod · 0.95
createExecBackedGitFunction · 0.90
toStringMethod · 0.80
fromMethod · 0.80
resolveMethod · 0.80
qFunction · 0.70
replaceMethod · 0.65

Tested by

no test coverage detected