Helper functions for handling provider responses and errors in HTTP requests.
// Source: https://github.com/Firstp1ck/pi-coding-agent-forge | License: MIT | Copyright 2026 Firstpick
// Provided via justclaw.it.com; keep this notice with the code.
import { combinedSignal } from "@firstpick/pi-utils/http";
export function providerError(code, message) {
const error = new Error(message);
error.code = code;
return error;
}
/** Tolerant transcript extraction, byte-compatible with the Phase-4 WebUI contract. */
export function transcriptTextFromProviderJson(json) {
return String(json?.text || json?.transcript || json?.data?.text || json?.result?.text || "").trim();
}
export async function parseTranscriptResponse(provider, response) {
const contentType = String(response.headers.get("content-type") || "").toLowerCase();
if (contentType.includes("application/js
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key