pi-service-tier 0.1.3 → 0.3.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/README.md +6 -5
- package/package.json +1 -1
- package/service-tier.ts +49 -42
package/README.md
CHANGED
|
@@ -59,13 +59,14 @@ extension.
|
|
|
59
59
|
|
|
60
60
|
When [pi-fancy-footer](https://github.com/mavam/pi-fancy-footer) is installed,
|
|
61
61
|
the widget appears only when the active model uses a supported provider/API pair
|
|
62
|
-
and that provider has a configured tier.
|
|
63
|
-
|
|
64
|
-

|
|
62
|
+
and that provider has a configured tier. It shows a single `⚡` without the tier
|
|
63
|
+
name to keep the footer compact.
|
|
65
64
|
|
|
66
65
|
The widget id is `pi-service-tier.service-tier`. It uses the current
|
|
67
|
-
`pi-fancy-footer`
|
|
68
|
-
|
|
66
|
+
`pi-fancy-footer` event protocol, with row `1`, position `8`, right alignment,
|
|
67
|
+
and no fill behavior by default. The extension has no package dependency on the
|
|
68
|
+
footer: it publishes a complete snapshot when its state changes and republishes
|
|
69
|
+
when the footer announces that it is ready.
|
|
69
70
|
|
|
70
71
|
## 📝 TODO
|
|
71
72
|
|
package/package.json
CHANGED
package/service-tier.ts
CHANGED
|
@@ -28,27 +28,9 @@ import {
|
|
|
28
28
|
|
|
29
29
|
export const SERVICE_TIER_WIDGET_ID = "pi-service-tier.service-tier";
|
|
30
30
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
"pi-fancy-footer:request-widget-refresh";
|
|
35
|
-
|
|
36
|
-
function contributeFancyFooterWidget(
|
|
37
|
-
pi: ExtensionAPI,
|
|
38
|
-
widget: Record<string, unknown>,
|
|
39
|
-
): void {
|
|
40
|
-
pi.events.on(FANCY_FOOTER_DISCOVER_WIDGETS_EVENT, (payload) => {
|
|
41
|
-
const request = payload as
|
|
42
|
-
| { registerWidget?: (widget: Record<string, unknown>) => void }
|
|
43
|
-
| undefined;
|
|
44
|
-
if (typeof request?.registerWidget !== "function") return;
|
|
45
|
-
request.registerWidget(widget);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function requestFancyFooterRefresh(pi: ExtensionAPI): void {
|
|
50
|
-
pi.events.emit(FANCY_FOOTER_REQUEST_WIDGET_REFRESH_EVENT, {});
|
|
51
|
-
}
|
|
31
|
+
const FANCY_FOOTER_PROTOCOL = 1;
|
|
32
|
+
const FANCY_FOOTER_WIDGET_EVENT = "pi-fancy-footer:widget";
|
|
33
|
+
const FANCY_FOOTER_READY_EVENT = "pi-fancy-footer:ready";
|
|
52
34
|
|
|
53
35
|
function warnOnce(message: string, lastWarning: string): string {
|
|
54
36
|
if (message !== lastWarning) console.warn(`pi-service-tier: ${message}`);
|
|
@@ -84,6 +66,45 @@ export default function (pi: ExtensionAPI) {
|
|
|
84
66
|
let currentServiceTier: ServiceTierName | "" = "";
|
|
85
67
|
let lastConfigWarning = "";
|
|
86
68
|
|
|
69
|
+
const publishFancyFooterWidget = (): void => {
|
|
70
|
+
pi.events.emit(FANCY_FOOTER_WIDGET_EVENT, {
|
|
71
|
+
protocol: FANCY_FOOTER_PROTOCOL,
|
|
72
|
+
type: "upsert",
|
|
73
|
+
widget: {
|
|
74
|
+
id: SERVICE_TIER_WIDGET_ID,
|
|
75
|
+
label: "Service tier",
|
|
76
|
+
description: "Shows a bolt when a provider service tier is active.",
|
|
77
|
+
content: { type: "text", text: currentServiceTier ? "⚡" : "" },
|
|
78
|
+
icon: false,
|
|
79
|
+
layout: {
|
|
80
|
+
row: 1,
|
|
81
|
+
position: 8,
|
|
82
|
+
align: "right",
|
|
83
|
+
fill: "none",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const stopFancyFooterReady = pi.events.on(
|
|
90
|
+
FANCY_FOOTER_READY_EVENT,
|
|
91
|
+
(message) => {
|
|
92
|
+
if (
|
|
93
|
+
typeof message !== "object" ||
|
|
94
|
+
message === null ||
|
|
95
|
+
!("protocol" in message) ||
|
|
96
|
+
message.protocol !== FANCY_FOOTER_PROTOCOL
|
|
97
|
+
) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
publishFancyFooterWidget();
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// Covers the case where the footer installed its listener first. The ready
|
|
105
|
+
// handler above covers the opposite load order.
|
|
106
|
+
publishFancyFooterWidget();
|
|
107
|
+
|
|
87
108
|
const loadConfigOrDefault = (): ServiceTierConfigSnapshot => {
|
|
88
109
|
try {
|
|
89
110
|
const config = loadServiceTierConfig();
|
|
@@ -122,7 +143,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
currentServiceTier = nextServiceTier;
|
|
125
|
-
|
|
146
|
+
publishFancyFooterWidget();
|
|
126
147
|
return currentServiceTier;
|
|
127
148
|
};
|
|
128
149
|
|
|
@@ -140,24 +161,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
140
161
|
}
|
|
141
162
|
};
|
|
142
163
|
|
|
143
|
-
contributeFancyFooterWidget(pi, {
|
|
144
|
-
id: SERVICE_TIER_WIDGET_ID,
|
|
145
|
-
label: "Service tier",
|
|
146
|
-
description: "Shows the configured provider service tier when active.",
|
|
147
|
-
row: 1,
|
|
148
|
-
order: 8,
|
|
149
|
-
align: "right",
|
|
150
|
-
grow: false,
|
|
151
|
-
icon: {
|
|
152
|
-
nerd: "",
|
|
153
|
-
emoji: "⚡",
|
|
154
|
-
unicode: "⚡",
|
|
155
|
-
ascii: "!",
|
|
156
|
-
},
|
|
157
|
-
visible: () => currentServiceTier !== "",
|
|
158
|
-
render: () => currentServiceTier || undefined,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
164
|
pi.registerCommand("fast", {
|
|
162
165
|
description: "Toggle fast service tier for the current model provider.",
|
|
163
166
|
handler: async (_args, ctx) => {
|
|
@@ -262,8 +265,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
262
265
|
});
|
|
263
266
|
|
|
264
267
|
pi.on("session_shutdown", async () => {
|
|
265
|
-
if (!currentServiceTier) return;
|
|
266
268
|
currentServiceTier = "";
|
|
267
|
-
|
|
269
|
+
stopFancyFooterReady();
|
|
270
|
+
pi.events.emit(FANCY_FOOTER_WIDGET_EVENT, {
|
|
271
|
+
protocol: FANCY_FOOTER_PROTOCOL,
|
|
272
|
+
type: "remove",
|
|
273
|
+
id: SERVICE_TIER_WIDGET_ID,
|
|
274
|
+
});
|
|
268
275
|
});
|
|
269
276
|
}
|