Files
PaperClipAI/packages/paperclip-runner/src/cli/opencode-proxy-input.ts
T
DottaandPaperclip e171282078 Forward OpenCode completion feedback through its real proxy
Wait for controller acceptance before proposing a result. Preserve final-response feedback and concrete rejection reasons across the proxy. Cover the production boundary and admit only the bounded corrected source.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-04 21:57:16 -05:00

26 lines
1.4 KiB
TypeScript

export { enqueueSerialInput as enqueueOpenCodeProxyInput } from "./serial-input-queue.js";
import type { OpenCodeCompletionFeedback } from "../drivers/opencode/opencode-server-driver.js";
/** Preserve the exact call binding and the controller's acceptance/rejection. */
export function openCodeProxyCompletionFeedback(
request: (method: string, params: Record<string, unknown>) => Promise<unknown>,
): OpenCodeCompletionFeedback {
return async (result, call) => {
const response = await request("item/tool/call", { ...call, arguments: result });
if (!response || typeof response !== "object" || Array.isArray(response))
throw new Error("Completion controller returned an invalid response");
const value = response as Record<string, unknown>;
const items = Array.isArray(value.contentItems) ? value.contentItems : [];
const feedback = items.flatMap(item => {
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
const entry = item as Record<string, unknown>;
return entry.type === "inputText" && typeof entry.text === "string" ? [entry.text] : [];
}).join("\n");
if (value.success === false) throw new Error(feedback || "Completion report rejected by the controller");
if (value.success !== true || !feedback.trim())
throw new Error("Completion controller omitted accepted feedback");
return feedback;
};
}