pi-spark 0.10.1 → 0.10.2

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.
@@ -62,20 +62,10 @@ class FooterComponent implements Component {
62
62
  }
63
63
 
64
64
  private getStyledCostText(): string {
65
- const cost = this.ctx.sessionManager.getBranch().reduce((acc, entry) => {
66
- const entryUsage = getEntryUsage(this.ctx, entry);
67
- if (entryUsage) acc[entryUsage.type] += entryUsage.usage.cost.total;
68
- return acc;
69
- }, { subscription: 0, paid: 0 });
70
-
71
- const isSubscription = this.ctx.model ? this.ctx.modelRegistry.isUsingOAuth(this.ctx.model) : false;
72
- const subscriptionCostText = isSubscription || cost.subscription >= 0.005 ? formatCost(cost.subscription, true) : undefined;
73
- const paidCostText = !isSubscription || cost.paid >= 0.005 ? formatCost(cost.paid, false) : undefined;
74
- const costText = [subscriptionCostText, paidCostText].filter(Boolean).join(" + ");
75
-
76
- const totalCost = cost.subscription + cost.paid;
77
- if (totalCost > 20) return this.theme.fg("warning", costText);
65
+ const totalCost = this.ctx.sessionManager.getBranch().reduce((acc, entry) => acc + (getEntryUsage(entry)?.cost.total ?? 0), 0);
66
+ const costText = formatCost(totalCost);
78
67
 
68
+ if (totalCost > 20) return this.theme.fg("warning", costText);
79
69
  return this.theme.fg("dim", costText);
80
70
  }
81
71
 
@@ -24,8 +24,8 @@ export function formatContextUsage(contextUsage: ContextUsage | undefined): stri
24
24
  return `${tokens === null ? "?" : formatTokens(tokens)}/${contextWindow === null ? "?" : formatTokens(contextWindow)} (${percentText})`;
25
25
  }
26
26
 
27
- export function formatCost(cost: number, isSubscription: boolean): string {
28
- return `$${cost.toFixed(2)}${isSubscription ? " (sub)" : ""}`;
27
+ export function formatCost(cost: number): string {
28
+ return `$${cost.toFixed(2)}`;
29
29
  }
30
30
 
31
31
  export function formatCwd(cwd: string, home: string): string {
@@ -1,5 +1,5 @@
1
1
  import type { Usage } from "@earendil-works/pi-ai";
2
- import type { ExtensionContext, SessionEntry } from "@earendil-works/pi-coding-agent";
2
+ import type { SessionEntry } from "@earendil-works/pi-coding-agent";
3
3
 
4
4
  /** Structural type guard for the pi `Usage` shape. */
5
5
  export function isUsage(value: unknown): value is Usage {
@@ -44,20 +44,17 @@ export function addUsage(a: Usage, b: Usage): Usage {
44
44
  }
45
45
 
46
46
  /**
47
- * Extract usage from a session entry, classifying it as subscription or paid.
47
+ * Extract usage from a session entry.
48
48
  *
49
- * `usage`/`provider`/`model` live in different fields depending on the entry type:
49
+ * `usage` live in different fields depending on the entry type:
50
50
  *
51
- * - `message` carries them on `.message`
52
- * - `custom` on `.data`
53
- * - `custom_message` on `.details`.
51
+ * - `message` carries them on `message`.
52
+ * - `custom` on `data`.
53
+ * - `custom_message` on `details`.
54
54
  *
55
55
  * Other entry types carry no usage. Returns `undefined` when the resolved field has no `usage`.
56
- *
57
- * An entry counts as subscription only when its `provider`/`model` resolve to an OAuth model in the
58
- * registry; everything else (including entries without `provider`/`model`) is treated as paid.
59
56
  */
60
- export function getEntryUsage(ctx: ExtensionContext, entry: SessionEntry): { type: "subscription" | "paid"; usage: Usage } | undefined {
57
+ export function getEntryUsage(entry: SessionEntry): Usage | undefined {
61
58
  let source: unknown;
62
59
  if (entry.type === "message") source = entry.message;
63
60
  else if (entry.type === "custom") source = entry.data;
@@ -65,15 +62,8 @@ export function getEntryUsage(ctx: ExtensionContext, entry: SessionEntry): { typ
65
62
  else return;
66
63
 
67
64
  if (typeof source !== "object" || source === null) return;
68
- const data = source as { usage?: unknown; provider?: unknown; model?: unknown };
65
+ const data = source as { usage?: unknown };
69
66
  if (!isUsage(data.usage)) return;
70
67
 
71
- const type = isSubscription(ctx, data.provider, data.model) ? "subscription" : "paid";
72
- return { type, usage: data.usage };
73
- }
74
-
75
- function isSubscription(ctx: ExtensionContext, provider: unknown, model: unknown): boolean {
76
- if (typeof provider !== "string" || typeof model !== "string") return false;
77
- const resolved = ctx.modelRegistry.find(provider, model);
78
- return resolved ? ctx.modelRegistry.isUsingOAuth(resolved) : false;
68
+ return data.usage;
79
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spark",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "A small, opinionated collection of pi extensions",
5
5
  "keywords": [
6
6
  "pi-coding-agent",