archondev 2.19.9 → 2.19.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +81 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2844,6 +2844,55 @@ async function start(options = {}) {
2844
2844
  } catch {
2845
2845
  }
2846
2846
  }
2847
+ if (currentTier === "BYOK" && config.accessToken) {
2848
+ try {
2849
+ let usageStats = await fetchByokUsageStats(config.accessToken);
2850
+ const usageStatsUnavailable = !usageStats;
2851
+ if (!usageStats) {
2852
+ usageStats = {
2853
+ totalInputTokens: 0,
2854
+ totalOutputTokens: 0,
2855
+ totalBaseCost: 0,
2856
+ byModel: []
2857
+ };
2858
+ }
2859
+ console.log();
2860
+ console.log(chalk6.bold("\u{1F4CA} BYOK Usage"));
2861
+ console.log(chalk6.dim("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"));
2862
+ if (usageStats.periodStart) {
2863
+ const periodStart = new Date(usageStats.periodStart);
2864
+ const periodEnd = usageStats.periodEnd ? new Date(usageStats.periodEnd) : null;
2865
+ const formattedStart = isNaN(periodStart.getTime()) ? usageStats.periodStart : periodStart.toLocaleDateString();
2866
+ const formattedEnd = periodEnd && !isNaN(periodEnd.getTime()) ? periodEnd.toLocaleDateString() : void 0;
2867
+ if (formattedEnd) {
2868
+ console.log(chalk6.dim(` Period: ${formattedStart} \u2192 ${formattedEnd}`));
2869
+ } else {
2870
+ console.log(chalk6.dim(` Period start: ${formattedStart}`));
2871
+ }
2872
+ } else {
2873
+ console.log(chalk6.dim(" Period: Current month to date"));
2874
+ }
2875
+ const totalTokens = usageStats.totalInputTokens + usageStats.totalOutputTokens;
2876
+ console.log(` Tokens: ${chalk6.dim(totalTokens.toLocaleString())}`);
2877
+ console.log(` Estimated provider spend: ${chalk6.dim(`$${usageStats.totalBaseCost.toFixed(4)}`)}`);
2878
+ console.log();
2879
+ console.log(chalk6.dim(" Model Usage:"));
2880
+ if (usageStats.byModel.length > 0) {
2881
+ for (const model of usageStats.byModel) {
2882
+ const modelName = model.model.length > 32 ? model.model.slice(0, 29) + "..." : model.model;
2883
+ console.log(chalk6.dim(` ${modelName.padEnd(34)} $${model.cost.toFixed(4)}`));
2884
+ }
2885
+ } else {
2886
+ console.log(chalk6.dim(` ${"No usage yet".padEnd(34)} $0.0000`));
2887
+ }
2888
+ console.log(chalk6.dim("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"));
2889
+ if (usageStatsUnavailable) {
2890
+ console.log(chalk6.dim("Usage details may be delayed. Run `archon usage` to refresh."));
2891
+ }
2892
+ console.log(chalk6.dim("View details: archon usage | Models: archon preferences | Switch tier: archon upgrade"));
2893
+ } catch {
2894
+ }
2895
+ }
2847
2896
  if (currentTier === "BYOK") {
2848
2897
  const { keyManager } = await import("./keys-THCHXIFD.js");
2849
2898
  const hasKeys = await keyManager.hasAnyKey();
@@ -2988,6 +3037,38 @@ async function fetchCreditsUsageStats(accessToken, authId) {
2988
3037
  }
2989
3038
  return fetchCreditsUsageStatsFromSupabase(accessToken, authId);
2990
3039
  }
3040
+ async function fetchByokUsageStats(accessToken) {
3041
+ try {
3042
+ const { API_URL: API_URL3 } = await import("./constants-XDIWFFPN.js");
3043
+ const response = await fetch(`${API_URL3}/api/usage`, {
3044
+ headers: {
3045
+ "Authorization": `Bearer ${accessToken}`
3046
+ }
3047
+ });
3048
+ if (!response.ok) {
3049
+ return null;
3050
+ }
3051
+ const data = await response.json();
3052
+ if (data.tier && data.tier !== "BYOK") {
3053
+ return null;
3054
+ }
3055
+ const byModel = [...data.byModel ?? []].map((row) => ({
3056
+ model: row.model,
3057
+ cost: typeof row.cost === "number" ? row.cost : 0
3058
+ })).sort((a, b) => b.cost - a.cost);
3059
+ return {
3060
+ totalInputTokens: data.totalInputTokens ?? 0,
3061
+ totalOutputTokens: data.totalOutputTokens ?? 0,
3062
+ totalBaseCost: data.totalBaseCost ?? 0,
3063
+ byModel,
3064
+ periodStart: data.periodStart,
3065
+ periodEnd: data.periodEnd,
3066
+ periodSource: data.periodSource
3067
+ };
3068
+ } catch {
3069
+ return null;
3070
+ }
3071
+ }
2991
3072
  async function fetchCreditsUsageStatsFromSupabase(accessToken, authId) {
2992
3073
  try {
2993
3074
  const { SUPABASE_URL: SUPABASE_URL2, SUPABASE_ANON_KEY: SUPABASE_ANON_KEY2 } = await import("./constants-XDIWFFPN.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archondev",
3
- "version": "2.19.9",
3
+ "version": "2.19.10",
4
4
  "description": "Local-first AI-powered development governance system",
5
5
  "main": "dist/index.js",
6
6
  "bin": {