UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

36 lines (35 loc) • 1.93 kB
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs"; import { r as decodeUtf8Input } from "./utf8-input-BHczGT8v.mjs"; import { t as readByteStreamWithLimit } from "./read-byte-stream-with-limit-BjmaH2Xs.mjs"; //#region src/commands/models/auth-manual-input.ts /** Input contracts shared by manual token/API-key commands and the API-key writer. */ const MODELS_AUTH_STDIN_MAX_BYTES = 1048576; async function readPipedStdin(e = process.stdin) { const t = await readByteStreamWithLimit(e, { maxBytes: MODELS_AUTH_STDIN_MAX_BYTES, onOverflow: ({ maxBytes: e }) => /* @__PURE__ */ new Error(`Piped auth input exceeds ${e} bytes.`) }); return decodeUtf8Input(t, "Piped auth input"); } function resolveDefaultTokenProfileId(e) { return `${normalizeProviderId(e)}:manual`; } function normalizeManualAuthProvider(e) { const t = normalizeProviderId(e); if (t === "openai-codex" || t === "codex-cli") throw new Error(`"${t}" is a legacy provider ID; use --provider openai.`); return t === "openai" || t === "codex" ? "openai" : t; } function looksLikeOpenAIApiKey(e) { return /^sk-[A-Za-z0-9_-]{8,}$/.test(e.trim()); } function validateOpenAICodexApiKeyInput(e) { const t = e.trim(); if (!t) return "Required"; if (looksLikeOpenAIApiKey(t)) return; const n = t.replace(/^Bearer\s+/i, "").trim().split("."); if (n.length === 3 && n.every((e) => /^[A-Za-z0-9_-]{8,}$/.test(e)) || t.startsWith("{") || t.startsWith("[")) return `That looks like token or OAuth material, not an OpenAI API key. Use ${formatCliCommand("openclaw models auth paste-token --provider openai")} for token auth material.`; return "That does not look like an OpenAI API key."; } //#endregion export { validateOpenAICodexApiKeyInput as a, resolveDefaultTokenProfileId as i, normalizeManualAuthProvider as n, readPipedStdin as r, looksLikeOpenAIApiKey as t };