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,14 @@
|
||||
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 { fetchToolDetail, renderToolBody, STATUS_ICON } from './shared/tool-detail-view.js';
|
||||
|
||||
const PAGE_ID = 'tool_detail';
|
||||
|
||||
/// The view-context slice this page owns (see `lib/view-context.js`).
|
||||
const VIEW_SLICE = 'entity@tool_detail';
|
||||
|
||||
function idFromHash() {
|
||||
const h = location.hash;
|
||||
const prefix = `#${PAGE_ID}?id=`;
|
||||
@@ -45,20 +49,32 @@ export class ToolDetailPage 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();
|
||||
});
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
clearSlice(VIEW_SLICE);
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
async _loadFromHash() {
|
||||
const id = idFromHash();
|
||||
if (id == null) return;
|
||||
if (id == null) { clearSlice(VIEW_SLICE); return; }
|
||||
this._loading = true;
|
||||
this._error = null;
|
||||
this._tool = null;
|
||||
try {
|
||||
this._tool = await fetchToolDetail(id);
|
||||
// The entity slice: which tool this call ran. Only published on success —
|
||||
// the hash carries the call's id, which tells the model nothing.
|
||||
setSlice(VIEW_SLICE, [{
|
||||
label: 'Open tool call',
|
||||
value: this._tool.display_name || this._tool.name,
|
||||
}]);
|
||||
} catch (e) {
|
||||
this._error = e.message || String(e);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user