From 94f050fea13bf20c6f4cc16925d9ee9829ec19f2 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Fri, 22 May 2026 13:32:33 +0200 Subject: [PATCH 1/3] feat(chat): support agentId to auto-select persona MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass an optional agent-id attribute through NxChat → ChatController so the request body includes agentId, allowing da-agent to resolve a built-in or content-bus preset automatically. Co-authored-by: Cursor --- nx2/blocks/chat/chat-controller.js | 5 +++++ nx2/blocks/chat/chat.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/nx2/blocks/chat/chat-controller.js b/nx2/blocks/chat/chat-controller.js index 0b1f9e072..50ee554ac 100644 --- a/nx2/blocks/chat/chat-controller.js +++ b/nx2/blocks/chat/chat-controller.js @@ -19,6 +19,10 @@ export default class ChatController { this._room = null; } + setAgentId(id) { + this._agentId = id; + } + _pageContextForAgent() { const { org, site, path, view } = this._context ?? {}; return org && site ? { org, site, path: path ?? '', view } : undefined; @@ -222,6 +226,7 @@ export default class ChatController { pageContext, imsToken: accessToken?.token ?? null, room, + ...(this._agentId ? { agentId: this._agentId } : {}), ...(this._requestedSkills?.length ? { requestedSkills: this._requestedSkills } : {}), }), signal: this._abortController.signal, diff --git a/nx2/blocks/chat/chat.js b/nx2/blocks/chat/chat.js index 424105585..c925e509b 100644 --- a/nx2/blocks/chat/chat.js +++ b/nx2/blocks/chat/chat.js @@ -32,6 +32,7 @@ class NxChat extends LitElement { thinking: { type: Boolean }, connected: { type: Boolean }, toolCards: { type: Object }, + agentId: { type: String, attribute: 'agent-id' }, _prompts: { state: true }, _items: { state: true }, }; @@ -174,6 +175,7 @@ class NxChat extends LitElement { }, }); if (this._context) this._controller.setContext(this._context); + if (this.agentId) this._controller.setAgentId(this.agentId); this._unsubscribeHash = hashChange.subscribe((state) => { if (!this._explicitContext) this._applyContext(state); @@ -215,6 +217,9 @@ class NxChat extends LitElement { }; updated(changed) { + if (changed.has('agentId') && this._controller) { + this._controller.setAgentId(this.agentId); + } if (changed.has('messages')) { const log = this.shadowRoot.querySelector('.chat-scroll-container'); if (log) requestAnimationFrame(() => { log.scrollTop = log.scrollHeight; }); From 5cb894f97ee0f28d96b93c22f6c4937756256f2e Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Wed, 8 Jul 2026 15:46:50 +0200 Subject: [PATCH 2/3] refactor(chat): make agent-id a plain attribute, not a reactive prop - read agent-id via getAttribute at mount instead of a reactive Lit property, avoiding needless re-renders when it changes - drop the updated() handler for agentId; the value is read once before mount - document the agent-id attribute and its request-body contract in chat-ui-component.md Co-Authored-By: Claude Opus 4.8 --- docs/chat-ui-component.md | 8 +++++++- nx2/blocks/chat/chat.js | 7 ++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/chat-ui-component.md b/docs/chat-ui-component.md index 92cf3a2e6..3c1bef123 100644 --- a/docs/chat-ui-component.md +++ b/docs/chat-ui-component.md @@ -22,6 +22,12 @@ The component manages its own controller internally. No external wiring needed. | `thinking` | `Boolean` | Agent is processing. Disables input. | | `context` | `Object` | Page context: `{ org, site, path, view }`. Required — set by the host view. `view` must be `browse` or `edit`. | +## Attributes in + +| Attribute | Type | Description | +| ---------- | -------- | ----------------------------------------------------------------------------------------------- | +| `agent-id` | `String` | Optional. Selects a specific agent/persona. Read once on mount and forwarded to the agent as `agentId` in the request body. Not a reactive property — set it before mount; later changes are not observed. | + **Message shape:** ```js @@ -30,7 +36,7 @@ The component manages its own controller internally. No external wiring needed. { role: 'tool', ... } // filtered from display automatically ``` -**Request body:** The controller POSTs `{ messages, pageContext, imsToken, room, sessionId }` to the agent. `sessionId` is a UUID scoped to the current conversation session — it resets when the user clears the chat. Selection context is embedded on individual user messages (see [Selection context](#selection-context)) rather than as a top-level request field. +**Request body:** The controller POSTs `{ messages, pageContext, imsToken, room, sessionId }` to the agent (plus `agentId` when the `agent-id` attribute is set). `sessionId` is a UUID scoped to the current conversation session — it resets when the user clears the chat. Selection context is embedded on individual user messages (see [Selection context](#selection-context)) rather than as a top-level request field. ## Methods diff --git a/nx2/blocks/chat/chat.js b/nx2/blocks/chat/chat.js index c925e509b..bb53be4ee 100644 --- a/nx2/blocks/chat/chat.js +++ b/nx2/blocks/chat/chat.js @@ -32,7 +32,6 @@ class NxChat extends LitElement { thinking: { type: Boolean }, connected: { type: Boolean }, toolCards: { type: Object }, - agentId: { type: String, attribute: 'agent-id' }, _prompts: { state: true }, _items: { state: true }, }; @@ -175,7 +174,8 @@ class NxChat extends LitElement { }, }); if (this._context) this._controller.setContext(this._context); - if (this.agentId) this._controller.setAgentId(this.agentId); + const agentId = this.getAttribute('agent-id'); + if (agentId) this._controller.setAgentId(agentId); this._unsubscribeHash = hashChange.subscribe((state) => { if (!this._explicitContext) this._applyContext(state); @@ -217,9 +217,6 @@ class NxChat extends LitElement { }; updated(changed) { - if (changed.has('agentId') && this._controller) { - this._controller.setAgentId(this.agentId); - } if (changed.has('messages')) { const log = this.shadowRoot.querySelector('.chat-scroll-container'); if (log) requestAnimationFrame(() => { log.scrollTop = log.scrollHeight; }); From 8eb2b12a2e4e0b2a3748fdb35e1263578ebd48f4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 8 Jul 2026 16:32:41 +0200 Subject: [PATCH 3/3] Update worklog --- WORKLOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/WORKLOG.md b/WORKLOG.md index b400f35d2..38d16ea08 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -1,5 +1,19 @@ # Worklog +## 2026-07-08 + +### nx2/blocks/chat — agent-id as a plain attribute (feat/chat-agent-id branch, PR #462) + +Reviewer consensus (sharanyavinod + mhaack) on #462: `agentId` should not be a reactive Lit property since it is not used for rendering. Keeping it reactive re-renders `` on `agent-id` changes for no benefit today. + +- Removed `agentId: { type: String, attribute: 'agent-id' }` from `static properties`. +- Read the value once in `connectedCallback` via `getAttribute('agent-id')` and forward it to the controller's `setAgentId`. +- Dropped the `agentId` branch from `updated(changed)` (no longer observed). +- Controller plumbing unchanged: `setAgentId` stores `_agentId`, sent as `agentId` in the request body only when set. +- Documented the `agent-id` attribute and its request-body contract in `docs/chat-ui-component.md`. + +If we later drive rendering from the agent id, reintroduce it as a reactive property then (per the review thread). + ## 2026-06-23 ### nx2/blocks/shared/dialog — configurable panel sizing (dialog-css-vars branch)