@charmland/pi-hyper-provider 0.3.2 → 0.4.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 +3 -4
- package/package.json +4 -3
- package/src/index.ts +55 -0
package/README.md
CHANGED
|
@@ -18,10 +18,9 @@ pi install git:github.com/charmbracelet/pi-hyper-provider
|
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
> [!IMPORTANT]
|
|
21
|
-
>
|
|
22
|
-
>
|
|
23
|
-
>
|
|
24
|
-
> metadata.
|
|
21
|
+
> Pi refreshes provider extensions' model catalogs in TUI and RPC modes. Other
|
|
22
|
+
> non-interactive modes use the latest persisted catalog, so open the TUI when
|
|
23
|
+
> you want to discover new models or update model metadata.
|
|
25
24
|
|
|
26
25
|
## Usage
|
|
27
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charmland/pi-hyper-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Pi extension for Charm's Hyper inference provider",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -25,12 +25,13 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@earendil-works/pi-ai": "*",
|
|
27
27
|
"@earendil-works/pi-coding-agent": "*",
|
|
28
|
+
"@earendil-works/pi-tui": "*",
|
|
28
29
|
"typebox": "*"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@biomejs/biome": "^2.4.16",
|
|
32
|
-
"@earendil-works/pi-ai": "^0.84.
|
|
33
|
-
"@earendil-works/pi-coding-agent": "^0.84.
|
|
33
|
+
"@earendil-works/pi-ai": "^0.84.4",
|
|
34
|
+
"@earendil-works/pi-coding-agent": "^0.84.4",
|
|
34
35
|
"typebox": "^1.1.38",
|
|
35
36
|
"typescript": "^6.0.3"
|
|
36
37
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createProvider, envApiKeyAuth, lazyOAuth, type OAuthAuth } from "@earendil-works/pi-ai";
|
|
2
|
+
// Pi 0.84.2's extension loader aliases the root package but not API subpaths.
|
|
2
3
|
import { openAICompletionsApi } from "@earendil-works/pi-ai/compat";
|
|
3
4
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
4
6
|
import type { CreditStatusRuntime } from "./credits.js";
|
|
5
7
|
import { HYPER_API_BASE_URL, PROVIDER_DISPLAY_NAME, PROVIDER_NAME } from "./hyper.js";
|
|
6
8
|
import { createNotifier } from "./notify.js";
|
|
@@ -16,11 +18,31 @@ type PendingCreditStatusRefresh = {
|
|
|
16
18
|
model: ExtensionContext["model"];
|
|
17
19
|
};
|
|
18
20
|
|
|
21
|
+
function prismLabel(value: string | undefined): string | undefined {
|
|
22
|
+
return value !== undefined && value.trim() !== "" && value.length <= 200 && !/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(value)
|
|
23
|
+
? value.trim()
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
export default function (pi: ExtensionAPI) {
|
|
20
28
|
const notifier = createNotifier();
|
|
21
29
|
let creditStatusState: CreditStatusState = { kind: "idle" };
|
|
22
30
|
let pendingCreditStatusRefresh: PendingCreditStatusRefresh | undefined;
|
|
23
31
|
let creditStatusRefreshWork: ReturnType<typeof setImmediate> | undefined;
|
|
32
|
+
let collectingPrismRoute = false;
|
|
33
|
+
let prismRoute: { modelName: string | undefined; modelId: string | undefined } | undefined;
|
|
34
|
+
|
|
35
|
+
pi.registerEntryRenderer("hyper-prism-route", (entry, _options, theme) => {
|
|
36
|
+
const data = entry.data;
|
|
37
|
+
if (typeof data !== "object" || data === null) return;
|
|
38
|
+
const modelName =
|
|
39
|
+
"modelName" in data && typeof data.modelName === "string" ? prismLabel(data.modelName) : undefined;
|
|
40
|
+
const modelId = "modelId" in data && typeof data.modelId === "string" ? prismLabel(data.modelId) : undefined;
|
|
41
|
+
const label = modelName ?? modelId;
|
|
42
|
+
if (label) {
|
|
43
|
+
return new Text(`${theme.fg("muted", "Prism")} ${theme.fg("dim", "→")} ${theme.fg("muted", label)}`, 0, 0);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
24
46
|
|
|
25
47
|
function loadCreditStatus(): Promise<CreditStatusRuntime> {
|
|
26
48
|
if (creditStatusState.kind === "ready") return Promise.resolve(creditStatusState.runtime);
|
|
@@ -109,6 +131,39 @@ export default function (pi: ExtensionAPI) {
|
|
|
109
131
|
scheduleCreditStatusRefresh(ctx, ctx.model);
|
|
110
132
|
});
|
|
111
133
|
|
|
134
|
+
pi.on("turn_start", () => {
|
|
135
|
+
collectingPrismRoute = true;
|
|
136
|
+
prismRoute = undefined;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
pi.on("after_provider_response", (event) => {
|
|
140
|
+
if (!collectingPrismRoute) return;
|
|
141
|
+
// Collect only during the assistant request, not between-turn compaction.
|
|
142
|
+
const modelName = prismLabel(event.headers["x-prism-model-name"]);
|
|
143
|
+
const modelId = prismLabel(event.headers["x-prism-model-id"]);
|
|
144
|
+
prismRoute = modelName || modelId ? { modelName, modelId } : undefined;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
pi.on("message_end", (event) => {
|
|
148
|
+
if (event.message.role === "assistant") collectingPrismRoute = false;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
pi.on("turn_end", (event) => {
|
|
152
|
+
const route = prismRoute;
|
|
153
|
+
prismRoute = undefined;
|
|
154
|
+
collectingPrismRoute = false;
|
|
155
|
+
if (
|
|
156
|
+
event.message.role !== "assistant" ||
|
|
157
|
+
event.message.provider !== PROVIDER_NAME ||
|
|
158
|
+
event.message.stopReason === "error" ||
|
|
159
|
+
event.message.stopReason === "aborted"
|
|
160
|
+
)
|
|
161
|
+
return;
|
|
162
|
+
// message_end extensions run before the final UI update. turn_end runs
|
|
163
|
+
// after the assistant and its tool results have been rendered.
|
|
164
|
+
if (route) pi.appendEntry("hyper-prism-route", route);
|
|
165
|
+
});
|
|
166
|
+
|
|
112
167
|
pi.registerProvider(
|
|
113
168
|
createProvider({
|
|
114
169
|
id: PROVIDER_NAME,
|