pi-blablador 0.1.3 → 0.1.4
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 +17 -0
- package/blablador.ts +66 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -34,6 +34,12 @@ which is the fastest way to tell a missing token from a throttled one.
|
|
|
34
34
|
|
|
35
35
|
Needs Pi 1.4.0 or newer — the only version this was tested against.
|
|
36
36
|
|
|
37
|
+
## Web search
|
|
38
|
+
|
|
39
|
+
`web_search` searches through Blablador's anonymous SearXNG instance, so it needs no extra key. It
|
|
40
|
+
takes a `query` and an optional `category` (`general`, `news`, `science`, `it`), and returns six
|
|
41
|
+
results with title, URL, and snippet.
|
|
42
|
+
|
|
37
43
|
## Thinking levels
|
|
38
44
|
|
|
39
45
|
Every backend has its own `reasoning_effort` vocabulary and answers HTTP 400 for anything outside it,
|
|
@@ -53,6 +59,17 @@ so the map is per model family:
|
|
|
53
59
|
Pi's own levels are folded onto these, so you always pick from Pi's list: `--thinking high` on a Qwen
|
|
54
60
|
model sends `xhigh`, `--thinking medium` on DeepSeek sends `high`, `--thinking minimal` sends `low`.
|
|
55
61
|
|
|
62
|
+
## Count tokens
|
|
63
|
+
|
|
64
|
+
`count_tokens` sends a text to the gateway's `/tokenize` endpoint and returns the token count plus the
|
|
65
|
+
model's context ceiling, defaulting to the current model. Use it to check a prompt fits before
|
|
66
|
+
spending a chat request — an over-long prompt 400s, and that request is still charged.
|
|
67
|
+
|
|
68
|
+
`/tokenize` is implemented per backend, so it works for some aliases and not others (measured
|
|
69
|
+
2026-11-16: `alias-fast`, `alias-code`, `alias-large`, `alias-eve` and the Qwen 3.8 aliases answer;
|
|
70
|
+
the 1M deployments do not). For the rest the tool says the endpoint is not available instead of
|
|
71
|
+
returning a count.
|
|
72
|
+
|
|
56
73
|
## Context windows
|
|
57
74
|
|
|
58
75
|
The context windows the gateway enforces: 1,048,576 for the 1M deployments, 262,144 for the Qwen 3.8,
|
package/blablador.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Auth: BLABLADOR_API_TOKEN (or /login blablador once a credential is stored for the provider).
|
|
12
12
|
*/
|
|
13
|
-
import
|
|
13
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
14
|
+
import { defineTool, type ExtensionAPI, type ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
14
15
|
import {
|
|
15
16
|
BASE_URL,
|
|
16
17
|
EFFORT,
|
|
@@ -22,6 +23,8 @@ import {
|
|
|
22
23
|
fetchLiveModels,
|
|
23
24
|
outputCap,
|
|
24
25
|
resolveToken,
|
|
26
|
+
tokenize,
|
|
27
|
+
webSearch,
|
|
25
28
|
type CatalogModel,
|
|
26
29
|
} from "blablador-core";
|
|
27
30
|
|
|
@@ -72,6 +75,64 @@ export function buildModels(catalog: readonly CatalogModel[]): ProviderModelConf
|
|
|
72
75
|
return catalog.map(chatModel);
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
// Blablador ships an anonymous SearXNG instance, so a web_search tool needs no extra key. The search
|
|
79
|
+
// logic is shared with opencode-blablador through blablador-core; this is the pi-side registration.
|
|
80
|
+
const webSearchTool = defineTool({
|
|
81
|
+
name: "web_search",
|
|
82
|
+
label: "Web search",
|
|
83
|
+
description:
|
|
84
|
+
"Search the web via Blablador's SearXNG instance. Returns titles, URLs, and snippets. Use it for current information the model does not already know.",
|
|
85
|
+
parameters: Type.Object({
|
|
86
|
+
query: Type.String({ description: "The search query" }),
|
|
87
|
+
category: Type.Optional(
|
|
88
|
+
Type.Union(
|
|
89
|
+
[Type.Literal("general"), Type.Literal("news"), Type.Literal("science"), Type.Literal("it")],
|
|
90
|
+
{ description: "Result category (default: general)" },
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
}),
|
|
94
|
+
async execute(_toolCallId, params, signal) {
|
|
95
|
+
const results = await webSearch(params.query, { categories: params.category, signal });
|
|
96
|
+
const text =
|
|
97
|
+
results
|
|
98
|
+
.map((result, index) => `${index + 1}. ${result.title}\n ${result.url}\n ${result.content}`)
|
|
99
|
+
.join("\n\n") || "No results.";
|
|
100
|
+
return { content: [{ type: "text", text }], details: results };
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// count_tokens: check a text fits a model's window before processing it. The current model comes
|
|
105
|
+
// from ctx (pi exposes it); the token from pi's auth resolution, the same source the provider uses.
|
|
106
|
+
const countTokensTool = defineTool({
|
|
107
|
+
name: "count_tokens",
|
|
108
|
+
label: "Count tokens",
|
|
109
|
+
description:
|
|
110
|
+
"Count how many tokens a text uses against a Blablador model's context window. Use it to check a large input fits before processing it. Returns the token count and the model's max context length.",
|
|
111
|
+
parameters: Type.Object({
|
|
112
|
+
text: Type.String({ description: "The text to count" }),
|
|
113
|
+
model: Type.Optional(Type.String({ description: "Blablador alias to check against (default: the current model)" })),
|
|
114
|
+
}),
|
|
115
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
116
|
+
// Resolve the token the same way the provider does: pi's auth store first, then the env var;
|
|
117
|
+
// getApiKeyForProvider already does that fallback. Trim, because the gateway 401s on whitespace.
|
|
118
|
+
const token = (await ctx.modelRegistry.getApiKeyForProvider("blablador").catch(() => undefined))?.trim();
|
|
119
|
+
if (!token)
|
|
120
|
+
return { content: [{ type: "text", text: "No Blablador API token configured (set BLABLADOR_API_TOKEN)." }], details: {} };
|
|
121
|
+
const modelId = params.model ?? ctx.model?.id;
|
|
122
|
+
if (!modelId) return { content: [{ type: "text", text: "No model to count against; pass a model." }], details: {} };
|
|
123
|
+
try {
|
|
124
|
+
const { count, maxModelLen } = await tokenize(modelId, params.text, token, ctx.signal);
|
|
125
|
+
// Reserve the answer budget: a prompt that fills the window still 400s once output is asked for.
|
|
126
|
+
const fits =
|
|
127
|
+
count !== undefined && maxModelLen !== undefined ? count <= maxModelLen - outputCap(maxModelLen) : undefined;
|
|
128
|
+
const text = `Counted ${count ?? "?"} tokens for "${modelId}" (max context ${maxModelLen ?? "?"}).${fits === false ? " Does NOT fit." : fits ? " Fits." : ""}`;
|
|
129
|
+
return { content: [{ type: "text", text }], details: { model: modelId, count, maxModelLen, fits } };
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return { content: [{ type: "text", text: `Token count failed: ${error instanceof Error ? error.message : String(error)}` }], details: {} };
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
75
136
|
export default function blablador(pi: ExtensionAPI): void {
|
|
76
137
|
// pi interpolates "$BLABLADOR_API_TOKEN" into the Authorization header verbatim, so a key
|
|
77
138
|
// pasted with surrounding whitespace 401s every request. The extension shares the CLI process,
|
|
@@ -115,4 +176,8 @@ export default function blablador(pi: ExtensionAPI): void {
|
|
|
115
176
|
return models;
|
|
116
177
|
},
|
|
117
178
|
});
|
|
179
|
+
|
|
180
|
+
// Registered alongside the provider: a tool, not a model, so it shows in every blablador session.
|
|
181
|
+
pi.registerTool(webSearchTool);
|
|
182
|
+
pi.registerTool(countTokensTool);
|
|
118
183
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-blablador",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Blablador (Helmholtz / JSC) provider for Pi: live alias discovery, per-family thinking effort, measured context windows",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,18 +23,22 @@
|
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@earendil-works/pi-coding-agent": ">=1.4.0 <2.0.0"
|
|
26
|
+
"@earendil-works/pi-coding-agent": ">=1.4.0 <2.0.0",
|
|
27
|
+
"@earendil-works/pi-ai": ">=1.4.0 <2.0.0"
|
|
27
28
|
},
|
|
28
29
|
"peerDependenciesMeta": {
|
|
29
30
|
"@earendil-works/pi-coding-agent": {
|
|
30
31
|
"optional": true
|
|
32
|
+
},
|
|
33
|
+
"@earendil-works/pi-ai": {
|
|
34
|
+
"optional": true
|
|
31
35
|
}
|
|
32
36
|
},
|
|
33
37
|
"engines": {
|
|
34
38
|
"node": ">=22.18.0"
|
|
35
39
|
},
|
|
36
40
|
"dependencies": {
|
|
37
|
-
"blablador-core": "0.1.
|
|
41
|
+
"blablador-core": "0.1.4"
|
|
38
42
|
},
|
|
39
43
|
"scripts": {
|
|
40
44
|
"test": "node --test \"test/**/*.test.mjs\"",
|