pi-spark 0.10.1 → 0.10.3
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.
package/README.md
CHANGED
|
@@ -24,10 +24,10 @@ Install from npm:
|
|
|
24
24
|
pi install npm:pi-spark
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
For local development from this monorepo:
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
pi install
|
|
30
|
+
pi install /path/to/pi-packages/packages/pi-spark
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
## Configure
|
|
@@ -117,4 +117,4 @@ Project trust is an [input-loading guard](https://pi.dev/docs/latest/security#pr
|
|
|
117
117
|
|
|
118
118
|
## Other pi packages
|
|
119
119
|
|
|
120
|
-
- [pi-credits](https://github.com/zlliang/pi-credits): shows the active provider's credit balance or rate-limit usage as a footer status.
|
|
120
|
+
- [pi-credits](https://github.com/zlliang/pi-packages/tree/main/packages/pi-credits): shows the active provider's credit balance or rate-limit usage as a footer status.
|
|
@@ -62,20 +62,10 @@ class FooterComponent implements Component {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
private getStyledCostText(): string {
|
|
65
|
-
const
|
|
66
|
-
|
|
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
|
|
28
|
-
return `$${cost.toFixed(2)}
|
|
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 {
|
|
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
|
|
47
|
+
* Extract usage from a session entry.
|
|
48
48
|
*
|
|
49
|
-
* `usage
|
|
49
|
+
* `usage` live in different fields depending on the entry type:
|
|
50
50
|
*
|
|
51
|
-
* - `message` carries them on `.
|
|
52
|
-
* - `custom` on `.
|
|
53
|
-
* - `custom_message` on
|
|
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(
|
|
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
|
|
65
|
+
const data = source as { usage?: unknown };
|
|
69
66
|
if (!isUsage(data.usage)) return;
|
|
70
67
|
|
|
71
|
-
|
|
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.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "A small, opinionated collection of pi extensions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-coding-agent",
|
|
@@ -8,24 +8,21 @@
|
|
|
8
8
|
],
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/zlliang/pi-
|
|
11
|
+
"url": "git+https://github.com/zlliang/pi-packages.git",
|
|
12
|
+
"directory": "packages/pi-spark"
|
|
12
13
|
},
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"type": "module",
|
|
15
16
|
"files": [
|
|
16
17
|
"extensions",
|
|
17
18
|
"assets",
|
|
18
|
-
"README.md"
|
|
19
|
-
"LICENSE"
|
|
19
|
+
"README.md"
|
|
20
20
|
],
|
|
21
21
|
"pi": {
|
|
22
22
|
"extensions": [
|
|
23
23
|
"./extensions"
|
|
24
24
|
],
|
|
25
|
-
"image": "https://raw.githubusercontent.com/zlliang/pi-
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"typecheck": "tsc --noEmit"
|
|
25
|
+
"image": "https://raw.githubusercontent.com/zlliang/pi-packages/main/packages/pi-spark/assets/cover.png"
|
|
29
26
|
},
|
|
30
27
|
"dependencies": {
|
|
31
28
|
"liqe": "^3.8.7",
|
|
@@ -39,13 +36,7 @@
|
|
|
39
36
|
"@earendil-works/pi-tui": "*",
|
|
40
37
|
"typebox": "*"
|
|
41
38
|
},
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"@earendil-works/pi-ai": "*",
|
|
45
|
-
"@earendil-works/pi-coding-agent": "*",
|
|
46
|
-
"@earendil-works/pi-tui": "*",
|
|
47
|
-
"@types/node": "*",
|
|
48
|
-
"typebox": "*",
|
|
49
|
-
"typescript": "^6.0.3"
|
|
39
|
+
"scripts": {
|
|
40
|
+
"typecheck": "pnpm --dir ../.. typecheck"
|
|
50
41
|
}
|
|
51
|
-
}
|
|
42
|
+
}
|