pi-service-tier 0.2.0 → 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 +4 -2
- package/package.json +1 -1
- package/service-tier.ts +49 -37
package/README.md
CHANGED
|
@@ -63,8 +63,10 @@ and that provider has a configured tier. It shows a single `⚡` without the tie
|
|
|
63
63
|
name to keep the footer compact.
|
|
64
64
|
|
|
65
65
|
The widget id is `pi-service-tier.service-tier`. It uses the current
|
|
66
|
-
`pi-fancy-footer`
|
|
67
|
-
|
|
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.
|
|
68
70
|
|
|
69
71
|
## 📝 TODO
|
|
70
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,19 +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 a bolt when a provider service tier is active.",
|
|
147
|
-
row: 1,
|
|
148
|
-
order: 8,
|
|
149
|
-
align: "right",
|
|
150
|
-
grow: false,
|
|
151
|
-
icon: false,
|
|
152
|
-
visible: () => currentServiceTier !== "",
|
|
153
|
-
render: () => (currentServiceTier ? "⚡" : undefined),
|
|
154
|
-
});
|
|
155
|
-
|
|
156
164
|
pi.registerCommand("fast", {
|
|
157
165
|
description: "Toggle fast service tier for the current model provider.",
|
|
158
166
|
handler: async (_args, ctx) => {
|
|
@@ -257,8 +265,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
257
265
|
});
|
|
258
266
|
|
|
259
267
|
pi.on("session_shutdown", async () => {
|
|
260
|
-
if (!currentServiceTier) return;
|
|
261
268
|
currentServiceTier = "";
|
|
262
|
-
|
|
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
|
+
});
|
|
263
275
|
});
|
|
264
276
|
}
|