@aibranch/llm-meta-widget 0.7.6 → 0.8.1
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
CHANGED
|
@@ -124,7 +124,7 @@ that is not Rails needs no gem, no template engine and no asset pipeline — two
|
|
|
124
124
|
lines of HTML:
|
|
125
125
|
|
|
126
126
|
```html
|
|
127
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.
|
|
127
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.8"></script>
|
|
128
128
|
<llm-meta-widget llm-url="https://your-meta-server.example"
|
|
129
129
|
model="qwen3-6-35b-fast"
|
|
130
130
|
greeting="Hi — ask me anything about this page."></llm-meta-widget>
|
|
@@ -135,6 +135,16 @@ instead of ERB. Both produce the same widget, so the advice in that section
|
|
|
135
135
|
— CORS, a reachable `llm_url`, the hub's name for the model — applies here
|
|
136
136
|
too.
|
|
137
137
|
|
|
138
|
+
**`@0.8` is a range, and it stops at 0.8.x on purpose.** You get patches without
|
|
139
|
+
touching your page, and you do not get a breaking release by surprise. The cost
|
|
140
|
+
is that moving to 0.9 is a deliberate edit: read [CHANGELOG.md](CHANGELOG.md)
|
|
141
|
+
first, because a major-or-minor bump here is where the page's own contract can
|
|
142
|
+
change — 0.8.0 changed the shape of `window.aiState`, and a page that followed
|
|
143
|
+
the new documentation while still loading `@0.7` would have had every state
|
|
144
|
+
value silently replaced by an error string. Rails hosts are protected from that
|
|
145
|
+
mismatch by the Gemfile constraint; a CDN embed has no such guard, so the
|
|
146
|
+
version in that URL is the guard.
|
|
147
|
+
|
|
138
148
|
Nothing else is needed: the stylesheets and the markdown renderer are bundled
|
|
139
149
|
in, and the element injects its own styles. The host serves no CSS and no JS.
|
|
140
150
|
|
|
@@ -211,10 +221,17 @@ Declared inline on the same view as the widget. Runs as JavaScript in the browse
|
|
|
211
221
|
|
|
212
222
|
<!-- (b) State readers folded into the LLM's system prompt EVERY turn, -->
|
|
213
223
|
<!-- so the LLM can answer from page state without a tool_call. -->
|
|
224
|
+
<!-- Each reader declares what it returns, like every other channel. -->
|
|
214
225
|
<script>
|
|
215
226
|
window.aiState = {
|
|
216
|
-
text:
|
|
217
|
-
|
|
227
|
+
text: {
|
|
228
|
+
description: "the text the user wants to annotate",
|
|
229
|
+
read: function() { return $("#text").val() || ""; }
|
|
230
|
+
},
|
|
231
|
+
selected_dictionaries: {
|
|
232
|
+
description: "the dictionaries the user has chosen for annotation",
|
|
233
|
+
read: function() { return getSelected(); }
|
|
234
|
+
}
|
|
218
235
|
};
|
|
219
236
|
</script>
|
|
220
237
|
|
|
@@ -226,7 +243,17 @@ Declared inline on the same view as the widget. Runs as JavaScript in the browse
|
|
|
226
243
|
</script>
|
|
227
244
|
```
|
|
228
245
|
|
|
229
|
-
**What the LLM sees.** The `ai-actions` JSON is passed to the meta-server as `local_tools` for every turn. Alongside it, every reader in `window.aiState` is invoked (each turn) and
|
|
246
|
+
**What the LLM sees.** The `ai-actions` JSON is passed to the meta-server as `local_tools` for every turn. Alongside it, every reader in `window.aiState` is invoked (each turn) and rendered into a `Current page state:` block appended to the system prompt, one line per reader, with its description beside its value:
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
Current page state:
|
|
250
|
+
- text (the text the user wants to annotate): "The stomach was examined."
|
|
251
|
+
- selected_dictionaries (the dictionaries the user has chosen for annotation): ["uberon"]
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
So the LLM can answer from state directly instead of tool-calling for lookups, and knows what each value *means* rather than guessing from the key.
|
|
255
|
+
|
|
256
|
+
**Breaking change in 0.8.0.** A reader must be `{ description, read }`. The bare-function form — `text: function() {…}` — is removed, with no fallback. A key that still uses it is reported to the console by name, with the shape it should have, and skipped; the page's other readers keep working. Descriptions are not decoration: every other channel the widget declares to the model already carries one (Class 3 tool schemas, Class 2 `.well-known` tools, Class 1 hub tools, resources), and state readers were the exception.
|
|
230
257
|
|
|
231
258
|
**When the tool_call fires.** During the turn, as soon as the LLM emits the
|
|
232
259
|
call. Since 0.4.0 the action's outcome — `{ok: true, applied: "<name>"}`, or
|
|
@@ -279,7 +306,7 @@ Declared out-of-band on the meta-server (via the hub's admin UI or `/user/:id/mc
|
|
|
279
306
|
|
|
280
307
|
**Declaration.** No widget-side change. Register the server on the hub → flip `public: true` (visible to signed-in users) and optionally `public_to_anonymous: true` (visible to widget visitors without a login). See the meta-server's `Api::McpServersController`.
|
|
281
308
|
|
|
282
|
-
**What the LLM sees.** Only tools
|
|
309
|
+
**What the LLM sees.** Only tools the visitor has **enabled via the tool picker** (see "Level-1 pickers" below) — nothing is auto-selected, the visitor opts in per session. A page can set the starting selection instead, with `remote_tools_schema_id:`: those tools arrive already ticked, and the visitor can still untick them.
|
|
283
310
|
|
|
284
311
|
**When the tool_call fires.** Synchronously during the turn — widget POSTs to the hub's `/api/llm_api_keys/:uuid/models/:name/single_llm_calls` endpoint with `tool_ids: [...]`; the hub proxies to each MCP server and streams results back through SSE.
|
|
285
312
|
|
|
@@ -332,9 +359,9 @@ translate directly.
|
|
|
332
359
|
| `api_key_uuid:` | `"ollama-local"` | Hub API-key uuid to invoke |
|
|
333
360
|
| `element_path:` | `"/llm_meta_widget_assets/llm-meta-widget.js"` | The bundled element the page loads. Served by the gem's engine; override to load it from elsewhere |
|
|
334
361
|
| `actions_schema_id:` | `"ai-actions"` | DOM id of the Class-3 schema block |
|
|
335
|
-
| `state_global:` | `"aiState"` | Global window object holding Class-3 state readers |
|
|
362
|
+
| `state_global:` | `"aiState"` | Global window object holding Class-3 state readers, each `{ description, read }` (see the breaking change in 0.8.0) |
|
|
336
363
|
| `actions_global:` | `"aiActions"` | Global window object holding Class-3 implementations |
|
|
337
|
-
| `remote_tools_schema_id:` | `"remote-mcp-tools"` |
|
|
364
|
+
| `remote_tools_schema_id:` | `"remote-mcp-tools"` | DOM id of a JSON block listing Class-1 tools (`{id, name, description, input_schema}`) to start with. They seed the picker rather than bypassing it — shown ticked, and the visitor may untick them. Read once, at boot |
|
|
338
365
|
| `well_known_urls:` | `nil` | `nil` = auto-discover same-origin; explicit array = fetch those; `[]` = disable |
|
|
339
366
|
| `greeting:` | `nil` | First thing a visitor sees when the panel opens, above the offered prompt templates. `nil` = a generic line |
|
|
340
367
|
| `max_rounds:` | `3` | Cap on tool-call rounds per LLM turn. Page actions cost a round each since 0.4.0 — raise it for multi-step flows |
|
|
@@ -457,6 +484,10 @@ it most, since they must already know your form to press it.
|
|
|
457
484
|
behind the custom-element move: the npm package and its CDN URL, why `main`,
|
|
458
485
|
`exports` and `sideEffects` are set the way they are, and why the gem and the npm
|
|
459
486
|
package must never drift in version.
|
|
487
|
+
- **A page you can run** — `examples/connection-test.html` checks every call the
|
|
488
|
+
widget makes to a hub, one at a time, then mounts the widget with a tool
|
|
489
|
+
already selected. Serve it from an origin the hub allows and open it: if
|
|
490
|
+
something in the chain is wrong, it names which step.
|
|
460
491
|
- **Issues and questions** — <https://github.com/jdkim/llm_meta_widget/issues>
|
|
461
492
|
|
|
462
493
|
## License
|
|
@@ -642,7 +642,8 @@ async function resourceLinesForTurn({ plan, cached, endpoint, read, budgetBytes
|
|
|
642
642
|
}
|
|
643
643
|
var PROMPT_ARG_ALIASES = { dictionaries: "selected_dictionaries" };
|
|
644
644
|
function promptArgFromState(argName, state) {
|
|
645
|
-
const
|
|
645
|
+
const entry = state && state[argName] || state && state[PROMPT_ARG_ALIASES[argName]];
|
|
646
|
+
const reader = entry && typeof entry.read === "function" ? entry.read : null;
|
|
646
647
|
if (typeof reader !== "function") return "";
|
|
647
648
|
let value;
|
|
648
649
|
try {
|
|
@@ -4266,17 +4267,51 @@ function boot(cfg) {
|
|
|
4266
4267
|
currentThinkingBlock = null;
|
|
4267
4268
|
currentThinkingBody = null;
|
|
4268
4269
|
}
|
|
4270
|
+
function stateReaders() {
|
|
4271
|
+
var declared = window[STATE_GLOBAL] || {};
|
|
4272
|
+
var out = [];
|
|
4273
|
+
Object.keys(declared).forEach(function(key) {
|
|
4274
|
+
var entry = declared[key];
|
|
4275
|
+
var hasDescription = entry && typeof entry.description === "string" && entry.description.trim() !== "";
|
|
4276
|
+
var hasRead = entry && typeof entry.read === "function";
|
|
4277
|
+
if (!hasDescription || !hasRead) {
|
|
4278
|
+
console.error(
|
|
4279
|
+
"[llm-meta-widget] " + STATE_GLOBAL + "." + key + ' is not a valid state reader. Expected { description: "what this value is", read: function () { \u2026 } }, got ' + (typeof entry === "function" ? "a bare function (the 0.7 form, removed in 0.8)" : describeValue(entry)) + ". Skipping " + key + "."
|
|
4280
|
+
);
|
|
4281
|
+
return;
|
|
4282
|
+
}
|
|
4283
|
+
out.push({ key, description: entry.description, read: entry.read });
|
|
4284
|
+
});
|
|
4285
|
+
return out;
|
|
4286
|
+
}
|
|
4287
|
+
function describeValue(v) {
|
|
4288
|
+
if (v === null) return "null";
|
|
4289
|
+
if (Array.isArray(v)) return "an array";
|
|
4290
|
+
if (typeof v === "object") {
|
|
4291
|
+
var missing = [];
|
|
4292
|
+
if (typeof v.description !== "string" || v.description.trim() === "") missing.push("description");
|
|
4293
|
+
if (typeof v.read !== "function") missing.push("read");
|
|
4294
|
+
return "an object missing " + missing.join(" and ");
|
|
4295
|
+
}
|
|
4296
|
+
return typeof v;
|
|
4297
|
+
}
|
|
4269
4298
|
function currentPageState() {
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
Object.keys(reader).forEach(function(k) {
|
|
4299
|
+
return stateReaders().map(function(r) {
|
|
4300
|
+
var value;
|
|
4273
4301
|
try {
|
|
4274
|
-
|
|
4302
|
+
value = r.read();
|
|
4275
4303
|
} catch (e) {
|
|
4276
|
-
|
|
4304
|
+
value = "<error: " + e.message + ">";
|
|
4277
4305
|
}
|
|
4306
|
+
return { key: r.key, description: r.description, value };
|
|
4307
|
+
});
|
|
4308
|
+
}
|
|
4309
|
+
function pageStateLines() {
|
|
4310
|
+
var readers = currentPageState();
|
|
4311
|
+
if (readers.length === 0) return ["(this page declares no state)"];
|
|
4312
|
+
return readers.map(function(r) {
|
|
4313
|
+
return "- " + r.key + " (" + r.description + "): " + JSON.stringify(r.value);
|
|
4278
4314
|
});
|
|
4279
|
-
return out;
|
|
4280
4315
|
}
|
|
4281
4316
|
function currentSystemPrompt(resourceLines) {
|
|
4282
4317
|
return [
|
|
@@ -4288,9 +4323,8 @@ function boot(cfg) {
|
|
|
4288
4323
|
"3. After a tool returns a result, use it: either take the next step the task needs, or \u2014 if the task is done \u2014 answer in plain text. Do not stop silently after a tool call.",
|
|
4289
4324
|
"4. NEVER repeat a call you have already made with the same or similar arguments \u2014 its result is already in the conversation history.",
|
|
4290
4325
|
"",
|
|
4291
|
-
"Current page state:"
|
|
4292
|
-
|
|
4293
|
-
].concat(resourceLines || []).join("\n");
|
|
4326
|
+
"Current page state:"
|
|
4327
|
+
].concat(pageStateLines()).concat(resourceLines || []).join("\n");
|
|
4294
4328
|
}
|
|
4295
4329
|
async function resourceLinesForThisTurn() {
|
|
4296
4330
|
var turn = await resourceLinesForTurn({
|
|
@@ -971,7 +971,12 @@ export async function resourceLinesForTurn({ plan, cached, endpoint, read, budge
|
|
|
971
971
|
const PROMPT_ARG_ALIASES = { dictionaries: "selected_dictionaries" }
|
|
972
972
|
|
|
973
973
|
export function promptArgFromState(argName, state) {
|
|
974
|
-
|
|
974
|
+
// Same object shape the system-prompt annex consumes: { description, read }.
|
|
975
|
+
// The bare-function form was removed in 0.8.0, so an entry without `read` is
|
|
976
|
+
// simply not a reader — the prompt argument stays empty and the visitor fills
|
|
977
|
+
// it, which is the documented behaviour for state the page cannot supply.
|
|
978
|
+
const entry = (state && state[argName]) || (state && state[PROMPT_ARG_ALIASES[argName]])
|
|
979
|
+
const reader = entry && typeof entry.read === "function" ? entry.read : null
|
|
975
980
|
if (typeof reader !== "function") return ""
|
|
976
981
|
let value
|
|
977
982
|
try {
|
|
@@ -17,7 +17,7 @@ reduced to the element tag. The gem keeps its helper signature, so
|
|
|
17
17
|
PubDictionaries needs no edit.
|
|
18
18
|
|
|
19
19
|
Landed since: the npm package and the CDN URL. `@aibranch/llm-meta-widget` is on
|
|
20
|
-
npm, and `https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.
|
|
20
|
+
npm, and `https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.8` resolves to
|
|
21
21
|
the bundle, so the two-line integration in the example below is now literally
|
|
22
22
|
true — no gem, no Rails and no self-hosting required. The gem and the npm package
|
|
23
23
|
ship the identical file, which is checked rather than assumed: both 0.7.2 copies
|
|
@@ -95,7 +95,7 @@ to npm and served from a CDN. Integration in any stack, or none:
|
|
|
95
95
|
|
|
96
96
|
```html
|
|
97
97
|
<script type="module"
|
|
98
|
-
src="https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.
|
|
98
|
+
src="https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.8"></script>
|
|
99
99
|
<llm-meta-widget llm-url="https://hub.aibranch.org"
|
|
100
100
|
tool-hub-url="https://hub.aibranch.org"
|
|
101
101
|
model="qwen3-8-27b-fast"
|
|
@@ -195,7 +195,7 @@ adopter of it.
|
|
|
195
195
|
The CDN URL has no path:
|
|
196
196
|
|
|
197
197
|
```
|
|
198
|
-
https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.
|
|
198
|
+
https://cdn.jsdelivr.net/npm/@aibranch/llm-meta-widget@0.8
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
`main` and `exports["."]` both point at the bundle, so jsdelivr resolves the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aibranch/llm-meta-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"//version": "Must stay in step with lib/llm_meta_widget/version.rb. Two independently versioned copies of the same client is the drift docs/custom-element-distribution.md warns about: bump both, release both.",
|
|
5
5
|
"description": "Embeddable browser chat widget: a custom element that discovers tools at page, origin and hub scope and dispatches each tool call to the right one. Two lines of HTML on any host, Rails or not.",
|
|
6
6
|
"keywords": [
|