@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
31 lines • 1.82 kB
JavaScript
import { forwardToolEvents } from "../../core/extensions/two-sided-forwarding.js";
/**
* A loopless runtime's own extensions' `tool_call`/`tool_result` handlers, emitted as a session emits them. On a hand
* (a call that carries its nested requests), a two-sided extension's handlers are forwarded to the loop that owns the
* call instead of running here (S29). When the loop runs away from the user's machine (a hosted loop, S33/K5), the user's
* machine is the extension's home: `twoSidedHome: "hand"` keeps its tool handlers here, and its loop hooks come here too
* over the loop-hook link.
*/
export function extensionToolHandlers(runner, twoSidedHome = "loop") {
const twoSided = twoSidedHome === "loop" ? runner.twoSidedExtensionPaths() : new Set();
const options = (nested) => nested === undefined || twoSided.size === 0 ? {} : { forward: forwardToolEvents(twoSided, nested) };
return {
beforeToolCall: ({ toolName, toolCallId, input, nested }) => runner.hasHandlers("tool_call")
? runner.emitToolCall({ type: "tool_call", toolName, toolCallId, input }, options(nested))
: Promise.resolve(undefined),
afterToolCall: ({ toolName, toolCallId, input, result, isError, nested }) => runner.hasHandlers("tool_result")
? runner.emitToolResult({
type: "tool_result",
toolName,
toolCallId,
input,
content: result.content,
details: result.details,
...(result.structuredContent === undefined ? {} : { structuredContent: result.structuredContent }),
isError,
usage: result.usage,
}, options(nested))
: Promise.resolve(undefined),
};
}
//# sourceMappingURL=loopless-tool-handlers.js.map