refactor: dedupe bluebubbles and zalouser readers

This commit is contained in:
Peter Steinberger
2026-04-07 08:02:44 +01:00
parent 90a45a4907
commit 424b65b697
13 changed files with 45 additions and 27 deletions

View File

@@ -1,5 +1,6 @@
import { createHash, randomBytes } from "node:crypto";
import type { OAuthCredentials } from "@mariozechner/pi-ai";
import { normalizeOptionalString } from "../shared/string-coerce.js";
export const CHUTES_OAUTH_ISSUER = "https://api.chutes.ai";
export const CHUTES_AUTHORIZE_ENDPOINT = `${CHUTES_OAUTH_ISSUER}/idp/authorize`;
@@ -66,8 +67,8 @@ export function parseOAuthCallbackInput(
}
}
const code = url.searchParams.get("code")?.trim();
const state = url.searchParams.get("state")?.trim();
const code = normalizeOptionalString(url.searchParams.get("code"));
const state = normalizeOptionalString(url.searchParams.get("state"));
if (!code) {
return { error: "Missing 'code' parameter in URL" };
}
@@ -181,7 +182,7 @@ export async function refreshChutesTokens(params: {
if (!clientId) {
throw new Error("Missing CHUTES_CLIENT_ID for Chutes OAuth refresh (set env var or re-auth).");
}
const clientSecret = process.env.CHUTES_CLIENT_SECRET?.trim() || undefined;
const clientSecret = normalizeOptionalString(process.env.CHUTES_CLIENT_SECRET);
const body = new URLSearchParams({
grant_type: "refresh_token",

View File

@@ -156,7 +156,7 @@ export function buildEmbeddedRunPayloads(params: {
})
: undefined;
const rawErrorMessage = lastAssistantErrored
? params.lastAssistant?.errorMessage?.trim() || undefined
? normalizeOptionalString(params.lastAssistant?.errorMessage)
: undefined;
const rawErrorFingerprint = rawErrorMessage
? getApiErrorPayloadFingerprint(rawErrorMessage)

View File

@@ -1,3 +1,5 @@
import { normalizeOptionalString } from "../shared/string-coerce.js";
export const testServiceAuditCodes = {
gatewayEntrypointMismatch: "gateway-entrypoint-mismatch",
gatewayTokenMismatch: "gateway-token-mismatch",
@@ -11,5 +13,5 @@ export function readEmbeddedGatewayTokenForTest(
) {
return command?.environmentValueSources?.OPENCLAW_GATEWAY_TOKEN === "file"
? undefined
: command?.environment?.OPENCLAW_GATEWAY_TOKEN?.trim() || undefined;
: normalizeOptionalString(command?.environment?.OPENCLAW_GATEWAY_TOKEN);
}