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
+15 -2
View File
@@ -2,6 +2,7 @@ import { html, nothing } from 'lit';
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
import { LightElement } from '../lib/base.js';
import { t } from '../lib/i18n.js';
import { setSlice, clearSlice } from '../lib/view-context.js';
// Connector marketplace — blueprint §14/§15.
//
@@ -17,6 +18,9 @@ import { t } from '../lib/i18n.js';
const ADMIN_ID = 'admin';
/// The view-context slice this page owns (see `lib/view-context.js`).
const VIEW_SLICE = 'entity@marketplace';
async function jf(url, opts) {
const res = await fetch(url, opts);
if (!res.ok) throw new Error(await res.text() || `HTTP ${res.status}`);
@@ -64,15 +68,24 @@ export class MarketplacePage extends LightElement {
window.addEventListener('llm-page-change', (e) => {
this._open = e.detail.page === 'marketplace';
this.style.display = this._open ? 'flex' : 'none';
if (this._open) this._load();
if (this._open) { this._load(); this._publishViewContext(); }
else clearSlice(VIEW_SLICE);
});
}
disconnectedCallback() {
window.removeEventListener('locale-changed', this.__onLocaleChanged);
clearSlice(VIEW_SLICE);
super.disconnectedCallback();
}
// The entity slice: the active search filter, if any. An empty box is no
// slice at all, and it is the search term — never a card's fields.
_publishViewContext() {
const q = this._q.trim();
setSlice(VIEW_SLICE, q ? [{ label: 'Search', value: q }] : null);
}
get _isAdmin() { return this._me?.role_id === ADMIN_ID; }
async _load() {
@@ -209,7 +222,7 @@ export class MarketplacePage extends LightElement {
<div class="connector-search">
<i class="bi bi-search"></i>
<input class="form-control form-control-sm" placeholder=${t('marketplace.filter.search')}
.value=${this._q} @input=${(e) => { this._q = e.target.value; }} />
.value=${this._q} @input=${(e) => { this._q = e.target.value; this._publishViewContext(); }} />
</div>
${this._segment(t('marketplace.filter.scope'), this._scope, (v) => { this._scope = v; },
[[t('marketplace.filter.all'), 'all'], [t('marketplace.filter.global'), 'global'], [t('marketplace.filter.per_user'), 'per_user']])}