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,10 +1,18 @@
|
||||
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';
|
||||
|
||||
const PAGE_ID = 'llm-requests';
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
/// The view-context slice this page owns (see `lib/view-context.js`). It is
|
||||
/// published from here and not from `<llm-request-detail>` on purpose: the
|
||||
/// detail stays connected (only `display:none`) while the page is hidden, so
|
||||
/// the host — which knows both `_open` and `_detailId` — is the one place that
|
||||
/// can guarantee the slice never describes a page nobody is looking at.
|
||||
const VIEW_SLICE = 'entity@llm-requests';
|
||||
|
||||
function formatDate(iso) {
|
||||
if (!iso) return '—';
|
||||
return new Date(iso).toLocaleString(undefined, {
|
||||
@@ -75,14 +83,24 @@ export class LlmRequestsPage extends LightElement {
|
||||
this._detailId = id;
|
||||
if (id == null && this._items.length === 0) this._fetch(1);
|
||||
}
|
||||
this._publishViewContext();
|
||||
});
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
window.removeEventListener('locale-changed', this.__onLocaleChanged);
|
||||
clearSlice(VIEW_SLICE);
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
// The entity slice: which request is open, if any. On the list there is none
|
||||
// — the route slice already describes it.
|
||||
_publishViewContext() {
|
||||
setSlice(VIEW_SLICE, this._open && this._detailId != null
|
||||
? [{ label: 'Open LLM request', value: `#${this._detailId}` }]
|
||||
: null);
|
||||
}
|
||||
|
||||
_idFromHash() {
|
||||
const parts = location.hash.replace('#', '').split('/');
|
||||
if (parts[0] === PAGE_ID && parts[1]) {
|
||||
@@ -94,11 +112,13 @@ export class LlmRequestsPage extends LightElement {
|
||||
|
||||
_openDetail(id) {
|
||||
this._detailId = id;
|
||||
this._publishViewContext();
|
||||
history.pushState({}, '', `#${PAGE_ID}/${id}`);
|
||||
}
|
||||
|
||||
_back() {
|
||||
this._detailId = null;
|
||||
this._publishViewContext();
|
||||
history.pushState({}, '', `#${PAGE_ID}`);
|
||||
if (this._items.length === 0) this._fetch(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user