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:
@@ -2,9 +2,13 @@ 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';
|
||||
|
||||
const PAGE_ID = 'session';
|
||||
|
||||
/// The view-context slice this page owns (see `lib/view-context.js`).
|
||||
const VIEW_SLICE = 'entity@session';
|
||||
|
||||
function formatDate(iso) {
|
||||
if (!iso) return '—';
|
||||
return new Date(iso).toLocaleString(undefined, {
|
||||
@@ -64,7 +68,7 @@ export class SessionDetailPage extends LightElement {
|
||||
this._open = e.detail.page === PAGE_ID;
|
||||
this.style.display = this._open ? 'flex' : 'none';
|
||||
if (this._open) this._loadFromHash();
|
||||
else this._closeWs();
|
||||
else { this._closeWs(); clearSlice(VIEW_SLICE); }
|
||||
};
|
||||
this.__onHashChange = () => {
|
||||
if (this._open) this._loadFromHash();
|
||||
@@ -79,6 +83,7 @@ export class SessionDetailPage extends LightElement {
|
||||
window.removeEventListener('llm-page-change', this.__onPageChange);
|
||||
window.removeEventListener('hashchange', this.__onHashChange);
|
||||
this._closeWs();
|
||||
clearSlice(VIEW_SLICE);
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
@@ -90,7 +95,10 @@ export class SessionDetailPage extends LightElement {
|
||||
|
||||
_loadFromHash() {
|
||||
const id = this._idFromHash();
|
||||
if (id == null) return;
|
||||
if (id == null) { clearSlice(VIEW_SLICE); return; }
|
||||
// The entity slice: which conversation is open. Published before the fetch
|
||||
// — a message sent while the transcript loads is still about this session.
|
||||
setSlice(VIEW_SLICE, [{ label: 'Open conversation', value: `#${id}` }]);
|
||||
// Reload on the same id too when the socket is down: leaving the page closes
|
||||
// it, so coming back to the session we already hold would otherwise show a
|
||||
// frozen snapshot with nothing streaming into it.
|
||||
|
||||
Reference in New Issue
Block a user