@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
33 lines • 1.79 kB
JavaScript
import { toStoreValue } from "@earendil-works/pi-agent-core";
/**
* The loop-side effects of a hand runtime's late work (brain/hand split H3), each turned into a wake for the brain that
* owns the scope: exactly the arguments a local session's `sendMessage`, `sendUserMessage`, `appendEntry` and
* `ui.notify` would have received, plus the loop session's id when a loop-hook call on that session started the work.
*/
export function loopWakeRoute(offer, sessionId) {
const wake = (source, fields) => offer({ source, payload: toStoreValue(sessionId === undefined ? fields : { ...fields, sessionId }) });
return {
sendMessage: (message, options) => wake("message", { message, options }),
sendUserMessage: (content, options) => wake("user_message", { content, options }),
appendEntry: (customType, data) => wake("entry", { customType, data }),
notify: (message, type) => wake("notice", { message, type }),
};
}
/**
* Where a loop-hook call's effects go once the call ended: its runtime's wake outbox, or, on a runtime without one,
* nowhere, and `dropped` reports each one so it is never lost silently.
*/
export function lateLoopRoute(wake, dropped) {
if (wake !== undefined)
return (sessionId) => loopWakeRoute(wake, sessionId);
return (sessionId) => {
const drop = (what) => dropped(`A ${what} from loop session ${sessionId}'s hook work arrived after its call ended and was dropped: this runtime has no wake route to the loop.`);
return {
sendMessage: () => drop("message"),
sendUserMessage: () => drop("user message"),
appendEntry: () => drop("session entry"),
notify: () => drop("notice"),
};
};
}
//# sourceMappingURL=hand-wake-route.js.map