// Honcho user opt-in page (page_id `memory`, visible to any user with a // `plugin_access` grant). // // The per-user consent to long-term memory. Reuses the core per-user config // endpoints — `GET /api/plugins/mine` to read the current flag, // `PUT /api/plugins/honcho/my-config` to save `{ enabled }` — so this fragment // needs no backend of its own. Structured in sections so the future "what does // Honcho know about me?" panel is a drop-in addition (see the `soon` section). // Default-exports the element class; the host registers it. import { html, nothing } from 'lit'; import { HonchoBase, jf, t } from './common.js'; const P = 'plugin.honcho'; const ID = 'honcho'; export default class HonchoMemoryPage extends HonchoBase { static get properties() { return { _row: { state: true }, // UserPluginView | null (null once loaded = not granted) _enabled: { state: true }, // draft toggle _status: { state: true }, // { ok?, err? } _error: { state: true }, _loading: { state: true }, }; } constructor() { super(); this._row = null; this._enabled = false; this._status = {}; this._error = null; this._loading = true; } connectedCallback() { super.connectedCallback(); this._load(); } async _load() { this._loading = true; this._error = null; try { const mine = await jf('/api/plugins/mine'); const row = (mine ?? []).find(x => x.id === ID) ?? null; this._row = row; this._enabled = !!row?.user_config?.enabled; } catch (e) { this._error = e.message; } finally { this._loading = false; } } async _save() { this._status = {}; try { await jf(`/api/plugins/${ID}/my-config`, { method: 'PUT', body: JSON.stringify({ enabled: this._enabled }), }); this._status = { ok: t(`${P}.memory.saved`) }; await this._load(); } catch (e) { this._status = { err: e.message }; } } render() { return html`

${t(`${P}.memory.title`)}

${this._error ? html`
${this._error}
` : nothing} ${this._loading ? html`
${t(`${P}.memory.loading`)}
` : this._row ? this._renderBody() : this._renderUnavailable()}
`; } _renderUnavailable() { return html`

${t(`${P}.memory.unavailable`)}

`; } _renderBody() { return html`

${t(`${P}.memory.intro`)}

${t(`${P}.memory.privacy_title`)}
${t(`${P}.memory.privacy_body`)}
{ this._enabled = e.target.checked; this._status = {}; }} />
${this._status.err ? html`
${this._status.err}
` : nothing} ${this._status.ok ? html`
${this._status.ok}
` : nothing} ${this._renderSoon()}`; } // Placeholder for the future "what does Honcho know about me?" panel. When // built, this section gains a button that calls a new `GET ${this.api}/whoami` // (opt-in-gated) and renders the returned summary; only this method + that one // route change. _renderSoon() { if (!this._enabled) return nothing; return html`
${t(`${P}.memory.soon_title`)}
${t(`${P}.memory.soon_body`)}
`; } }