@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
66 lines • 2.3 kB
JavaScript
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import { BytePipe, CAPACITY } from "../../io/pipe.js";
import { JobConsole } from "./job_console.js";
import { Channel } from "./types.js";
/** Route a shell's piped channels through the shared bounded byte pipe. */
export class PipeConsole extends JobConsole {
pipeStderr;
pipe;
muted = false;
constructor(pipeStderr = false, bufferBytes = CAPACITY) {
super();
this.pipeStderr = pipeStderr;
this.pipe = new BytePipe(bufferBytes);
}
async emit(channel, data) {
if (channel !== Channel.STDOUT && !this.pipeStderr)
await super.emit(channel, data);
else if (!this.muted) {
await this.pipe.write(data).catch((error) => {
if (!this.muted)
throw error;
console.debug(`console pipe: a muted write is dropped: ${String(error)}`);
});
}
}
async drain() {
await this.pipe.drain();
}
get closedReader() {
return this.pipe.closedReader;
}
end(error) {
this.pipe.end(error);
}
/**
* End the reader's stream here and drop what is piped after, unrefused: a
* stopped JS run goes on past its abort, where a stopped process writes
* nothing more, and a refused write would end it as a broken pipe instead.
*/
mute() {
this.muted = true;
this.pipe.end();
}
closeReader() {
this.pipe.closeReader();
}
release() {
this.pipe.release();
}
stream() {
return this.pipe.stream(true);
}
}
//# sourceMappingURL=pipe.js.map