UNPKG

@convo-lang/convo-lang

Version:
53 lines 1.83 kB
import { vfs } from "@iyio/vfs"; import { Conversation } from "../Conversation.js"; export class ConvoWorkerCtx { constructor({ basePath = '.', dryRun = false, disableThreadLogging = false, vfs: vfsProp = vfs(), }) { this._isDisposed = false; this.basePath = basePath; this.dryRun = dryRun; this.disableThreadLogging = disableThreadLogging; this.vfs = vfsProp; } get isDisposed() { return this._isDisposed; } dispose() { if (this._isDisposed) { return; } this._isDisposed = true; } log(...args) { console.log(...args); } createConversationFor(worker) { return new Conversation({ disableAutoFlatten: true }); } async writeAsync(path, content) { if (this.dryRun) { this.log(`dryRun write - ${path}`); return; } await this.vfs.writeBufferAsync(path, content); } async writeJsonAsync(path, value) { return await this.writeAsync(path, JSON.stringify(value)); } async writeResponse(path, response) { const lastReturnValue = response.returnValues ? response.returnValues[response.returnValues.length - 1] : undefined; if (lastReturnValue !== undefined && lastReturnValue !== null) { return await this.writeJsonAsync(path, lastReturnValue); } else { return await this.writeAsync(path, response.message?.content ?? ''); } } async readAsync(path) { return await this.vfs.readStringAsync(path); } async appendAsync(path, content) { return await this.vfs.appendStringAsync(path, content); } async existsAsync(path) { return await this.vfs.getItemAsync(path) ? true : false; } } //# sourceMappingURL=ConvoWorkerCtx.js.map