Skip to content

Commit 6afa421

Browse files
ericdalloeca-agent
andcommitted
Forward chatId on chat selection notifications
The bridge's outbound handler now prefers an explicit data.chatId (supplied by the webview after the per-chat scoping fix) when forwarding chat/selectedModelChanged, chat/selectedAgentChanged, and chat/selectedVariantChanged to the remote REST endpoints, falling back to ctx.getCurrentChatId() when the webview omits it. Forward- compatible: works against both the previous webview submodule (which did not emit chatId) and the new one. Bumps eca-webview submodule to pick up the matching webview-side changes (Phase A drops the 'EMPTY' chat-id sentinel and mints a UUID upfront; Phase B includes chatId in the host messages and applies config/updated per-chat when scoped). editor-code-assistant/eca-emacs#231 🤖 Generated with [eca](https://eca.dev) Co-Authored-By: eca-agent <git@eca.dev>
1 parent 536f208 commit 6afa421

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/bridge/outbound-handler.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,19 @@ export async function handleOutbound(
104104
await api.answerQuestion(data.requestId, data.answer, data.cancelled);
105105
break;
106106

107-
// --- Config changes (apply to current chat) ---
107+
// --- Config changes (apply to the chat the webview targets, falling
108+
// back to the current chat for older webview versions that don't
109+
// forward chatId in the message). ---
108110
case 'chat/selectedModelChanged':
109-
await withCurrentChat(ctx, (chatId) => api.changeModel(chatId, data.model));
111+
await withTargetChat(ctx, data.chatId, (chatId) => api.changeModel(chatId, data.model));
110112
break;
111113

112114
case 'chat/selectedAgentChanged':
113-
await withCurrentChat(ctx, (chatId) => api.changeAgent(chatId, data.agent));
115+
await withTargetChat(ctx, data.chatId, (chatId) => api.changeAgent(chatId, data.agent));
114116
break;
115117

116118
case 'chat/selectedVariantChanged':
117-
await withCurrentChat(ctx, (chatId) => api.changeVariant(chatId, data.variant));
119+
await withTargetChat(ctx, data.chatId, (chatId) => api.changeVariant(chatId, data.variant));
118120
break;
119121

120122
// --- Editor operations ---
@@ -303,14 +305,17 @@ async function handleUserPrompt(data: UserPromptData, ctx: OutboundContext): Pro
303305
}
304306

305307
/**
306-
* Run an action against the current chat ID, silently catching errors.
307-
* Used for config changes (model/agent/variant) which are best-effort.
308+
* Run an action against an explicit chat ID when the webview provides one,
309+
* otherwise fall back to the current session-wide chat ID. Errors are
310+
* silently caught — these config changes (model/agent/variant) are
311+
* best-effort and must not break the UI.
308312
*/
309-
async function withCurrentChat(
313+
async function withTargetChat(
310314
ctx: OutboundContext,
315+
explicitChatId: string | undefined,
311316
action: (chatId: string) => Promise<void>,
312317
): Promise<void> {
313-
const chatId = ctx.getCurrentChatId();
318+
const chatId = explicitChatId || ctx.getCurrentChatId();
314319
if (chatId) {
315320
await action(chatId).catch(() => {});
316321
}

src/bridge/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ export type OutboundMessage =
249249
| { type: 'chat/removeFlag'; data: { chatId: string; contentId: string } }
250250
| { type: 'chat/fork'; data: { chatId: string; contentId: string } }
251251
| { type: 'chat/answerQuestion'; data: { requestId: string; answer: string | null; cancelled: boolean } }
252-
| { type: 'chat/selectedModelChanged'; data: { model: string } }
253-
| { type: 'chat/selectedAgentChanged'; data: { agent: string } }
254-
| { type: 'chat/selectedVariantChanged'; data: { variant: string } }
252+
| { type: 'chat/selectedModelChanged'; data: { model: string; chatId?: string; variant?: string } }
253+
| { type: 'chat/selectedAgentChanged'; data: { agent: string; chatId?: string } }
254+
| { type: 'chat/selectedVariantChanged'; data: { variant: string; chatId?: string } }
255255
| { type: 'editor/openUrl'; data: { url: string } }
256256
| { type: 'editor/openFile'; data: unknown }
257257
| { type: 'editor/openGlobalConfig'; data: unknown }

0 commit comments

Comments
 (0)