@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
37 lines • 2.03 kB
JavaScript
import { join } from "node:path";
import { ToolRuntimeUnsupportedHostError, toolRuntimeHostRefusal, } from "../../cli/tool-runtime.js";
import { SessionToolChild } from "../../modes/rpc/tool-child/session-child.js";
import { createSessionHostCallHandler } from "../tool-child-host-calls.js";
import { createToolDispatcher } from "./tool-dispatcher.js";
/**
* Build the tool-child runtime: the dispatcher that places tools, the tool child it runs child-placed work on, and the
* host-call handler both share. `AgentSession` builds its runtime here, and so does a runtime without a session
* (senpi#5227).
*/
export function createToolChildRuntime(options) {
const hostRefusal = toolRuntimeHostRefusal(options.toolRuntime);
if (hostRefusal !== undefined)
throw new ToolRuntimeUnsupportedHostError(hostRefusal);
// One host-call handler for both runtimes: the child's reverse bridge and an in-process ctx.offload module.
const hostCalls = createSessionHostCallHandler(options.hostCallDeps);
const toolChild = options.toolRuntime === "child"
? new SessionToolChild({
dir: join(options.agentDir, "tool-children", options.scopeId),
cwd: options.cwd,
moduleRoots: options.moduleRoots,
onRecord: options.onRecord,
onHostCall: hostCalls,
...(options.onWake === undefined ? {} : { onWake: options.onWake }),
...(options.command === undefined ? {} : { command: options.command }),
})
: undefined;
const dispatcher = createToolDispatcher({
runtime: options.toolRuntime,
...(options.notify === undefined ? {} : { notify: options.notify }),
hostCalls,
...(options.onModuleStuck === undefined ? {} : { onModuleStuck: options.onModuleStuck }),
...(toolChild === undefined ? {} : { childRunner: toolChild.runner, childKindRunner: toolChild.kindRunner }),
});
return { dispatcher, toolChild, hostCalls };
}
//# sourceMappingURL=tool-child-runtime.js.map