Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/37863-favourite-conversations.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions ui/packages/app-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions ui/packages/app-shell/src/context/FavoritesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions ui/packages/app-shell/src/hooks/useConversationList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConversationListItem | null> {
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 {
Expand Down
71 changes: 69 additions & 2 deletions ui/packages/app-shell/src/layout/ChatDock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
<Button
variant="ghost"
size="icon"
className={cn(box, 'text-muted-foreground hover:text-foreground', starred && 'text-amber-500 hover:text-amber-600')}
onClick={() =>
toggleFavorite(
conversationFavoriteItem({
conversationId,
agent: actions.agent as string,
label: label ?? t('console.ai.newConversation', { defaultValue: 'New conversation' }),
}),
)
}
aria-pressed={starred}
aria-label={name}
title={name}
data-testid={testId}
>
<Star className={cn(icon, starred && 'fill-current')} />
</Button>
);
}

/**
* 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.
*/
Expand All @@ -409,6 +468,14 @@ function DockHeaderButtons({ actions, history, size, onStartNew }: DockHeaderBut
: t('console.ai.dock.history', { defaultValue: 'History' });
return (
<>
{actions?.conversationId && actions.agent ? (
<DockFavoriteButton
actions={actions}
box={box}
icon={icon}
testId={size === 'sheet' ? 'chat-dock-mobile-favorite' : 'chat-dock-favorite'}
/>
) : null}
{startNew ? (
<Button
variant="ghost"
Expand Down
3 changes: 2 additions & 1 deletion ui/packages/app-shell/src/layout/ChatDockConversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,10 @@ export function ChatDockConversation({
label: paneConversationId ? headerLabel : undefined,
labelPending,
startNew,
agent: activeAgentRoute,
},
);
}, [onActionsChange, inert, conversationId, paneConversationId, headerLabel, labelPending, startNew]);
}, [onActionsChange, inert, conversationId, paneConversationId, headerLabel, labelPending, startNew, activeAgentRoute]);

// OSS / no AI seat → the whole dock body is inert (the robot is gated too).
if (inert) return null;
Expand Down
43 changes: 40 additions & 3 deletions ui/packages/app-shell/src/layout/UnifiedSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ import { useWorkspacePreference } from '../utils/workspacePreference.js';
import { SidebarItemMenu, sidebarItemDesignPath, favoriteDesignPath } from './SidebarItemMenu.js';
import { SortableFavoriteRows, type FavoriteRowDragProps } from './SortableFavoriteRows.js';
import { favoriteAppSegment } from './listViewFavorites.js';
import { useChatDockControl } from './chatDockControl.js';
import { conversationFavoriteTarget, useUnavailableConversationFavorites } from './conversationFavorites.js';
import { resolveAiApiBase } from '../hooks/aiApiBase.js';
import { useDesignModeActive } from './designMode.js';
import { electSidebarArea, type SidebarAreaRoute } from './sidebarAreaElection.js';
import type { FavoriteItem } from '../hooks/useFavorites.js';
Expand Down Expand Up @@ -336,7 +339,8 @@ export function UnifiedSidebar({
// A recent entry's text is the item's own, resolved on this render
// (objectui#11678); the entry stores identity only.
const recentLabel = useRecentItemLabel();
const { favorites, removeFavorite, reorderFavorites } = useFavorites();
const { favorites, removeFavorite, reorderFavorites, refreshLabel: refreshFavoriteLabel } = useFavorites();
const chatDock = useChatDockControl();

const metadata = useMetadata();
const { apps: metadataApps } = metadata;
Expand Down Expand Up @@ -690,15 +694,48 @@ export function UnifiedSidebar({
.filter(f => f.type !== 'nav')
.filter(f => f.type !== 'view' || matchAppBySegment(apps.filter((a: any) => a.active !== false), favoriteAppSegment(f.href)) === activeApp)
.slice(0, 8);
// objectstack#37863 — a favourite conversation's row opens the drawer in
// place on it (the target its history row opens), and its address only where
// no drawer takes it: no host, the app's AI inquiry page (A4), or a click
// that asks for a new tab. A conversation the server answers is gone or not
// this user's is drawn unavailable and opens nothing; its ⋯ still removes it.
const unavailableConversations = useUnavailableConversationFavorites(
contentFavorites,
resolveAiApiBase(),
refreshFavoriteLabel,
);
const openConversationFavorite = (item: FavoriteItem, event: React.MouseEvent) => {
const target = conversationFavoriteTarget(item);
if (!target) return;
if (unavailableConversations.has(item.id)) {
event.preventDefault();
return;
}
if (!chatDock || chatDock.askPageActive) return;
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
event.preventDefault();
chatDock.open(target);
if (isMobile) setOpenMobile(false);
};
const contentFavoriteRow = (item: FavoriteItem, drag?: FavoriteRowDragProps) => {
const unavailable = unavailableConversations.has(item.id);
const unavailableText = t('sidebar.conversationUnavailable', { defaultValue: 'This conversation is no longer available' });
return (
<>
<SidebarMenuButton asChild tooltip={item.label}>
<Link to={item.href} {...(drag ?? {})}>
<SidebarMenuButton asChild tooltip={unavailable ? `${item.label} · ${unavailableText}` : item.label}>
<Link
to={item.href}
{...(drag ?? {})}
onClick={item.type === 'conversation' ? (event) => openConversationFavorite(item, event) : undefined}
aria-disabled={unavailable || undefined}
data-unavailable={unavailable || undefined}
className={unavailable ? 'text-muted-foreground line-through decoration-muted-foreground/60' : undefined}
>
{/* objectstack#36141 — the menu's tiles: an object, one of its
views or records is that object's tile, the rest neutral. */}
{contentTile(item.type, favoriteItemObject(item), item.type === 'view' ? item.icon : undefined)}
<span className="truncate">{item.label}</span>
{unavailable ? <span className="sr-only">{`(${unavailableText})`}</span> : null}
</Link>
</SidebarMenuButton>
<SidebarItemMenu
Expand Down
Loading
Loading