feat(chat): view context — tell the assistant what you're looking at
Nightly Build / build (push) Successful in 7m51s
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:
@@ -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 { jf, schemaFields, pluginHealth } from './shared/plugin-common.js';
|
||||
|
||||
// One plugin's admin page (`#plugin-detail?id=<plugin id>`), reached from the
|
||||
@@ -21,6 +22,9 @@ import { jf, schemaFields, pluginHealth } from './shared/plugin-common.js';
|
||||
|
||||
const PAGE_ID = 'plugin-detail';
|
||||
|
||||
/// The view-context slice this page owns (see `lib/view-context.js`).
|
||||
const VIEW_SLICE = 'entity@plugin-detail';
|
||||
|
||||
function idFromHash() {
|
||||
const m = location.hash.match(/^#plugin-detail\?id=(.*)$/);
|
||||
if (!m) return null;
|
||||
@@ -68,6 +72,7 @@ export class PluginDetailPage extends LightElement {
|
||||
this._open = e.detail.page === PAGE_ID;
|
||||
this.style.display = this._open ? 'flex' : 'none';
|
||||
if (this._open) this._loadFromHash();
|
||||
else clearSlice(VIEW_SLICE);
|
||||
});
|
||||
window.addEventListener('hashchange', () => {
|
||||
if (this._open) this._loadFromHash();
|
||||
@@ -76,15 +81,19 @@ export class PluginDetailPage extends LightElement {
|
||||
|
||||
disconnectedCallback() {
|
||||
window.removeEventListener('locale-changed', this.__onLocaleChanged);
|
||||
clearSlice(VIEW_SLICE);
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
async _loadFromHash() {
|
||||
const id = idFromHash();
|
||||
if (!id) return;
|
||||
if (!id) { clearSlice(VIEW_SLICE); return; }
|
||||
// A different plugin must not inherit the previous one's typed config.
|
||||
if (id !== this._id) this._reset();
|
||||
this._id = id;
|
||||
// The entity slice: which plugin is open. The id is the whole answer — a
|
||||
// detail page says *which* object, never what its config holds.
|
||||
setSlice(VIEW_SLICE, [{ label: 'Open plugin', value: id }]);
|
||||
await this._load();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user