pi-context 1.1.2 → 1.1.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/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/context.ts +5 -0
- package/src/utils.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -281,7 +281,7 @@ export default function (pi) {
|
|
|
281
281
|
// --- Context Dashboard (HUD) ---
|
|
282
282
|
const usage = await ctx.getContextUsage();
|
|
283
283
|
let usageStr = "Unknown";
|
|
284
|
-
if (usage) {
|
|
284
|
+
if (usage && usage.percent != null && usage.tokens != null && usage.contextWindow != null) {
|
|
285
285
|
usageStr = `${usage.percent.toFixed(1)}% (${formatTokens(usage.tokens)}/${formatTokens(usage.contextWindow)})`;
|
|
286
286
|
}
|
|
287
287
|
// Find the distance to the nearest tag
|
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -62,6 +62,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
62
62
|
const totalActual = usage.tokens;
|
|
63
63
|
const limit = usage.contextWindow;
|
|
64
64
|
|
|
65
|
+
if (totalActual == null || limit == null || usage.percent == null) {
|
|
66
|
+
ctx.ui.notify("Context usage info not available.", "warning");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
65
70
|
const totalRaw = systemTokensRaw + toolDefTokensRaw + msgTokensRaw + toolUseTokensRaw + toolResultTokensRaw;
|
|
66
71
|
const ratio = totalRaw > 0 ? (totalActual / totalRaw) : 1;
|
|
67
72
|
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export const formatTokens = (n: number) => {
|
|
1
|
+
export const formatTokens = (n: number | null | undefined) => {
|
|
2
|
+
if (n == null) return "N/A";
|
|
2
3
|
if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M";
|
|
3
4
|
if (n >= 1_000) return Math.round(n / 1_000) + "k";
|
|
4
5
|
return n.toString();
|