@arhen/pi-senja 1.2.2 → 1.2.4
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 +1 -1
- package/package.json +1 -1
- package/src/index.ts +24 -31
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Forked from [pi-haiku](https://github.com/nnocte/pi-haiku) **0.2.0** by **nocte*
|
|
|
13
13
|
- **Quiet tool text** — tool titles and output both use the foreground beige (`fg0`) rather than loud accents, keeping panels calm against their tint.
|
|
14
14
|
- **Editor-style code colors** — pink keywords, olive strings, aqua function names, amber types, warm beige identifiers and punctuation, readable muted comments. Applies to code in tool calls/results and Markdown code blocks through Pi's syntax roles.
|
|
15
15
|
- **A live timer** while Pi works, plus elapsed-time completion message and notification. Preserves the active mode label and colour from `@arhen/pi-add-mode` (`review is working... 8s`).
|
|
16
|
-
- **Fast / Ultrafast mode** — `/fast on|off` and `/ultrafast on|off` set a paid speed preference per OpenAI provider and model. For ChatGPT sign-in, Senja checks the account’s model catalog before enabling or restoring a tier. If it is unavailable or cannot be verified, Senja warns and does not apply it. API-key mode checks known model support, not account entitlement. The footer
|
|
16
|
+
- **Fast / Ultrafast mode** — `/fast on|off` and `/ultrafast on|off` set a paid speed preference per OpenAI provider and model. For ChatGPT sign-in, Senja checks the account’s model catalog before enabling or restoring a tier. If it is unavailable or cannot be verified, Senja warns and does not apply it. API-key mode checks known model support, not account entitlement. The footer shows only `fast` or `ultrafast`. If a completed request reports a different tier (or none), Senja warns once for that response. The badge stays on, and the next request still asks for the selected tier. Failed or canceled requests do not change the preference. Off shows no chip and adds no tier. Preferences persist under `<agent-dir>/fast-mode/`; explicit `samplingParams.service_tier` still wins.
|
|
17
17
|
- **A fresh start** — clear the visible screen on initial terminal startup without clearing scrollback.
|
|
18
18
|
|
|
19
19
|
Enabled by default in terminal UI mode. Print, JSON, SDK, and RPC modes do not install terminal components, switch themes, clear the screen, or start UI timers. `/senja` in RPC mode reports that terminal UI is required.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -356,7 +356,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
356
356
|
let lastDoneIn: number | undefined;
|
|
357
357
|
let modeWorkingMessage: string | undefined;
|
|
358
358
|
const speedTiers = new Map<string, SpeedTier | null>();
|
|
359
|
-
const speedLabels = new Map<string, string>();
|
|
360
359
|
const pendingReports = new Map<string, SpeedTier>();
|
|
361
360
|
|
|
362
361
|
const unsubscribeMode = pi.events.on("pi-mode:working-message", (message) => {
|
|
@@ -394,13 +393,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
394
393
|
if (warning && ctx.hasUI) ctx.ui.notify(warning, "warning");
|
|
395
394
|
}
|
|
396
395
|
|
|
397
|
-
function speedLabel(key: string, tier: SpeedTier) {
|
|
398
|
-
return speedLabels.get(key) ?? `${tier} requested`;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
396
|
function setSpeedTier(key: string, tier: SpeedTier | null): void {
|
|
402
397
|
speedTiers.set(key, tier);
|
|
403
|
-
speedLabels.delete(key);
|
|
404
398
|
pendingReports.delete(key);
|
|
405
399
|
if (tier) {
|
|
406
400
|
mkdirSync(speedDir, { recursive: true });
|
|
@@ -435,31 +429,33 @@ export default function (pi: ExtensionAPI) {
|
|
|
435
429
|
const tier = speedTiers.get(key);
|
|
436
430
|
if (!tier) return;
|
|
437
431
|
pendingReports.delete(key);
|
|
438
|
-
if (payload.service_tier !== undefined)
|
|
439
|
-
speedLabels.set(key, `${tier} overridden by preset`);
|
|
440
|
-
requestFooterRender();
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
speedLabels.delete(key);
|
|
432
|
+
if (payload.service_tier !== undefined) return;
|
|
444
433
|
pendingReports.set(key, tier);
|
|
445
|
-
requestFooterRender();
|
|
446
434
|
return { ...payload, service_tier: wireTier(tier) };
|
|
447
435
|
});
|
|
448
436
|
|
|
449
|
-
|
|
450
|
-
const data = event.data as { type?: string; response?: { service_tier?: unknown } } | null;
|
|
451
|
-
if (data?.type !== "response.completed" && data?.type !== "response.done") return;
|
|
452
|
-
const key = `${event.provider}/${event.model}`;
|
|
437
|
+
function finishSpeedRequest(key: string, served: unknown, ctx: ExtensionContext) {
|
|
453
438
|
const tier = pendingReports.get(key);
|
|
454
439
|
if (!tier) return;
|
|
455
440
|
pendingReports.delete(key);
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
441
|
+
if (!ctx.hasUI || served === wireTier(tier) || served === tier) return;
|
|
442
|
+
const reason =
|
|
443
|
+
typeof served === "string" && /^[a-z0-9_-]{1,32}$/i.test(served) ? `reported ${served}` : "did not report a tier";
|
|
444
|
+
ctx.ui.notify(`Requested ${tier} for ${key}; OpenAI ${reason}. ${tier} stays on.`, "warning");
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
pi.on("provider_stream_event", (event, ctx) => {
|
|
448
|
+
const data = event.data as { type?: string; response?: { service_tier?: unknown; status?: string } } | null;
|
|
449
|
+
if (data?.type !== "response.completed" && data?.type !== "response.done") return;
|
|
450
|
+
if (data.response?.status && data.response.status !== "completed") return;
|
|
451
|
+
finishSpeedRequest(`${event.provider}/${event.model}`, data.response?.service_tier, ctx);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
pi.on("message_end", ({ message }, ctx) => {
|
|
455
|
+
if (message.role !== "assistant") return;
|
|
456
|
+
const key = `${message.provider}/${message.model}`;
|
|
457
|
+
if (message.stopReason === "stop" || message.stopReason === "toolUse") finishSpeedRequest(key, undefined, ctx);
|
|
458
|
+
else pendingReports.delete(key);
|
|
463
459
|
});
|
|
464
460
|
|
|
465
461
|
// Track how long the current prompt has been running.
|
|
@@ -587,8 +583,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
587
583
|
}
|
|
588
584
|
const key = speedKey(ctx.model);
|
|
589
585
|
const tier = key && speedTiers.get(key);
|
|
590
|
-
if (
|
|
591
|
-
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg("warning",
|
|
586
|
+
if (tier) {
|
|
587
|
+
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg("warning", tier)}`;
|
|
592
588
|
}
|
|
593
589
|
|
|
594
590
|
const line1 = alignRight(locationBlock, modelBlock, width, theme);
|
|
@@ -712,8 +708,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
712
708
|
let speedTier = key ? speedTiers.get(key) : null;
|
|
713
709
|
const arg = args.trim().toLowerCase();
|
|
714
710
|
if (arg !== "on" && arg !== "off") {
|
|
715
|
-
if (ctx.hasUI)
|
|
716
|
-
ctx.ui.notify(speedTier && key ? speedLabel(key, speedTier) : "Fast and Ultrafast are off", "info");
|
|
711
|
+
if (ctx.hasUI) ctx.ui.notify(speedTier ?? "Fast and Ultrafast are off", "info");
|
|
717
712
|
return;
|
|
718
713
|
}
|
|
719
714
|
if (!model || !key) {
|
|
@@ -725,7 +720,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
725
720
|
if (warning) {
|
|
726
721
|
if (speedTiers.get(key) === tier) {
|
|
727
722
|
speedTiers.set(key, null);
|
|
728
|
-
speedLabels.delete(key);
|
|
729
723
|
pendingReports.delete(key);
|
|
730
724
|
requestFooterRender();
|
|
731
725
|
}
|
|
@@ -747,7 +741,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
747
741
|
ctx.ui.notify(`${tier} mode off`, "info");
|
|
748
742
|
return;
|
|
749
743
|
}
|
|
750
|
-
ctx.ui.notify(
|
|
744
|
+
ctx.ui.notify(speedTier, "info");
|
|
751
745
|
},
|
|
752
746
|
});
|
|
753
747
|
|
|
@@ -756,7 +750,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
756
750
|
|
|
757
751
|
pi.on("session_start", async (event, ctx) => {
|
|
758
752
|
speedTiers.clear();
|
|
759
|
-
speedLabels.clear();
|
|
760
753
|
pendingReports.clear();
|
|
761
754
|
await restoreSpeedTier(ctx);
|
|
762
755
|
clearWorkingTimers();
|