fd7387928c
## Summary - **Queue messages while streaming**: Messages sent during active AI streaming are queued server-side and auto-flushed when the current stream completes. Frontend renders queued messages optimistically in a dedicated queue UI. - **Drop `@ai-sdk/react` + `resumable-stream`**: Replace the dual HTTP SSE + AI SDK client architecture with a single GraphQL SSE subscription per thread. All events (token chunks, message persistence, queue updates, errors) flow through Redis PubSub → GraphQL subscription. - **Server-driven architecture**: The server decides whether to queue or stream (via `POST /:threadId/message`). The frontend mirrors this decision for optimistic rendering but defers to the server response. - **Reuse AI SDK accumulation logic**: `readUIMessageStream` from the `ai` package handles chunk-to-message accumulation on the frontend, avoiding a custom 780-line accumulator. ## Key files **Backend:** - `agent-chat-event-publisher.service.ts` — publishes events to Redis PubSub - `agent-chat-subscription.resolver.ts` — GraphQL subscription resolver - `stream-agent-chat.job.ts` — publishes chunks via PubSub instead of resumable-stream - `agent-chat.controller.ts` — unified `POST /:threadId/message` endpoint **Frontend:** - `useAgentChatSubscription.ts` — subscribes to `onAgentChatEvent`, bridges to `readUIMessageStream` - `useAgentChat.ts` — send/stop/optimistic rendering (no more AI SDK) - `AgentChatStreamSubscriptionEffect.tsx` — replaces `AgentChatAiSdkStreamEffect.tsx` ## Test plan - [ ] Send message on new thread → optimistic render, streaming response appears - [ ] Send message while streaming → queued instantly (no flash in main thread) - [ ] Queued message auto-flushes after current stream completes - [ ] Remove queued message via queue UI - [ ] Stop streaming mid-response - [ ] Leave chat idle for several minutes → streaming still works after (SSE client recycling) - [ ] Token refresh during session → requests succeed (authenticated fetch) - [ ] Switch threads while streaming → clean subscription handoff Made with [Cursor](https://cursor.com) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { type MetadataEntityKey } from '@/metadata-store/states/metadataStoreState';
|
|
|
|
const METADATA_NAME_TO_ENTITY_KEY: Record<string, MetadataEntityKey> = {
|
|
objectMetadata: 'objectMetadataItems',
|
|
fieldMetadata: 'fieldMetadataItems',
|
|
index: 'indexMetadataItems',
|
|
view: 'views',
|
|
viewField: 'viewFields',
|
|
viewFieldGroup: 'viewFieldGroups',
|
|
viewGroup: 'viewGroups',
|
|
viewSort: 'viewSorts',
|
|
viewFilter: 'viewFilters',
|
|
viewFilterGroup: 'viewFilterGroups',
|
|
rowLevelPermissionPredicate: 'rowLevelPermissionPredicates',
|
|
rowLevelPermissionPredicateGroup: 'rowLevelPermissionPredicateGroups',
|
|
logicFunction: 'logicFunctions',
|
|
role: 'roles',
|
|
roleTarget: 'roleTargets',
|
|
agent: 'agents',
|
|
skill: 'skills',
|
|
pageLayout: 'pageLayouts',
|
|
pageLayoutWidget: 'pageLayoutWidgets',
|
|
pageLayoutTab: 'pageLayoutTabs',
|
|
commandMenuItem: 'commandMenuItems',
|
|
navigationMenuItem: 'navigationMenuItems',
|
|
frontComponent: 'frontComponents',
|
|
webhook: 'webhooks',
|
|
agentChatThread: 'agentChatThreads',
|
|
};
|
|
|
|
export const mapAllMetadataNameToEntityKey = (
|
|
metadataName: string,
|
|
): MetadataEntityKey | undefined => METADATA_NAME_TO_ENTITY_KEY[metadataName];
|