diff --git a/.changeset/37863-favourite-conversations.md b/.changeset/37863-favourite-conversations.md new file mode 100644 index 00000000000..05b5de5fd81 --- /dev/null +++ b/.changeset/37863-favourite-conversations.md @@ -0,0 +1,15 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +--- + +feat(app-shell): the assistant drawer's ☆ favourites a conversation, and the sidebar's Favorites open it in the drawer in place + +Clause-②: no +Metadata-protocol: none + +- **The drawer header's ☆.** Once the first message has created the conversation, the header's ☆ (before +) adds it to the user's favourites, and is pressed while it is one; pressed again, it removes it. It is drawn in the side panel, the full window and the phone sheet. While the conversation is a favourite, its stored label follows the header's title. +- **A conversation can be a favourite.** `FavoriteItem` gains the `conversation` type, id `conversation:ID`, with the conversation's id and agent (`conversationId`, `agent`); its `href` is the conversation's `/ai…` address. Conversation favourites count against the same cap of 20 as the other content favourites. +- **The sidebar row opens the drawer in place.** A favourite conversation is a row of the sidebar's Favorites section, with the chat-bubble icon. Clicking it opens the assistant drawer on that conversation, the way its history row does, and the page stays where it is. The address is followed only where no drawer can take it: a page without the drawer, the app's AI inquiry page, or a click that opens a new tab. +- **The label follows the conversation.** The sidebar reads each favourite conversation once and keeps the label its history row shows (the server's title, else the latest message the user wrote). +- **A deleted conversation is marked.** A conversation the server answers is gone, or is not this user's, is drawn struck through as unavailable (`sidebar.conversationUnavailable`, new in every pack), opens nothing, and is still removed from its ⋯ menu. A failed read of any other kind marks nothing. diff --git a/ui/packages/app-shell/README.md b/ui/packages/app-shell/README.md index 653ae39c155..471946c963f 100644 --- a/ui/packages/app-shell/README.md +++ b/ui/packages/app-shell/README.md @@ -1412,6 +1412,15 @@ adapter syncs both flows. The legacy `objectui-nav-pins` localStorage key is migrated on first mount and then removed. Content favorites (20) and nav pins (20) each have an independent cap. See the guide below for details. +An AI conversation can be a content favorite too (`type: 'conversation'`, id +`conversation:ID`, with `conversationId` and `agent`), starred from the +assistant drawer. Its sidebar row opens the drawer in place +on that conversation, and follows its `href` (the conversation's `/ai…` +address) only where no drawer can take it. The sidebar reads each favorite +conversation once: the label follows the conversation's title, and a +conversation the server answers is gone or not this user's is drawn +unavailable, stays removable, and opens nothing. + The sidebar's Pinned section keeps the user's order, stored with the pins: `pinnedIds` lists them in it, a new pin joins the end, and `reorderPins(orderedIds)` saves a new order. The sidebar passes both to diff --git a/ui/packages/app-shell/src/context/FavoritesProvider.tsx b/ui/packages/app-shell/src/context/FavoritesProvider.tsx index fac49ba94fe..a6f241c0c75 100644 --- a/ui/packages/app-shell/src/context/FavoritesProvider.tsx +++ b/ui/packages/app-shell/src/context/FavoritesProvider.tsx @@ -55,11 +55,15 @@ export interface FavoriteItem { * favorites surfaced on Home (Starred Apps) and the sidebar Favorites * section. A `view` is one list view of an object (objectstack#27594), id * `view:OBJECT:VIEW`; the sidebar draws it only in the app its `href` names. + * - `conversation` — an AI conversation the user starred in the assistant + * drawer's header (objectstack#37863), id `conversation:ID`. The sidebar + * row opens it in the drawer in place; `href` is its `/ai…` address, the + * fallback where no drawer can take it. It counts against the content cap. * - `nav` — a sidebar navigation entry promoted to the "Pinned" position via * the in-tree pin toggle (see `useNavPins`). Excluded from Home/Starred and * from the generic sidebar Favorites list so it doesn't render twice. */ - type: 'object' | 'dashboard' | 'page' | 'report' | 'record' | 'view' | 'nav'; + type: 'object' | 'dashboard' | 'page' | 'report' | 'record' | 'view' | 'conversation' | 'nav'; /** ISO timestamp of when the item was favorited */ favoritedAt: string; /** @@ -80,6 +84,10 @@ export interface FavoriteItem { * tree node without leaking the synthesized favorite into other UIs. */ navId?: string; + /** For `type === 'conversation'` items: the conversation the drawer opens. */ + conversationId?: string; + /** For `type === 'conversation'` items: the agent the conversation is with, by route name. */ + agent?: string; } interface FavoritesContextValue { @@ -140,7 +148,7 @@ const STORAGE_BASE_KEY = 'objectui-favorites'; /** Legacy key used by the standalone `useNavPins` hook before it was merged * into Favorites. Migrated once at provider mount, then deleted. */ const LEGACY_NAV_PINS_KEY = 'objectui-nav-pins'; -/** Cap for user-visible content favorites (object/dashboard/page/report/record). */ +/** Cap for user-visible content favorites (every type but `nav`). */ const MAX_FAVORITES = 20; /** Independent cap for nav-pin favorites — they live in a separate bucket. */ const MAX_NAV_PINS = 20; diff --git a/ui/packages/app-shell/src/hooks/useConversationList.ts b/ui/packages/app-shell/src/hooks/useConversationList.ts index b69abe58f92..294b502e461 100644 --- a/ui/packages/app-shell/src/hooks/useConversationList.ts +++ b/ui/packages/app-shell/src/hooks/useConversationList.ts @@ -169,6 +169,22 @@ async function fetchConversationDetail( return normalize(row as ServerConversation); } +/** + * One conversation's history row, read by id; `null` when the server answers + * that it is gone or not this user's (404, 403). Any other failure throws, so + * a network blip never reads as a deleted conversation. + */ +export async function readConversationRow(apiBase: string, id: string): Promise { + const res = await authFetch(`${apiBase}/conversations/${encodeURIComponent(id)}`, { + credentials: 'include', + }); + if (res.status === 404 || res.status === 403) return null; + if (!res.ok) throw Object.assign(new Error(`GET conversation failed: ${res.status}`), { status: res.status }); + const body = (await res.json()) as ServerConversation | { conversation?: ServerConversation }; + const row = 'conversation' in body && body.conversation ? body.conversation : body; + return normalize(row as ServerConversation); +} + export function useConversationList( options: UseConversationListOptions, ): UseConversationListReturn { diff --git a/ui/packages/app-shell/src/layout/ChatDock.tsx b/ui/packages/app-shell/src/layout/ChatDock.tsx index b7493ad291e..3880893d9ce 100644 --- a/ui/packages/app-shell/src/layout/ChatDock.tsx +++ b/ui/packages/app-shell/src/layout/ChatDock.tsx @@ -39,7 +39,7 @@ import { SheetHeader, SheetTitle, } from '@object-ui/components'; -import { History, Maximize2, MessagesSquare, Minimize2, MoreHorizontal, Plus, Share2, X } from 'lucide-react'; +import { History, Maximize2, MessagesSquare, Minimize2, MoreHorizontal, Plus, Share2, Star, X } from 'lucide-react'; import { formatNumber, useObjectTranslation } from '@object-ui/i18n'; import { useAgents } from '@object-ui/plugin-chatbot/core'; import { resolveApiBase } from '../console/ai/resolveApiBase.js'; @@ -48,6 +48,8 @@ import { useAiUsage } from '../hooks/useAiUsage.js'; import { cloudConsoleUrl } from '../console/marketplace/marketplaceApi.js'; import { getUpgradeUrl } from '../runtime-config.js'; import { usePlanApprovalPending } from '../assistant/assistantBus.js'; +import { useFavorites } from '../context/FavoritesProvider.js'; +import { conversationFavoriteId, conversationFavoriteItem } from './conversationFavorites.js'; import type { ChatSurfaceContext } from './chatSurfaceContext.js'; import { readStoredDockFullWindow, @@ -394,7 +396,64 @@ interface DockHeaderButtonsProps { } /** - * ui ADR-0057 Amendment A5 — the header's + and history buttons, as icons: + * objectstack#37863 — the header's ☆: adds the thread in view to the user's + * favourites, or removes it (pressed while it is one). Drawn once the first + * send has created the thread. While it is a favourite, the stored label + * follows the label the header reads. + */ +function DockFavoriteButton({ + actions, + box, + icon, + testId, +}: { + actions: ChatDockConversationActions; + box: string; + icon: string; + testId: string; +}) { + const { t } = useObjectTranslation(); + const { isFavorite, toggleFavorite, refreshLabel } = useFavorites(); + const conversationId = actions.conversationId as string; + const id = conversationFavoriteId(conversationId); + const starred = isFavorite(id); + const label = actions.labelPending ? undefined : actions.label; + const refreshLabelRef = React.useRef(refreshLabel); + React.useLayoutEffect(() => { + refreshLabelRef.current = refreshLabel; + }); + React.useEffect(() => { + if (starred && label) refreshLabelRef.current(id, label); + }, [starred, id, label]); + const name = starred + ? t('common.removeFromFavorites', { defaultValue: 'Remove from favorites' }) + : t('common.addToFavorites', { defaultValue: 'Add to favorites' }); + return ( + + ); +} + +/** + * ui ADR-0057 Amendment A5 — the header's ☆ (objectstack#37863), + and history buttons, as icons: * + starts a new conversation on the agent in use, the clock shows the * history over the chat (pressed while it does) and goes back to the chat. */ @@ -409,6 +468,14 @@ function DockHeaderButtons({ actions, history, size, onStartNew }: DockHeaderBut : t('console.ai.dock.history', { defaultValue: 'History' }); return ( <> + {actions?.conversationId && actions.agent ? ( + + ) : null} {startNew ? (