chore: tweak providers docs link
This commit is contained in:
parent
03cf7da2bd
commit
cda050d050
@ -1,3 +1,4 @@
|
|||||||
|
import { spinner } from "@clack/prompts";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -45,7 +46,7 @@ import { createClackPrompter } from "../wizard/clack-prompter.js";
|
|||||||
import { setupProviders } from "./onboard-providers.js";
|
import { setupProviders } from "./onboard-providers.js";
|
||||||
import type { ProviderChoice } from "./onboard-types.js";
|
import type { ProviderChoice } from "./onboard-types.js";
|
||||||
|
|
||||||
const DOCS_BASE = "https://docs.clawd.bot";
|
const DOCS_ROOT = "https://docs.clawd.bot";
|
||||||
|
|
||||||
const CHAT_PROVIDERS = [
|
const CHAT_PROVIDERS = [
|
||||||
"whatsapp",
|
"whatsapp",
|
||||||
@ -95,12 +96,6 @@ export type ProvidersRemoveOptions = {
|
|||||||
delete?: boolean;
|
delete?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function docsLink(path: string, label?: string): string {
|
|
||||||
const cleanPath = path.startsWith("/") ? path : `/${path}`;
|
|
||||||
const url = `${DOCS_BASE}${cleanPath}`;
|
|
||||||
return formatTerminalLink(label ?? url, url, { fallback: url });
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeChatProvider(raw?: string): ChatProvider | null {
|
function normalizeChatProvider(raw?: string): ChatProvider | null {
|
||||||
const trimmed = (raw ?? "").trim().toLowerCase();
|
const trimmed = (raw ?? "").trim().toLowerCase();
|
||||||
if (!trimmed) return null;
|
if (!trimmed) return null;
|
||||||
@ -447,6 +442,7 @@ export async function providersListCommand(
|
|||||||
) {
|
) {
|
||||||
const cfg = await requireValidConfig(runtime);
|
const cfg = await requireValidConfig(runtime);
|
||||||
if (!cfg) return;
|
if (!cfg) return;
|
||||||
|
const includeUsage = opts.usage !== false;
|
||||||
|
|
||||||
const whatsappAccounts = listWhatsAppAccountIds(cfg);
|
const whatsappAccounts = listWhatsAppAccountIds(cfg);
|
||||||
const telegramAccounts = listTelegramAccountIds(cfg);
|
const telegramAccounts = listTelegramAccountIds(cfg);
|
||||||
@ -466,9 +462,8 @@ export async function providersListCommand(
|
|||||||
profileId === CODEX_CLI_PROFILE_ID,
|
profileId === CODEX_CLI_PROFILE_ID,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const usage = opts.usage ? await loadProviderUsageSummary() : undefined;
|
|
||||||
|
|
||||||
if (opts.json) {
|
if (opts.json) {
|
||||||
|
const usage = includeUsage ? await loadProviderUsageSummary() : undefined;
|
||||||
const payload = {
|
const payload = {
|
||||||
chat: {
|
chat: {
|
||||||
whatsapp: whatsappAccounts,
|
whatsapp: whatsappAccounts,
|
||||||
@ -574,17 +569,54 @@ export async function providersListCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usage) {
|
runtime.log(lines.join("\n"));
|
||||||
lines.push("");
|
|
||||||
lines.push(...formatUsageReportLines(usage));
|
if (includeUsage) {
|
||||||
|
runtime.log("");
|
||||||
|
const usage = await loadUsageWithSpinner(runtime);
|
||||||
|
if (usage) {
|
||||||
|
const usageLines = formatUsageReportLines(usage);
|
||||||
|
if (usageLines.length > 0) {
|
||||||
|
usageLines[0] = chalk.cyan(usageLines[0]);
|
||||||
|
runtime.log(usageLines.join("\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.push("");
|
runtime.log("");
|
||||||
lines.push(
|
runtime.log(
|
||||||
`Docs: ${docsLink("/gateway/configuration", "gateway/configuration")}`,
|
`Docs: gateway/configuration -> ${formatTerminalLink(
|
||||||
|
DOCS_ROOT,
|
||||||
|
DOCS_ROOT,
|
||||||
|
{ fallback: DOCS_ROOT },
|
||||||
|
)}`,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
runtime.log(lines.join("\n"));
|
async function loadUsageWithSpinner(
|
||||||
|
runtime: RuntimeEnv,
|
||||||
|
): Promise<Awaited<ReturnType<typeof loadProviderUsageSummary>> | null> {
|
||||||
|
const rich = Boolean(process.stdout.isTTY);
|
||||||
|
if (!rich) {
|
||||||
|
try {
|
||||||
|
return await loadProviderUsageSummary();
|
||||||
|
} catch (err) {
|
||||||
|
runtime.error(String(err));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const spin = spinner();
|
||||||
|
spin.start(chalk.cyan("Fetching usage snapshot…"));
|
||||||
|
try {
|
||||||
|
const usage = await loadProviderUsageSummary();
|
||||||
|
spin.stop(chalk.green("Usage snapshot ready"));
|
||||||
|
return usage;
|
||||||
|
} catch (err) {
|
||||||
|
spin.stop(chalk.red("Usage snapshot failed"));
|
||||||
|
runtime.error(String(err));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function providersStatusCommand(
|
export async function providersStatusCommand(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user