@arhen/pi-senja 1.2.2 → 1.2.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 +1 -1
- package/package.json +1 -1
- package/src/index.ts +30 -30
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 Senja request reports a different tier or none, Senja warns once and turns the mode off for that model. 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,40 @@ 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
|
-
|
|
441
|
+
if (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
|
+
let warning = `OpenAI ${reason}. Turned off ${tier} for ${key}.`;
|
|
445
|
+
try {
|
|
446
|
+
setSpeedTier(key, null);
|
|
447
|
+
} catch {
|
|
448
|
+
warning += " Could not save this change.";
|
|
449
|
+
}
|
|
462
450
|
requestFooterRender();
|
|
451
|
+
if (ctx.hasUI) ctx.ui.notify(warning, "warning");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
pi.on("provider_stream_event", (event, ctx) => {
|
|
455
|
+
const data = event.data as { type?: string; response?: { service_tier?: unknown; status?: string } } | null;
|
|
456
|
+
if (data?.type !== "response.completed" && data?.type !== "response.done") return;
|
|
457
|
+
if (data.response?.status && data.response.status !== "completed") return;
|
|
458
|
+
finishSpeedRequest(`${event.provider}/${event.model}`, data.response?.service_tier, ctx);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
pi.on("message_end", ({ message }, ctx) => {
|
|
462
|
+
if (message.role !== "assistant") return;
|
|
463
|
+
const key = `${message.provider}/${message.model}`;
|
|
464
|
+
if (message.stopReason === "stop" || message.stopReason === "toolUse") finishSpeedRequest(key, undefined, ctx);
|
|
465
|
+
else pendingReports.delete(key);
|
|
463
466
|
});
|
|
464
467
|
|
|
465
468
|
// Track how long the current prompt has been running.
|
|
@@ -587,8 +590,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
587
590
|
}
|
|
588
591
|
const key = speedKey(ctx.model);
|
|
589
592
|
const tier = key && speedTiers.get(key);
|
|
590
|
-
if (
|
|
591
|
-
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg("warning",
|
|
593
|
+
if (tier) {
|
|
594
|
+
modelBlock += ` ${theme.fg("dim", GLYPH.square)} ${theme.fg("warning", tier)}`;
|
|
592
595
|
}
|
|
593
596
|
|
|
594
597
|
const line1 = alignRight(locationBlock, modelBlock, width, theme);
|
|
@@ -712,8 +715,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
712
715
|
let speedTier = key ? speedTiers.get(key) : null;
|
|
713
716
|
const arg = args.trim().toLowerCase();
|
|
714
717
|
if (arg !== "on" && arg !== "off") {
|
|
715
|
-
if (ctx.hasUI)
|
|
716
|
-
ctx.ui.notify(speedTier && key ? speedLabel(key, speedTier) : "Fast and Ultrafast are off", "info");
|
|
718
|
+
if (ctx.hasUI) ctx.ui.notify(speedTier ?? "Fast and Ultrafast are off", "info");
|
|
717
719
|
return;
|
|
718
720
|
}
|
|
719
721
|
if (!model || !key) {
|
|
@@ -725,7 +727,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
725
727
|
if (warning) {
|
|
726
728
|
if (speedTiers.get(key) === tier) {
|
|
727
729
|
speedTiers.set(key, null);
|
|
728
|
-
speedLabels.delete(key);
|
|
729
730
|
pendingReports.delete(key);
|
|
730
731
|
requestFooterRender();
|
|
731
732
|
}
|
|
@@ -747,7 +748,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
747
748
|
ctx.ui.notify(`${tier} mode off`, "info");
|
|
748
749
|
return;
|
|
749
750
|
}
|
|
750
|
-
ctx.ui.notify(
|
|
751
|
+
ctx.ui.notify(speedTier, "info");
|
|
751
752
|
},
|
|
752
753
|
});
|
|
753
754
|
|
|
@@ -756,7 +757,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
756
757
|
|
|
757
758
|
pi.on("session_start", async (event, ctx) => {
|
|
758
759
|
speedTiers.clear();
|
|
759
|
-
speedLabels.clear();
|
|
760
760
|
pendingReports.clear();
|
|
761
761
|
await restoreSpeedTier(ctx);
|
|
762
762
|
clearWorkingTimers();
|