@narumitw/pi-usage 0.41.0 → 0.43.0
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/package.json +2 -2
- package/src/usage.ts +19 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-usage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Pi extension that shows current-account usage for Codex, GitHub Copilot, and OpenRouter.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"directory": "extensions/pi-usage"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@narumitw/pi-tui-kit": "^0.
|
|
48
|
+
"@narumitw/pi-tui-kit": "^0.41.0"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/usage.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type ExtensionContext,
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionCommandContext,
|
|
4
|
+
ExtensionContext,
|
|
6
5
|
} from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
6
|
+
import { defineMenu, runMenu, runTask } from "@narumitw/pi-tui-kit";
|
|
8
7
|
import {
|
|
9
8
|
awaitWithDeadline,
|
|
10
9
|
errorMessage,
|
|
@@ -52,8 +51,6 @@ type StableCurrent = {
|
|
|
52
51
|
model: PiModel | undefined;
|
|
53
52
|
};
|
|
54
53
|
|
|
55
|
-
type LoaderResult<T> = { ok: true; value: T } | { ok: false; error: unknown };
|
|
56
|
-
|
|
57
54
|
export default function usageExtension(pi: ExtensionAPI) {
|
|
58
55
|
const cache = new UsageCache(CACHE_TTL_MS);
|
|
59
56
|
const failureBackoff = new Map<string, { until: number; message: string }>();
|
|
@@ -351,28 +348,21 @@ export default function usageExtension(pi: ExtensionAPI) {
|
|
|
351
348
|
parentSignal: AbortSignal,
|
|
352
349
|
operation: (signal: AbortSignal) => Promise<T>,
|
|
353
350
|
): Promise<T | undefined> => {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (finished) return;
|
|
360
|
-
finished = true;
|
|
361
|
-
done(value);
|
|
362
|
-
};
|
|
363
|
-
loader.onAbort = () => finish(null);
|
|
364
|
-
const signal = AbortSignal.any([parentSignal, loader.signal]);
|
|
365
|
-
void operation(signal)
|
|
366
|
-
.then((value) => finish({ ok: true, value }))
|
|
367
|
-
.catch((error) => {
|
|
368
|
-
if (isAbortError(error)) finish(null);
|
|
369
|
-
else finish({ ok: false, error });
|
|
370
|
-
});
|
|
371
|
-
return loader;
|
|
351
|
+
const result = await runTask(ctx, {
|
|
352
|
+
label,
|
|
353
|
+
signal: parentSignal,
|
|
354
|
+
onError: () => undefined,
|
|
355
|
+
task: ({ signal }) => operation(signal),
|
|
372
356
|
});
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
357
|
+
switch (result.kind) {
|
|
358
|
+
case "completed":
|
|
359
|
+
return result.value;
|
|
360
|
+
case "cancelled":
|
|
361
|
+
case "stale":
|
|
362
|
+
return undefined;
|
|
363
|
+
case "error":
|
|
364
|
+
throw result.error;
|
|
365
|
+
}
|
|
376
366
|
};
|
|
377
367
|
|
|
378
368
|
const outcomeStillCurrent = async (
|