@charmland/pi-hyper-provider 0.3.1 → 0.3.2
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/package.json +1 -1
- package/src/credits.ts +1 -1
- package/src/index.ts +30 -46
package/package.json
CHANGED
package/src/credits.ts
CHANGED
|
@@ -65,7 +65,7 @@ function isHyperModel(model: ExtensionContext["model"]): model is NonNullable<Ex
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
function statusText(balance: number, statusItems: HyperStatusItems, teamName: string | undefined): string {
|
|
68
|
-
const credits = `${HYPER_GEM} ${formatCredits(balance)}
|
|
68
|
+
const credits = `${HYPER_GEM} ${formatCredits(balance)} HC`;
|
|
69
69
|
if (statusItems.teamName && teamName) return `${teamName}: ${credits}`;
|
|
70
70
|
return credits;
|
|
71
71
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { envApiKeyAuth, lazyOAuth, type
|
|
1
|
+
import { createProvider, envApiKeyAuth, lazyOAuth, type OAuthAuth } from "@earendil-works/pi-ai";
|
|
2
2
|
import { openAICompletionsApi } from "@earendil-works/pi-ai/compat";
|
|
3
3
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import type { CreditStatusRuntime } from "./credits.js";
|
|
@@ -18,8 +18,6 @@ type PendingCreditStatusRefresh = {
|
|
|
18
18
|
|
|
19
19
|
export default function (pi: ExtensionAPI) {
|
|
20
20
|
const notifier = createNotifier();
|
|
21
|
-
const hyperApi = openAICompletionsApi();
|
|
22
|
-
let hyperModels: readonly Model<"openai-completions">[] = [];
|
|
23
21
|
let creditStatusState: CreditStatusState = { kind: "idle" };
|
|
24
22
|
let pendingCreditStatusRefresh: PendingCreditStatusRefresh | undefined;
|
|
25
23
|
let creditStatusRefreshWork: ReturnType<typeof setImmediate> | undefined;
|
|
@@ -111,49 +109,35 @@ export default function (pi: ExtensionAPI) {
|
|
|
111
109
|
scheduleCreditStatusRefresh(ctx, ctx.model);
|
|
112
110
|
});
|
|
113
111
|
|
|
114
|
-
pi.registerProvider(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const token = credential?.type === "oauth" ? credential.access : credential?.key;
|
|
145
|
-
const { fetchHyperModels } = await import("./models.js");
|
|
146
|
-
const refreshed = await fetchHyperModels({ signal, token });
|
|
147
|
-
if (signal.aborted) return;
|
|
148
|
-
await publish({
|
|
149
|
-
update: () => {
|
|
150
|
-
hyperModels = refreshed;
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
stream: hyperApi.stream,
|
|
155
|
-
streamSimple: hyperApi.streamSimple,
|
|
156
|
-
});
|
|
112
|
+
pi.registerProvider(
|
|
113
|
+
createProvider({
|
|
114
|
+
id: PROVIDER_NAME,
|
|
115
|
+
name: PROVIDER_DISPLAY_NAME,
|
|
116
|
+
baseUrl: HYPER_API_BASE_URL,
|
|
117
|
+
auth: {
|
|
118
|
+
apiKey: envApiKeyAuth("Hyper API key", ["HYPER_API_KEY"]),
|
|
119
|
+
oauth: lazyOAuth({
|
|
120
|
+
name: PROVIDER_DISPLAY_NAME,
|
|
121
|
+
load: async () => {
|
|
122
|
+
const { loginHyper, refreshHyperToken } = await import("./oauth.js");
|
|
123
|
+
return {
|
|
124
|
+
name: PROVIDER_DISPLAY_NAME,
|
|
125
|
+
login: loginHyper,
|
|
126
|
+
refresh: refreshHyperToken,
|
|
127
|
+
toAuth: async (credential) => ({ apiKey: credential.access }),
|
|
128
|
+
} satisfies OAuthAuth;
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
},
|
|
132
|
+
models: [],
|
|
133
|
+
fetchModels: async ({ credential, signal }) => {
|
|
134
|
+
const token = credential?.type === "oauth" ? credential.access : credential?.key;
|
|
135
|
+
const { fetchHyperModels } = await import("./models.js");
|
|
136
|
+
return fetchHyperModels({ signal, token });
|
|
137
|
+
},
|
|
138
|
+
api: openAICompletionsApi(),
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
157
141
|
|
|
158
142
|
pi.registerCommand("hyper-status", {
|
|
159
143
|
description: "Configure the Charm Hyper footer status",
|