tokenfactory-pi 0.2.5 → 0.2.6
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/index.js +25 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -12,9 +12,13 @@
|
|
|
12
12
|
* pi -e /path/to/tokenfactory-pi --provider nebius
|
|
13
13
|
* pi -e /path/to/tokenfactory-pi --provider nebius --model Qwen/Qwen3-32B
|
|
14
14
|
*/
|
|
15
|
+
import { gunzipSync } from "node:zlib";
|
|
15
16
|
const PROVIDER_NAME = "nebius";
|
|
16
17
|
const BASE_URL = "https://api.tokenfactory.nebius.com/v1";
|
|
17
18
|
const ENV_VAR = "NEBIUS_API_KEY";
|
|
19
|
+
function isGzip(bytes) {
|
|
20
|
+
return bytes.length >= 2 && bytes[0] === 0x1f && bytes[1] === 0x8b;
|
|
21
|
+
}
|
|
18
22
|
// ============================================================================
|
|
19
23
|
// Helpers
|
|
20
24
|
// ============================================================================
|
|
@@ -35,6 +39,19 @@ function parseCostPerMillion(raw) {
|
|
|
35
39
|
function isReasoningModel(id) {
|
|
36
40
|
return /(-R1|-Thinking|QwQ)/.test(id);
|
|
37
41
|
}
|
|
42
|
+
async function readTokenFactoryResponse(res) {
|
|
43
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
44
|
+
const body = (isGzip(bytes) ? gunzipSync(bytes) : bytes).toString("utf8");
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(body);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
const preview = body.slice(0, 200).replace(/\s+/g, " ");
|
|
50
|
+
throw new Error(`Invalid Token Factory JSON response (${res.status} ${res.statusText}, ` +
|
|
51
|
+
`content-type=${res.headers.get("content-type") || "unknown"}, ` +
|
|
52
|
+
`content-encoding=${res.headers.get("content-encoding") || "none"}): ${preview}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
38
55
|
// ============================================================================
|
|
39
56
|
// Extension entry point
|
|
40
57
|
// ============================================================================
|
|
@@ -46,14 +63,17 @@ export default async function (pi) {
|
|
|
46
63
|
let response;
|
|
47
64
|
try {
|
|
48
65
|
const res = await fetch(`${BASE_URL}/models?verbose=true`, {
|
|
49
|
-
headers: {
|
|
66
|
+
headers: {
|
|
67
|
+
Authorization: `Bearer ${apiKey}`,
|
|
68
|
+
"Accept-Encoding": "identity",
|
|
69
|
+
},
|
|
50
70
|
});
|
|
51
71
|
if (!res.ok) {
|
|
52
72
|
console.warn(`[${PROVIDER_NAME}] API returned ${res.status}: ${res.statusText}`);
|
|
53
73
|
console.warn(`[${PROVIDER_NAME}] Response headers:`, [...res.headers.entries()]);
|
|
54
74
|
return;
|
|
55
75
|
}
|
|
56
|
-
response =
|
|
76
|
+
response = await readTokenFactoryResponse(res);
|
|
57
77
|
}
|
|
58
78
|
catch (error) {
|
|
59
79
|
console.warn(`[${PROVIDER_NAME}] Failed to fetch models:`, error);
|
|
@@ -107,6 +127,9 @@ export default async function (pi) {
|
|
|
107
127
|
baseUrl: BASE_URL,
|
|
108
128
|
apiKey: ENV_VAR,
|
|
109
129
|
api: "openai-completions",
|
|
130
|
+
headers: {
|
|
131
|
+
"Accept-Encoding": "identity",
|
|
132
|
+
},
|
|
110
133
|
models,
|
|
111
134
|
});
|
|
112
135
|
// /nebius-models command to list and select a model
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenfactory-pi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Nebius Token Factory provider extension for pi coding agent. Requires `npm install -g @mariozechner/pi-coding-agent`. Install with `pi install npm:tokenfactory-pi`",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
"check": "tsc --noEmit",
|
|
44
44
|
"prepare": "npm run build"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|