@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
52 lines • 2.49 kB
JavaScript
import { interruptBackgroundError } from "../rpc/pause-command-validation.js";
import { availableModelsData, interruptRunningTurn, unsupportedThinkingLevel, } from "../rpc/session-control-actions-data.js";
import { failure, success } from "./session-control-server.js";
export const SESSION_CONTROL_COMMANDS = [
"get_available_models",
"get_available_thinking_levels",
"set_model",
"set_thinking_level",
"interrupt",
];
export async function runSessionControlCommand(session, controls, command) {
const { id, type } = command;
switch (type) {
case "get_available_models":
return success(id, type, await availableModelsData(session));
case "get_available_thinking_levels":
return success(id, type, { levels: session.getAvailableThinkingLevels() });
case "set_model":
return await setModel(session, controls, command);
case "set_thinking_level": {
const level = session.getAvailableThinkingLevels().find((candidate) => candidate === command.level);
if (level === undefined)
return failure(id, type, unsupportedThinkingLevel(command.level));
controls.selectThinkingLevel(level, command.scope !== "turn");
return success(id, type);
}
case "interrupt": {
const backgroundError = interruptBackgroundError(command.background);
if (backgroundError !== undefined)
return failure(id, type, backgroundError);
return success(id, type, await interruptRunningTurn(session, command.turnId, () => controls.interruptTurn(), command.background));
}
default:
return undefined;
}
}
async function setModel(session, controls, command) {
const { id, type } = command;
const models = await session.modelRegistry.getAvailable();
const model = models.find((candidate) => candidate.provider === command.provider && candidate.id === command.modelId);
if (model === undefined) {
return failure(id, type, `Model not found: ${String(command.provider)}/${String(command.modelId)}`);
}
try {
const change = await controls.selectModel(model);
return success(id, type, { ...model, systemPromptName: change?.systemPromptName });
}
catch (error) {
return failure(id, type, error instanceof Error ? error.message : String(error));
}
}
//# sourceMappingURL=session-control-session-commands.js.map