Skip to content

Commit 4af32b9

Browse files
feat(app-shell): Ask AI opens a new conversation after the user's own close, and the drawer header names the conversation (#37970)
repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU <!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoK5FfvaJPRjBoGxoAHny6iN)_ Fixes #37860 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:所有用户点「问 AI」时,如果上次是自己关掉的助手(或这个标签页第一次打开),就开一个新会话,旧会话留在历史里;手机上点答案里的链接被自动收起、或有待确认的写入时,仍回到原会话。抽屉顶部改为会话标题、+、历史图标、⋯、×。 - 为什么做:「问 AI」入口改造专题的第四张卡,解决从别的记录再问时落进上一个旧会话、问题被混在一起的问题。 - 出错会怎样:最坏是本该续上的会话开成了新会话(或反过来),用户可从历史里点回原会话,不丢数据;没发消息前不会产生空会话。直接撤回这次改动即恢复原样。 - 要你做什么:无。 ## What changes Implements every row of ui ADR-0057 Amendment A5's open-type table (as merged, `bc173343`). Where the card's text and A5 differ, A5 wins (claim 7218853868). 1. **Who closed the drawer is recorded.** `useConsoleChatDock` writes one per-tab record at each close (sessionStorage, module copy when storage throws): `by: user` for ×, the entry or the keyboard toggle again, and dismissing the phone sheet; `by: console` for the phone sheet's PUSH/POP collapse (objectstack#37556) and the A4 ask-page collapse; plus the conversation the body showed then (`onShownConversationChange`, reported by `ChatDockConversation`). 2. **An opening from the entry** (`openEntry` on the dock handle; the top bar's 「Ask AI」 toggle, the keyboard toggle, Home's 「Ask AI」 through `useAskAiEntry`, and the record pane's button) reads that record through the pure `entryOpening`: - row 1 / row 4: after the user's close, or with no record (first opening in the tab) → a new conversation, target `{ agent?, fresh: true }`, which reaches `useChatConversation` as `forceNew` only (never `resumeMode: 'fresh'`), so no row exists until the first send; - row 2: after the console's close → the same conversation; - row 3: a write awaiting this user's approval in the conversation shown at the close → that conversation (read off the assistant bus with `isApprovalPendingIn`); - row 8: a build thread (a target naming `build` or a package, or `app.defaultAgent: 'build'` with no target agent) → as before; - rows 5, 6, 7, 9 are untouched: `open(target)`, a reload, the bus's `requestAssistantOpen`, filling the window. An entry that names an agent (Home's `ask`) keeps the closed thread only when it is that agent's. 3. **Write approvals reach the bus** (A5's "Not recorded yet" bullet). `ChatPane` counts the tool calls the framework parked as pending actions (`approval-requested` with a `pendingActionId`) that have no decision, or a failed one, in the chat (`countWritesAwaitingApproval`), and publishes the count per conversation with `publishPlanApprovalPending`. The reading outlives the pane, as the bus intends. 4. **The header row**, the same in the rail, the full window and the phone sheet: the conversation's label on the left as its history row reads it (server title, else the latest user message: `useConversationLabel`, the list's own `normalize` on the detail read; the first message stands in until the server answers), "New conversation" (`console.ai.newConversation`, the history list's own fallback) before the first send, nothing while an existing label is read. Right: + (the body's new-conversation action), the history as an icon button with `aria-pressed` and both names (rail and sheet only; the full window keeps the column), ⋯ unchanged, × (the sheet keeps its own ✕ last). No ☆ (C8). 5. **C3's hand-over items.** The record pane's and the record drawer stack's `record-pane-open-assistant` button reads 「Ask AI」 (`home.askAI`) with the chat-bubble icon and opens as the entry does. The drawer is no longer titled "AI Assistant"; the objectstack#34827 pin now pins the new rule. No new i18n key: the title and + reuse `console.ai.newConversation`, the history button keeps `console.ai.dock.history` / `backToChat`. ## Tests - `useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx`, new top-level describe (the hook's shared harness): A5 rows 1 (first opening; ×; entry and keyboard closes; sheet dismissal), 2, 3 (and its control: another conversation, another user), 5, 6 (reload is no opening; the record survives a reload), 7, 8 (defaultAgent build; a build target with a package), Home's 「Ask AI」 after a build thread, and with the drawer open. The stand-ins now report the shown conversation and offer × and dismissal. - `ChatDock.test.tsx`, new describe: the header row in rail / full / sheet, the label, "New conversation", nothing while pending, the history icon's pressed state and names, + calling the body's action and closing the history. - `ChatDock.titleMatchesTopBar-34827.test.tsx` rewritten to "drawer title = the conversation's label, 「新对话」 / "New conversation" before the first send", real packs, every built-in pack. - `writeApprovalPending-37860.test.tsx`: real hydration of stored rows and the real `useHitlInChat` decisions → pending, cleared by an approval, kept by a failed one; control with no parked write. - `AiChatPage.toolLabelsLocale-11667.test.tsx`, new describe: the real `ChatPane` publishes the pending write for its conversation and clears it after the user's reject. - `recordDrawerAssistant-36998.test.tsx`, `ObjectDataPage.openRule-35875.test.tsx`: the pane button's name is 「Ask AI」 and its click is an entry opening. Ablation (on disk, restored from the commit): every entry opening forced to `same` → 7 of 30 cases in the hook harness red (all row-1 cases, the row-3 control, row 6, Home's entry). `ChatPane` publishing `pending: false` → the pane pin red (1 of 3). <details><summary>Readings</summary> - Related suite at `db93e901` + tests (every ui test file naming ChatDock, useConsoleChatDock, AssistantTopBarButton, ChatPane/AiChatPage, Console/Home layout, HomePage, the conversation list or sidebar, recordDrawerStack, ObjectDataPage, assistantBus, chatDockControl, DocsPortalShell): 327 files / 3893 tests passed. - After the last source change (`5d407804`): every ui test file naming ChatDock or useConsoleChatDock, 28 files / 305 tests passed. - `pnpm --filter @object-ui/app-shell run type-check` (src and `tsconfig.test.json`): exit 0, after building the dependency closure. - eslint on the changed files: 0 errors; no new warning on the changed lines. - `overlap-check.mjs` before the first push: clean against main, #37924 (shares `ChatDockConversation.tsx`) and #37940 (shares `useConversationList.ts`). </details> ## Acceptance notes - **zh title wording.** C3's note said 「新会话」; A5 says the header reads the history row's label and "New conversation" before the first send. The history list's own fallback is `console.ai.newConversation`, which reads 「新对话」 in zh-Hans, so the header reads 「新对话」. No pack changed. - **The amber marker now also lights for a pending write.** Write approvals reach the bus that the entry's marker (and Studio's 「N 项待确认」 count) read. Its description, `console.ai.dock.planAwaitingApproval`, now reads "An action is waiting for your approval" (「有一项操作等待确认」) in all eleven packs, with the key unchanged. That was L1-c's R1 (7220360349), fixed at `12ae1bed`. - **The record pane's button stays an icon** in the pane's top bar (the bar's own button shape), named 「Ask AI」 with the chat-bubble icon, not the outlined text button of the page header. - **Home's 「Ask AI」 with the drawer already open** is no opening; it opens on the `ask` agent as before. - **Label read.** The header reads the shown conversation's detail once per open and after each send (the same refresh cadence as the history list). That is a second read of a conversation the body already hydrates. - **Reload limits.** The approval reading lives in the page's memory (A5: "in the page's memory only"); after a reload, row 3 holds again once the chat is next mounted on that conversation. - **File surface.** Three files outside the claim's first glob, added to the claim by the seat (7218893089): `views/ObjectDataPage.tsx`, `views/recordDrawerStack.tsx`, `console/ai/ChatPane.tsx`. Plus `assistant/writeApprovalPending.ts` (new, inside the glob). - Ships in the same release as C5 (objectstack#37861), per the card. ## Verification Read first, by risk: 1. `ui/packages/app-shell/src/layout/useConsoleChatDock.tsx`: `entryOpening`, `openEntry`, `closeBy` and which close paths call it. 2. `ui/packages/app-shell/src/layout/ChatDockConversation.tsx`: the shown-conversation report and the header actions. 3. `ui/packages/app-shell/src/console/ai/ChatPane.tsx`: the bus publish effect. Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx`. Expected: 30 passed. In the Console: open 「问 AI」, send a message, close with ×, click 「问 AI」 again: the header reads 「新对话」 and the old thread is in history. --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibzv3KSUSav5J2uw97s)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ecd10e9 commit 4af32b9

33 files changed

Lines changed: 1098 additions & 168 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(app-shell): opening the assistant from 「Ask AI」 after closing it starts a new conversation, and the drawer's header names the conversation (ui ADR-0057 Amendment A5)
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
- **What an opening from the entry shows.** The entry is the top bar's 「Ask AI」 button, the keyboard toggle (Ctrl/Cmd+Shift+I), Home's 「Ask AI」 and the record pane's 「Ask AI」. After the user closes the drawer (×, the entry or the toggle again, dismissing the phone sheet), and the first time in a browser tab, it opens a new conversation; the last one stays in history. After the console closed the phone sheet because the page under it moved (a link in an answer, Back), it shows the same conversation. While a write the AI proposed waits for the user's approval in the conversation shown at the close, it shows that conversation. A build conversation (the `build` agent, a package, an app whose `defaultAgent` is `build`) opens as before. A named conversation (a history row, an `/ai…` address), a reload, the assistant bus and filling the window are unchanged.
12+
- **A new conversation leaves no empty row.** It is started with `forceNew`: nothing is created until the first message is sent.
13+
- **The header.** One row in the side panel, the full window and the phone sheet: the conversation's label as the history list shows it ("New conversation" before the first send), then + (a new conversation), the history as an icon button (side panel and sheet; the full window shows the history beside the chat), 「···」 and ×. The drawer is no longer titled "AI Assistant".
14+
- **Writes awaiting approval reach the assistant bus.** The chat now records, per conversation, an AI-proposed write that waits for the user's approval, so the entry's amber marker also shows for it while the chat is closed. The marker's text (`console.ai.dock.planAwaitingApproval`, key unchanged) now reads "An action is waiting for your approval" (「有一项操作等待确认」) in every pack, since no plan is published any more.
15+
- **The record pane's assistant button** reads 「Ask AI」 with the chat-bubble icon, like the top bar's, and opens as the entry does.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* ui ADR-0057 Amendment A5, row 3 (objectstack#37860) — a conversation holds a
5+
* write awaiting the user's approval while a proposed write the framework
6+
* parked as a pending action has no decision in the chat, or one that failed.
7+
*
8+
* ## Real subjects
9+
*
10+
* The real hydration of stored server rows (the path a reopened conversation
11+
* takes) and the real `useHitlInChat` decisions, as `ChatPane` hands both to
12+
* `countWritesAwaitingApproval` before publishing the answer to the bus.
13+
*/
14+
15+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
16+
import { act, renderHook } from '@testing-library/react';
17+
// `ChatPane` reaches `import('@object-ui/plugin-grid')`; pay its first load at
18+
// collection, never inside a clocked case (`check:test-source-alias`).
19+
import '@object-ui/plugin-grid';
20+
import { useHitlInChat } from '@object-ui/plugin-chatbot';
21+
import { hydratedMessagesToChatMessages } from '../../console/ai/AiChatPage';
22+
import { aiMessageRowsToServerMessages, toUIMessages } from '../../hooks/useChatConversation';
23+
import { countWritesAwaitingApproval } from '../writeApprovalPending';
24+
25+
/** A stored conversation whose last tool call came back as a pending approval. */
26+
function hydratePendingWrite() {
27+
return hydratedMessagesToChatMessages(
28+
toUIMessages(
29+
aiMessageRowsToServerMessages([
30+
{ id: 'u1', role: 'user', content: 'delete the task' },
31+
{
32+
id: 'a1',
33+
role: 'assistant',
34+
content: 'This needs your approval.',
35+
tool_calls: JSON.stringify([
36+
{ type: 'tool-call', toolCallId: 'c1', toolName: 'action_delete_task', input: { id: 't1' } },
37+
]),
38+
},
39+
{
40+
id: 't1',
41+
role: 'tool',
42+
tool_call_id: 'c1',
43+
content: JSON.stringify([
44+
{
45+
type: 'tool-result',
46+
toolCallId: 'c1',
47+
toolName: 'action_delete_task',
48+
output: {
49+
type: 'text',
50+
value: JSON.stringify({ status: 'pending_approval', pendingActionId: 'pa_1', toolName: 'action_delete_task' }),
51+
},
52+
},
53+
]),
54+
},
55+
]),
56+
),
57+
);
58+
}
59+
60+
describe('a write awaiting approval, as the drawer host reads it (objectstack#37860)', () => {
61+
beforeEach(() => {
62+
vi.stubGlobal('fetch', vi.fn());
63+
});
64+
afterEach(() => {
65+
vi.unstubAllGlobals();
66+
vi.restoreAllMocks();
67+
});
68+
69+
it('a reopened conversation with an undecided pending write counts it', () => {
70+
expect(countWritesAwaitingApproval(hydratePendingWrite(), {})).toBe(1);
71+
});
72+
73+
it('an approval the user made in the chat clears it; a failed one leaves it waiting', async () => {
74+
const messages = hydratePendingWrite();
75+
const fetchMock = globalThis.fetch as ReturnType<typeof vi.fn>;
76+
fetchMock.mockResolvedValueOnce({
77+
ok: true,
78+
text: async () => JSON.stringify({ status: 'executed', result: { deleted: 1 } }),
79+
} as Response);
80+
const approved = renderHook(() => useHitlInChat({ messages, apiBase: '/api/v1/ai' }));
81+
await act(async () => {
82+
await approved.result.current.decide('c1', true);
83+
});
84+
expect(approved.result.current.decisions.c1?.state).toBe('success');
85+
expect(countWritesAwaitingApproval(messages, approved.result.current.decisions)).toBe(0);
86+
87+
fetchMock.mockResolvedValueOnce({ ok: false, status: 500, text: async () => 'boom' } as Response);
88+
const failed = renderHook(() => useHitlInChat({ messages, apiBase: '/api/v1/ai' }));
89+
await act(async () => {
90+
await failed.result.current.decide('c1', true);
91+
});
92+
expect(failed.result.current.decisions.c1?.state).toBe('error');
93+
expect(countWritesAwaitingApproval(messages, failed.result.current.decisions)).toBe(1);
94+
});
95+
96+
it('control: a conversation with no parked write has none', () => {
97+
const messages = hydratedMessagesToChatMessages(
98+
toUIMessages(
99+
aiMessageRowsToServerMessages([
100+
{ id: 'u1', role: 'user', content: 'how many accounts?' },
101+
{ id: 'a1', role: 'assistant', content: 'Twelve.' },
102+
]),
103+
),
104+
);
105+
expect(countWritesAwaitingApproval(messages, {})).toBe(0);
106+
});
107+
});

‎ui/packages/app-shell/src/assistant/assistantBus.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ export function publishPlanApprovalPending(reading: {
249249
for (const l of planApprovalListeners) l();
250250
}
251251

252+
/**
253+
* ui ADR-0057 Amendment A5, row 3 — whether `conversationId` holds a proposal
254+
* awaiting `userId`'s approval, as a mounted chat last read it. Read outside
255+
* render, at the moment the drawer is opened from the entry, so it is a plain
256+
* read, not a hook. A reading taken for another user is no answer.
257+
*/
258+
export function isApprovalPendingIn(conversationId: string | undefined, userId: string | undefined): boolean {
259+
if (!conversationId) return false;
260+
const reading = planApprovalOwners.get(conversationId);
261+
return reading !== undefined && reading.owner === (userId ?? '');
262+
}
263+
252264
/**
253265
* True while any conversation of the signed-in user has a proposed plan
254266
* awaiting approval, as last read by a mounted chat. Read by the launchers.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* ui ADR-0057 Amendment A5, row 3 — whether a conversation holds a write the
6+
* AI proposed that still waits for the user's approval: a tool call the
7+
* framework parked as a pending action (`pendingActionId`, state
8+
* `approval-requested`) that the user has not decided in this chat, or whose
9+
* decision failed and so still waits. The chat host publishes the answer to
10+
* the assistant bus (`publishPlanApprovalPending`), where the drawer's host
11+
* reads it when the drawer is opened from the entry.
12+
*/
13+
14+
interface ToolCallReading {
15+
toolCallId: string;
16+
state?: string;
17+
pendingActionId?: string;
18+
}
19+
20+
interface MessageReading {
21+
toolInvocations?: readonly ToolCallReading[];
22+
}
23+
24+
/** The decision a chat holds for one tool call; only its `state` is read. */
25+
interface DecisionReading {
26+
state: string;
27+
}
28+
29+
/** How many proposed writes in `messages` still await the user's approval. */
30+
export function countWritesAwaitingApproval(
31+
messages: readonly MessageReading[],
32+
decisions: Readonly<Record<string, DecisionReading | undefined>>,
33+
): number {
34+
let count = 0;
35+
for (const message of messages) {
36+
for (const tool of message.toolInvocations ?? []) {
37+
if (tool.state !== 'approval-requested' || !tool.pendingActionId) continue;
38+
const decision = decisions[tool.toolCallId];
39+
if (decision === undefined || decision.state === 'error') count += 1;
40+
}
41+
}
42+
return count;
43+
}

‎ui/packages/app-shell/src/console/ai/ChatPane.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
1212
import { useNavigate } from 'react-router-dom';
1313
import { useObjectTranslation } from '@object-ui/i18n';
14+
import { useAuth } from '@object-ui/auth';
1415
import { translateMetadataType } from '../../views/metadata-admin/i18n.js';
1516
import {
1617
Select,
@@ -47,6 +48,8 @@ import {
4748
} from '@object-ui/plugin-chatbot/core';
4849

4950
import { useOpenAssistant } from '../../layout/chatDockControl.js';
51+
import { publishPlanApprovalPending } from '../../assistant/assistantBus.js';
52+
import { countWritesAwaitingApproval } from '../../assistant/writeApprovalPending.js';
5053
import type { ChatSurfaceContext } from '../../layout/chatSurfaceContext.js';
5154
import { buildFocusContext, type ConversationFocus } from '../../layout/chatFocus.js';
5255
import { ChatFocusRow } from './ChatFocusRow.js';
@@ -422,6 +425,23 @@ export function ChatPane({
422425
},
423426
});
424427

428+
// ui ADR-0057 Amendment A5, row 3 — a write the AI proposed that still waits
429+
// for this user's approval is published per conversation to the assistant
430+
// bus, where it outlives this pane: the drawer's host reads it when the
431+
// drawer is next opened from the entry, and reopens this conversation.
432+
const { user } = useAuth();
433+
const approvalOwner = user?.id;
434+
const writesAwaiting = countWritesAwaitingApproval(runtimeMessages, hitl.decisions);
435+
useEffect(() => {
436+
if (!conversationId) return;
437+
publishPlanApprovalPending({
438+
userId: approvalOwner,
439+
conversationId,
440+
pending: writesAwaiting > 0,
441+
count: writesAwaiting,
442+
});
443+
}, [approvalOwner, conversationId, writesAwaiting]);
444+
425445
// The real send, shared by a normal submit and by the deferred-first-message
426446
// replay below (resetSuppression → send → onSent, in that order).
427447
//

‎ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.toolLabelsLocale-11667.test.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ vi.mock('../../../providers/AdapterProvider', async (importOriginal) => {
8282
import { I18nProvider } from '@object-ui/i18n';
8383
import type { AgentDescriptor } from '@object-ui/plugin-chatbot';
8484
import { ChatPane } from '../AiChatPage';
85+
import { isApprovalPendingIn, publishPlanApprovalPending } from '../../../assistant/assistantBus';
8586

8687
window.matchMedia = ((query: string) => ({
8788
matches: false,
@@ -207,3 +208,22 @@ describe('AI chat tool-approval labels follow the UI locale (objectui#11667)', (
207208
expect(JSON.parse(String((init as RequestInit).body))).toEqual({ reason: 'Operator rejected from chat' });
208209
});
209210
});
211+
212+
// ui ADR-0057 Amendment A5, row 3 (objectstack#37860) — the pane publishes a
213+
// write awaiting approval to the assistant bus, per conversation, where the
214+
// drawer's host reads it when the drawer is next opened from the entry; the
215+
// user's decision in the chat clears it. Same fixture, same real pane.
216+
describe('the pane tells the assistant bus a write awaits approval (objectstack#37860)', () => {
217+
afterEach(() => publishPlanApprovalPending({ userId: undefined, conversationId: 'conv-1', pending: false }));
218+
219+
it('pending while the card waits; cleared once the user decides', async () => {
220+
renderPane('en');
221+
expect(await screen.findByRole('button', { name: 'Reject' })).toBeInTheDocument();
222+
expect(isApprovalPendingIn('conv-1', undefined)).toBe(true);
223+
// Control: the reading is the conversation's, not every conversation's.
224+
expect(isApprovalPendingIn('conv-2', undefined)).toBe(false);
225+
226+
fireEvent.click(screen.getByRole('button', { name: 'Reject' }));
227+
await waitFor(() => expect(isApprovalPendingIn('conv-1', undefined)).toBe(false));
228+
});
229+
});

‎ui/packages/app-shell/src/hooks/useConversationList.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,49 @@ export function useConversationList(
291291

292292
return { conversations, isLoading, error, refetch, remove, rename };
293293
}
294+
295+
export interface UseConversationLabelOptions {
296+
apiBase: string;
297+
/** The conversation the drawer shows; absent before the first send creates it. */
298+
conversationId: string | undefined;
299+
/** Bump to read the label again (a sent turn, the server titling the thread). */
300+
refreshKey?: number | string;
301+
}
302+
303+
export interface ConversationLabelReading {
304+
/** The label the history list gives this conversation's row; absent when it has none yet. */
305+
label: string | undefined;
306+
/** False while the label of the conversation now shown has not been read yet. */
307+
settled: boolean;
308+
}
309+
310+
/**
311+
* ui ADR-0057 Amendment A5 — the drawer's header names the conversation it
312+
* shows by the label its history row carries: the title the server gave it,
313+
* else the latest message the user wrote in it (`normalize`, the list's own
314+
* reading of one row). A read that fails settles with no label.
315+
*/
316+
export function useConversationLabel({
317+
apiBase,
318+
conversationId,
319+
refreshKey,
320+
}: UseConversationLabelOptions): ConversationLabelReading {
321+
const [reading, setReading] = useState<{ id: string; label: string | undefined } | undefined>(undefined);
322+
useEffect(() => {
323+
if (!conversationId) return;
324+
let cancelled = false;
325+
fetchConversationDetail(apiBase, conversationId).then(
326+
(row) => {
327+
if (!cancelled) setReading({ id: conversationId, label: row?.title || row?.preview || undefined });
328+
},
329+
() => {
330+
if (!cancelled) setReading({ id: conversationId, label: undefined });
331+
},
332+
);
333+
return () => {
334+
cancelled = true;
335+
};
336+
}, [apiBase, conversationId, refreshKey]);
337+
if (!conversationId) return { label: undefined, settled: true };
338+
return reading?.id === conversationId ? { label: reading.label, settled: true } : { label: undefined, settled: false };
339+
}

‎ui/packages/app-shell/src/layout/AssistantTopBarButton.tsx‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
* entry: it opens and closes the right-side drawer without leaving the page.
77
* The floating bottom-right button it replaces is gone; what that button
88
* carried moved here:
9-
* - objectui#11666 — while a proposed plan awaits the user's approval the
9+
* - objectui#11666 — while something the AI proposed awaits the user's
10+
* approval (since ui ADR-0057 A5, a write parked as a pending action) the
1011
* entry carries a marker, so a user who closed the chat still sees the
1112
* assistant is waiting on them. Read off the assistant bus; only a change
12-
* of the plan's state clears it, never opening the chat.
13+
* of that approval's state clears it, never opening the chat.
1314
*
1415
* objectstack#37858 — the entry is an outlined button that says what it does,
1516
* 「Ask AI」, beside a chat-bubble icon, on every page: the
@@ -56,22 +57,26 @@ function isMacPlatform(): boolean {
5657

5758
/**
5859
* The Ask AI entry's opening, for a button elsewhere on a page that asks the
59-
* assistant the way the standing entry does — Home's 「Ask AI」. Absent a
60-
* target it opens the drawer on whatever it shows now: the drawer's own
61-
* toggle, which is what the standing button runs (a handoff the drawer still
62-
* holds is kept); with one, on that target. Under no drawer host it goes to
63-
* the pre-drawer address. What opening means changes here and in the
64-
* button's toggle together.
60+
* assistant the way the standing entry does — Home's 「Ask AI」, the record
61+
* pane's. With the drawer closed it is an opening from the entry (ui ADR-0057
62+
* Amendment A5, the host's `openEntry`): a new conversation after the user's
63+
* own close, else as A5's table says; a target's `agent` is the agent the
64+
* entry asks. With the drawer open, a target opens on it as before and no
65+
* target leaves the drawer as it is. Under no drawer host it goes to the
66+
* pre-drawer address.
6567
*/
6668
export function useAskAiEntry(): (target?: ChatDockTarget) => void {
6769
const control = useChatDockControl();
6870
const openAssistant = useOpenAssistant();
6971
return React.useCallback(
7072
(target?: ChatDockTarget) => {
71-
if (control && target === undefined) {
72-
if (!control.expanded) control.toggle();
73+
if (control && !control.expanded) {
74+
if (control.openEntry) control.openEntry(target?.agent);
75+
else if (target === undefined) control.toggle();
76+
else control.open(target);
7377
return;
7478
}
79+
if (control && target === undefined) return;
7580
openAssistant(target);
7681
},
7782
[control, openAssistant],

0 commit comments

Comments
 (0)