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
+22 -2
View File
@@ -1,6 +1,7 @@
import { html, nothing } from 'lit';
import { LightElement } from '../lib/base.js';
import { t } from '../lib/i18n.js';
import { setSlice, clearSlice } from '../lib/view-context.js';
import {
announceChange, authLabel, connectorIconUrl, jf, normalizeSchema, parseJson, seedEnv, statusOf,
} from './shared/connector-common.js';
@@ -23,6 +24,9 @@ import {
const ADMIN_ID = 'admin';
const PAGE_ID = 'connector';
/// The view-context slice this page owns (see `lib/view-context.js`).
const VIEW_SLICE = 'entity@connector';
function nameFromHash() {
const m = location.hash.match(/^#connector\?name=(.*)$/);
if (!m) return null;
@@ -82,7 +86,10 @@ export class ConnectorDetailPage extends LightElement {
this._open = e.detail.page === PAGE_ID;
this.style.display = this._open ? 'flex' : 'none';
if (this._open) this._loadFromHash();
else this._stopQrPoll(); // never poll a connector's login off-screen
else {
this._stopQrPoll(); // never poll a connector's login off-screen
clearSlice(VIEW_SLICE);
}
});
window.addEventListener('hashchange', () => {
if (this._open) this._loadFromHash();
@@ -92,6 +99,7 @@ export class ConnectorDetailPage extends LightElement {
disconnectedCallback() {
window.removeEventListener('locale-changed', this.__onLocaleChanged);
this._stopQrPoll();
clearSlice(VIEW_SLICE);
super.disconnectedCallback();
}
@@ -106,13 +114,24 @@ export class ConnectorDetailPage extends LightElement {
async _loadFromHash() {
const name = nameFromHash();
if (!name) return;
if (!name) { clearSlice(VIEW_SLICE); return; }
// A different connector must not inherit the previous one's typed secrets.
if (name !== this._name) this._reset();
this._name = name;
// Say which connector is open before the fetch lands — the status line is
// added by `_load` once the runtime rows are known.
this._publishViewContext(false);
await this._load();
}
// The entity slice: which connector this page is about, and — once loaded —
// its state. Never a config value or a credential: *which*, not *what's in it*.
_publishViewContext(withStatus) {
if (!this._name) return;
const value = withStatus ? `${this._name} (status: ${this._status})` : this._name;
setSlice(VIEW_SLICE, [{ label: 'Open connector', value }]);
}
async _load() {
this._error = null;
try {
@@ -133,6 +152,7 @@ export class ConnectorDetailPage extends LightElement {
this._entry = entry;
this._glob = glob;
this._act = act;
this._publishViewContext(true);
const schema = normalizeSchema(parseJson(entry?.config_schema_json, []));
this._schema = schema;