Some checks are pending
CI / build-check-test (push) Waiting to run
CLI (coding-agent): - web-search.ts: DuckDuckGo web search tool - web-fetch.ts: Fetch and read web pages - image-gen.ts: Venice AI image generation - memory.ts: In-session memory store/recall - browser.ts: Playwright headless browser tool - tools/index.ts: Register all new tools - model-resolver.ts: Venice as default provider Web UI: - VeniceModelBrowser.ts: Model picker with category tags - ProvidersModelsTab.ts: Venice API key + model browser - ProviderKeyInput.ts: Venice key validation - ModelSelector.ts: Updated model selector - SettingsDialog.ts: Settings wired up - tools/index.ts: Export new tools - utils/model-discovery.ts: Venice model fetching - utils/format.ts: Formatting helpers - example/main.ts: Wire up new tools in example app jae-ai: - env-api-keys.ts: VENICE_API_KEY mapping - types.ts: venice in KnownProvider - oauth/venice.ts: Venice OAuth/API key provider - oauth/index.ts: Register Venice provider
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import type { Usage } from "@jaeswift/jae-ai";
|
|
import { i18n } from "@mariozechner/mini-lit";
|
|
|
|
export function formatCost(cost: number): string {
|
|
return `$${cost.toFixed(4)}`;
|
|
}
|
|
|
|
export function formatModelCost(cost: any): string {
|
|
if (!cost) return i18n("Free");
|
|
const input = cost.input || 0;
|
|
const output = cost.output || 0;
|
|
if (input === 0 && output === 0) return i18n("Free");
|
|
|
|
// Format numbers with appropriate precision
|
|
const formatNum = (num: number): string => {
|
|
if (num >= 100) return num.toFixed(0);
|
|
if (num >= 10) return num.toFixed(1).replace(/\.0$/, "");
|
|
if (num >= 1) return num.toFixed(2).replace(/\.?0+$/, "");
|
|
return num.toFixed(3).replace(/\.?0+$/, "");
|
|
};
|
|
|
|
return `$${formatNum(input)}/$${formatNum(output)}`;
|
|
}
|
|
|
|
export function formatUsage(usage: Usage) {
|
|
if (!usage) return "";
|
|
|
|
const parts = [];
|
|
if (usage.input) parts.push(`↑${formatTokenCount(usage.input)}`);
|
|
if (usage.output) parts.push(`↓${formatTokenCount(usage.output)}`);
|
|
if (usage.cacheRead) parts.push(`R${formatTokenCount(usage.cacheRead)}`);
|
|
if (usage.cacheWrite) parts.push(`W${formatTokenCount(usage.cacheWrite)}`);
|
|
if (usage.cost?.total) parts.push(formatCost(usage.cost.total));
|
|
|
|
return parts.join(" ");
|
|
}
|
|
|
|
export function formatTokenCount(count: number): string {
|
|
if (count < 1000) return count.toString();
|
|
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
|
|
return `${Math.round(count / 1000)}k`;
|
|
}
|