UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

47 lines (46 loc) • 2.02 kB
import { a as writeRuntimeJson } from "./runtime-DlO3PTAd.mjs"; import { n as sanitizeTerminalText } from "./safe-text-SY_CvCi3.mjs"; import { t as formatCliCommand } from "./command-format-DwEdrDKL.mjs"; import { t as ClawHubRequestError } from "./clawhub-client-D-mEumEV.mjs"; import { i as fetchClawHubPromotions, t as markPromotionSlugsNotified } from "./promotions-feed-D9IPRe55.mjs"; //#region src/commands/promos/list.ts /** Lists active ClawHub promotional model offers. */ function formatWindowEnd(promotion) { const daysLeft = Math.max(0, Math.floor((promotion.endsAt - Date.now()) / 864e5)); if (daysLeft === 0) return "ends today"; return daysLeft === 1 ? "1 day left" : `${daysLeft} days left`; } async function promosListCommand(opts, runtime) { let promotions; try { promotions = await fetchClawHubPromotions(); } catch (error) { if (!(error instanceof ClawHubRequestError) || error.status !== 404) throw error; if (opts.json) writeRuntimeJson(runtime, { promotions: [] }); else runtime.log("Promotions are not available from ClawHub yet."); return; } await markPromotionSlugsNotified(promotions.map((promotion) => promotion.slug)); if (opts.json) { writeRuntimeJson(runtime, { promotions }); return; } if (promotions.length === 0) { runtime.log("No active promotions right now."); return; } const safe = sanitizeTerminalText; for (const promotion of promotions) { const sponsor = promotion.sponsor ? ` — ${safe(promotion.sponsor)}` : ""; runtime.log(`${safe(promotion.title)}${sponsor} (${formatWindowEnd(promotion)})`); runtime.log(` ${safe(promotion.blurb)}`); for (const model of promotion.models) { const alias = model.alias ? ` (${safe(model.alias)})` : ""; const suggested = model.suggestedDefault ? " — suggested default" : ""; runtime.log(` · ${safe(model.modelRef)}${alias}${suggested}`); } runtime.log(` Claim: ${formatCliCommand(`openclaw promos claim ${safe(promotion.slug)}`)}`); } } //#endregion export { promosListCommand };