@sema-agent/core
Version:
Stateless, task-oriented AI agent core
33 lines (32 loc) • 1.39 kB
JavaScript
import { describeRejectedValue } from "../tool-search-setting.js";
import { isPermissionMode, PERMISSION_MODES } from "../ask-origin.js";
export function streamModeVerb(input) {
const { live, ready, orTimeout, steeringError } = input;
const liveHandle = async () => {
if (live.resultValue)
throw steeringError("the task has already finished");
const h = live.handle ?? (await orTimeout(ready));
if (!h)
throw steeringError("the task is not running");
return h;
};
const setPermissionMode = async (mode) => {
const modeIn = mode;
if (!isPermissionMode(modeIn)) {
const e = new Error(`cannot set the permission mode: it must be one of ${PERMISSION_MODES.join("/")} (got ${describeRejectedValue(modeIn)})`);
e.code = "steering.invalid_content";
throw e;
}
return (await liveHandle()).permissionMode.steer(modeIn);
};
const setFastMode = async (on) => {
const onIn = on;
if (typeof onIn !== "boolean") {
const e = new Error(`cannot set fast mode: it must be true or false (got ${describeRejectedValue(onIn)})`);
e.code = "steering.invalid_content";
throw e;
}
return (await liveHandle()).fastMode.setRequested(onIn);
};
return { setPermissionMode, setFastMode };
}