feat(chat): view context — tell the assistant what you're looking at
Nightly Build / build (push) Successful in 7m51s

An eye next to the paperclip shares what the user has open with their next
message: the page, the folder being browsed, the file open in the viewer and
any highlighted passage (line numbers where a source view exists), plus which
entity a detail page is about. The bag is client-authored {label, value} pairs
in English — the backend only clamps (chars, never bytes), neutralizes the
harness tag and renders one <system-extra> block per message, deduped
consecutively so it appears exactly when the view changed. On by default,
per-device toggle, hover/tap to preview, a chip on every sent message;
docs/view-context.md for users, an updated harness.md clause for the model.
This commit is contained in:
Daniele
2026-08-23 20:53:30 +01:00
parent 488c702517
commit 505f2e95c1
42 changed files with 2096 additions and 122 deletions
+18
View File
@@ -1,6 +1,10 @@
import { html } from 'lit';
import { LightElement } from '../lib/base.js';
import { t } from '../lib/i18n.js';
import { setSlice, clearSlice } from '../lib/view-context.js';
/// The view-context slice this page owns (see `lib/view-context.js`).
const VIEW_SLICE = 'entity@models';
const CARDS = [
{
@@ -52,16 +56,28 @@ export class ModelsHubPage extends LightElement {
this.style.display = open ? 'flex' : 'none';
if (open) {
this._section = this._sectionFromHash();
this._publishViewContext();
if (!this._section) this._loadCounts();
} else {
clearSlice(VIEW_SLICE);
}
});
}
disconnectedCallback() {
window.removeEventListener('locale-changed', this.__onLocaleChanged);
clearSlice(VIEW_SLICE);
super.disconnectedCallback();
}
// The entity slice: which section is open. The hub root is no one section,
// so it publishes nothing — the route slice already describes it.
_publishViewContext() {
setSlice(VIEW_SLICE, this._section
? [{ label: 'Open section', value: this._section }]
: null);
}
_sectionFromHash() {
const parts = location.hash.slice(1).split('/');
if (parts[0] === 'models' && parts[1]) {
@@ -100,11 +116,13 @@ export class ModelsHubPage extends LightElement {
_openSection(id) {
this._section = id;
this._publishViewContext();
history.pushState({ page: 'models', section: id }, '', `#models/${id}`);
}
_goBack() {
this._section = null;
this._publishViewContext();
this._loadCounts();
history.replaceState({ page: 'models' }, '', '#models');
}