Add ui rpc command adapters
18f9996c45a916ef61f6c5331615ee11f4c56d6c
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
- Parent 1: 40948a40d315
bugabingas pi extensions
18f9996c45a916ef61f6c5331615ee11f4c56d6c
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
+100 / −0 text lines
new file mode 100644+60 / −0 text lines
import { describe, expect, it } from "vitest";import { abortCurrent, compactSession, cycleModel, cycleThinking, runBash, runSlashCommand, sendPrompt,} from "../command-adapter";describe("ui rpc command adapters", () => { it("sends normal prompts", async () => { const rpc = fakeRpc(); await sendPrompt(rpc, "hello"); expect(rpc.sent).toEqual([{ type: "prompt", message: "hello" }]); }); it("runs slash commands through prompt expansion", async () => { const rpc = fakeRpc(); await runSlashCommand(rpc, "mode", "terse"); expect(rpc.sent).toEqual([{ type: "prompt", message: "/mode terse" }]); }); it("runs bash and preserves context exclusion", async () => { const rpc = fakeRpc(); await runBash(rpc, "git status", true); expect(rpc.sent).toEqual([ { type: "bash", command: "git status", excludeFromContext: true }, ]); }); it("cycles model and thinking", async () => { const rpc = fakeRpc(); await cycleModel(rpc); await cycleThinking(rpc); expect(rpc.sent).toEqual([ { type: "cycle_model" }, { type: "cycle_thinking_level" }, ]); }); it("compacts and aborts", async () => { const rpc = fakeRpc(); await compactSession(rpc); await abortCurrent(rpc); expect(rpc.sent).toEqual([{ type: "compact" }, { type: "abort" }]); });});function fakeRpc() { const sent: unknown[] = []; return { sent, send(request: unknown) { sent.push(request); return Promise.resolve({ type: "response", success: true }); }, };}new file mode 100644+40 / −0 text lines
import type { RpcClient, RpcResponse } from "./rpc";export type RpcSender = Pick<RpcClient, "send">;export function sendPrompt(rpc: RpcSender, text: string): Promise<RpcResponse> { return rpc.send({ type: "prompt", message: text });}export function runSlashCommand( rpc: RpcSender, command: string, args = "",): Promise<RpcResponse> { const suffix = args.trim() ? ` ${args.trim()}` : ""; return sendPrompt(rpc, `/${command}${suffix}`);}export function runBash( rpc: RpcSender, command: string, excludeFromContext: boolean,): Promise<RpcResponse> { return rpc.send({ type: "bash", command, excludeFromContext });}export function cycleModel(rpc: RpcSender): Promise<RpcResponse> { return rpc.send({ type: "cycle_model" });}export function cycleThinking(rpc: RpcSender): Promise<RpcResponse> { return rpc.send({ type: "cycle_thinking_level" });}export function compactSession(rpc: RpcSender): Promise<RpcResponse> { return rpc.send({ type: "compact" });}export function abortCurrent(rpc: RpcSender): Promise<RpcResponse> { return rpc.send({ type: "abort" });}