@raquezha/noheadroom 0.2.3 → 0.2.5
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/dist/client.d.ts +1 -0
- package/dist/client.js +14 -0
- package/dist/index.js +9 -2
- package/extensions/client.ts +14 -0
- package/extensions/index.ts +8 -2
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare class HeadroomHttpClient {
|
|
|
8
8
|
private readonly timeoutMs;
|
|
9
9
|
constructor(options: HeadroomClientOptions);
|
|
10
10
|
health(signal?: AbortSignal): Promise<boolean>;
|
|
11
|
+
probe(signal?: AbortSignal): Promise<boolean>;
|
|
11
12
|
stats(signal?: AbortSignal): Promise<unknown>;
|
|
12
13
|
compress(messages: OpenAIMessage[], model: string | undefined, signal?: AbortSignal): Promise<CompressResult>;
|
|
13
14
|
}
|
package/dist/client.js
CHANGED
|
@@ -21,6 +21,20 @@ export class HeadroomHttpClient {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
async probe(signal) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(`${this.baseUrl}/v1/compress`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: { "Content-Type": "application/json" },
|
|
29
|
+
body: JSON.stringify({ messages: [{ role: "user", content: "ping" }], model: "gpt-4o" }),
|
|
30
|
+
signal: buildSignal(5_000, signal),
|
|
31
|
+
});
|
|
32
|
+
return response.ok;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
24
38
|
async stats(signal) {
|
|
25
39
|
const response = await fetch(`${this.baseUrl}/stats`, {
|
|
26
40
|
signal: buildSignal(this.timeoutMs, signal),
|
package/dist/index.js
CHANGED
|
@@ -82,7 +82,12 @@ function createRuntime(pi) {
|
|
|
82
82
|
async function updateHealthState(runtime, signal) {
|
|
83
83
|
if (isRemoteBlocked(runtime.config))
|
|
84
84
|
return false;
|
|
85
|
-
|
|
85
|
+
if (await runtime.client.health(signal)) {
|
|
86
|
+
runtime.state.proxyOnline = true;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
runtime.state.proxyOnline = await runtime.client.probe(signal);
|
|
90
|
+
}
|
|
86
91
|
return runtime.state.proxyOnline;
|
|
87
92
|
}
|
|
88
93
|
async function ensureProxy(runtime, ctx) {
|
|
@@ -221,6 +226,8 @@ async function handleContextCompression(runtime, event, ctx) {
|
|
|
221
226
|
// until the actual compressible candidate material changes.
|
|
222
227
|
runtime.state.lastInputFingerprint = inputFingerprint;
|
|
223
228
|
runtime.state.lastGuardSkipCandidateFingerprint = candidateFingerprint;
|
|
229
|
+
// ponytail: clear stats.last so renderFooterStatus shows idle instead of stale savings
|
|
230
|
+
runtime.state.stats.last = undefined;
|
|
224
231
|
runtime.refreshStatus(ctx);
|
|
225
232
|
return undefined;
|
|
226
233
|
}
|
|
@@ -483,7 +490,7 @@ function renderFooterStatus(ctx, config, state) {
|
|
|
483
490
|
if (!state.stats.last)
|
|
484
491
|
return paint("success", "✓") + paint("dim", " Headroom");
|
|
485
492
|
const pct = Math.round((1 - state.stats.last.compressionRatio) * 100);
|
|
486
|
-
return (paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()}
|
|
493
|
+
return (paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()} saved)`));
|
|
487
494
|
}
|
|
488
495
|
async function showProxyStats(ctx, client, config) {
|
|
489
496
|
if (isRemoteBlocked(config)) {
|
package/extensions/client.ts
CHANGED
|
@@ -38,6 +38,20 @@ export class HeadroomHttpClient {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
async probe(signal?: AbortSignal): Promise<boolean> {
|
|
42
|
+
try {
|
|
43
|
+
const response = await fetch(`${this.baseUrl}/v1/compress`, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: { "Content-Type": "application/json" },
|
|
46
|
+
body: JSON.stringify({ messages: [{ role: "user", content: "ping" }], model: "gpt-4o" }),
|
|
47
|
+
signal: buildSignal(5_000, signal),
|
|
48
|
+
});
|
|
49
|
+
return response.ok;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
41
55
|
async stats(signal?: AbortSignal): Promise<unknown> {
|
|
42
56
|
const response = await fetch(`${this.baseUrl}/stats`, {
|
|
43
57
|
signal: buildSignal(this.timeoutMs, signal),
|
package/extensions/index.ts
CHANGED
|
@@ -137,7 +137,11 @@ function createRuntime(pi: ExtensionAPI): HeadroomRuntime {
|
|
|
137
137
|
|
|
138
138
|
async function updateHealthState(runtime: HeadroomRuntime, signal?: AbortSignal): Promise<boolean> {
|
|
139
139
|
if (isRemoteBlocked(runtime.config)) return false;
|
|
140
|
-
|
|
140
|
+
if (await runtime.client.health(signal)) {
|
|
141
|
+
runtime.state.proxyOnline = true;
|
|
142
|
+
} else {
|
|
143
|
+
runtime.state.proxyOnline = await runtime.client.probe(signal);
|
|
144
|
+
}
|
|
141
145
|
return runtime.state.proxyOnline;
|
|
142
146
|
}
|
|
143
147
|
|
|
@@ -287,6 +291,8 @@ async function handleContextCompression(
|
|
|
287
291
|
// until the actual compressible candidate material changes.
|
|
288
292
|
runtime.state.lastInputFingerprint = inputFingerprint;
|
|
289
293
|
runtime.state.lastGuardSkipCandidateFingerprint = candidateFingerprint;
|
|
294
|
+
// ponytail: clear stats.last so renderFooterStatus shows idle instead of stale savings
|
|
295
|
+
runtime.state.stats.last = undefined;
|
|
290
296
|
runtime.refreshStatus(ctx);
|
|
291
297
|
return undefined;
|
|
292
298
|
}
|
|
@@ -578,7 +584,7 @@ function renderFooterStatus(ctx: ExtensionContext, config: HeadroomConfig, state
|
|
|
578
584
|
|
|
579
585
|
const pct = Math.round((1 - state.stats.last.compressionRatio) * 100);
|
|
580
586
|
return (
|
|
581
|
-
paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()}
|
|
587
|
+
paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()} saved)`)
|
|
582
588
|
);
|
|
583
589
|
}
|
|
584
590
|
|
package/package.json
CHANGED