diff --git a/WORKLOG.md b/WORKLOG.md index 6758e44ee..f3d1ec991 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-26 ### nx2/blocks/chat/chat.js — skill selection preserves pending attachments (feat/da-skill-attachment-fix) @@ -14,7 +28,6 @@ Post-review follow-up (fe049a9b): - Renamed loop variable `i` → `item` in `_onSlashSelect` callbacks - Added regression tests in `test/nx2/blocks/chat/chat.test.js` (8 tests, all pass) - ## 2026-06-23 ### nx2/blocks/shared/dialog — configurable panel sizing (dialog-css-vars branch) diff --git a/docs/chat-ui-component.md b/docs/chat-ui-component.md index 66ae0dd39..e2d5da26d 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-controller.js b/nx2/blocks/chat/chat-controller.js index 02da447a1..25c9465fc 100644 --- a/nx2/blocks/chat/chat-controller.js +++ b/nx2/blocks/chat/chat-controller.js @@ -88,6 +88,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; @@ -370,6 +374,7 @@ export default class ChatController { pageContext, imsToken: accessToken?.token ?? null, room, + ...(this._agentId ? { agentId: this._agentId } : {}), sessionId: this._sessionId, ...(this._requestedSkills?.length ? { requestedSkills: this._requestedSkills } : {}), ...(this._pendingAttachments?.length ? { attachments: this._pendingAttachments } : {}), diff --git a/nx2/blocks/chat/chat.js b/nx2/blocks/chat/chat.js index 6c83c7b67..73019790c 100644 --- a/nx2/blocks/chat/chat.js +++ b/nx2/blocks/chat/chat.js @@ -211,6 +211,8 @@ class NxChat extends LitElement { }, }); if (this._context) this._controller.setContext(this._context); + const agentId = this.getAttribute('agent-id'); + if (agentId) this._controller.setAgentId(agentId); this._unsubscribeHash = hashChange.subscribe((state) => { if (!this._explicitContext) this._applyContext(state);