@ai4b-team/fsaos-gateway-sdk 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -664,6 +664,33 @@ interface ChannelMessage {
664
664
  intent_card?: Record<string, unknown>;
665
665
  thread_summary?: Array<Record<string, unknown>>;
666
666
  }
667
+ /** A parsed card item bundled with channel messages from the kernel v2 response. */
668
+ interface ChannelCard {
669
+ id: string;
670
+ path: string;
671
+ name: string;
672
+ createdAt: string;
673
+ action: string;
674
+ targetId?: string;
675
+ targetPath: string;
676
+ targetDisplayName: string;
677
+ targetDescription: string;
678
+ targetItemType: string;
679
+ /** Derived tool use ID (name without 'card-' prefix). */
680
+ toolId?: string;
681
+ /** Path of the parent message (for child cards). Undefined for sibling cards. */
682
+ parentMessagePath?: string;
683
+ visibility: string;
684
+ }
685
+ /** Full response from fetchChannelMessagesWithCards — includes bundled cards. */
686
+ interface ChannelMessagesResponse {
687
+ messages: ChannelMessage[];
688
+ /** Cards that are direct children of messages in this page. Keyed by message path. */
689
+ messageCards: Map<string, ChannelCard[]>;
690
+ /** Cards that are direct siblings (children of the channel itself). */
691
+ siblingCards: ChannelCard[];
692
+ mode: 'top_level' | 'thread';
693
+ }
667
694
  /**
668
695
  * Fetch channel messages via the kernel's `get-channel-messages` method.
669
696
  *
@@ -676,9 +703,24 @@ interface ChannelMessage {
676
703
  * If omitted, returns top-level messages.
677
704
  */
678
705
  declare function fetchChannelMessages(channelPath: string, parentMessageId?: string): Promise<ChannelMessage[]>;
706
+ /**
707
+ * Fetch channel messages WITH bundled cards from the kernel v2 response.
708
+ *
709
+ * The kernel's get-channel-messages (v2) returns messages interleaved with
710
+ * their associated cards (both sibling cards and child cards). This function
711
+ * parses both and groups child cards by their parent message path.
712
+ *
713
+ * This eliminates the N+1 query problem where the frontend previously made
714
+ * separate `list` calls for each message to fetch its cards.
715
+ */
716
+ declare function fetchChannelMessagesWithCards(channelPath: string, parentMessageId?: string): Promise<ChannelMessagesResponse>;
679
717
  /** Response shape from fetchChannelMessagesPage. */
680
718
  interface ChannelMessagesPage {
681
719
  messages: ChannelMessage[];
720
+ /** Cards grouped by parent message path (child cards of messages in this page). */
721
+ messageCards: Map<string, ChannelCard[]>;
722
+ /** Cards that are direct siblings of the channel (not nested under a message). */
723
+ siblingCards: ChannelCard[];
682
724
  /** Mode returned by kernel: 'top_level' or 'thread'. */
683
725
  mode: 'top_level' | 'thread';
684
726
  }
@@ -1482,14 +1524,24 @@ interface ChannelMessagesOptions {
1482
1524
  realtime?: boolean;
1483
1525
  enabled?: boolean;
1484
1526
  }
1485
- /** Fetch channel messages via the kernel's `get-channel-messages` method. */
1527
+ /**
1528
+ * Fetch channel messages via the kernel's `get-channel-messages` method.
1529
+ *
1530
+ * Now uses `fetchChannelMessagesWithCards` to get bundled cards in a single
1531
+ * request, eliminating the N+1 query problem. Cards are returned alongside
1532
+ * messages, grouped by parent message path.
1533
+ */
1486
1534
  declare function useChannelMessages(options: ChannelMessagesOptions): {
1487
1535
  messages: ChannelMessage[];
1536
+ /** Cards grouped by parent message path (child cards of messages). */
1537
+ messageCards: Map<string, ChannelCard[]>;
1538
+ /** Cards that are direct siblings of the channel (not nested under a message). */
1539
+ siblingCards: ChannelCard[];
1488
1540
  threads: ChannelMessage[];
1489
1541
  isLoading: boolean;
1490
1542
  isFetching: boolean;
1491
1543
  error: Error | null;
1492
- refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<ChannelMessage[], Error>>;
1544
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<ChannelMessagesResponse, Error>>;
1493
1545
  };
1494
1546
  /** Options for useInfiniteChannelMessages. */
1495
1547
  interface InfiniteChannelMessagesOptions {
@@ -1523,6 +1575,10 @@ interface InfiniteChannelMessagesOptions {
1523
1575
  */
1524
1576
  declare function useInfiniteChannelMessages(options: InfiniteChannelMessagesOptions): {
1525
1577
  messages: ChannelMessage[];
1578
+ /** Cards grouped by parent message path (child cards of messages). */
1579
+ messageCards: Map<string, ChannelCard[]>;
1580
+ /** Cards that are direct siblings of the channel (not nested under a message). */
1581
+ siblingCards: ChannelCard[];
1526
1582
  threads: ChannelMessage[];
1527
1583
  isLoading: boolean;
1528
1584
  isFetching: boolean;
@@ -1875,4 +1931,4 @@ declare function uploadFile(file: File | Blob, options: UploadOptions, onProgres
1875
1931
  */
1876
1932
  declare function useFileUpload(): UseFileUploadReturn;
1877
1933
 
1878
- export { type AccountInfo, type Channel, type ChannelMessage, type ChannelMessagesOptions, type ChannelMessagesPage, type ChannelsOptions, type ComponentOpener, ComponentRenderer, type CreateParams, type DeleteParams, EnforcementDeniedError, type EnforcementPayload, type FieldDescriptor, type FileRef, type GatewayParams, type GatewayResponse, type InfiniteChannelMessagesOptions, type ItemVersionsOptions, type ItemVersionsResult, type ItemsFilter, KernelProvider, type LinkParams, type MoveParams, type Notification, type NotificationsOptions, type OpenEnvelope, type OpenOptions, type PrincipalData, type ResolveParams, type ResolveResponse, type ResolveResultItem, type SessionEntry, type TypeDefinition, type TypeHelpers, type TypeSchema, type UnreadCountsOptions, type UpdateParams, type UploadItem, type UploadOptions, type UploadResult, type UseFileUploadReturn, type VFSEdge, type VFSItem, auth, awaitScopeReady, callTool, clearCachedToken, clearSession, createItem, disconnectSSE, disposeVfsRealtimeWs, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAssetUrl, getDefaultSort, getRequiredFormFields, getScope, getScopeVersion, getSessionEntry, initSession, initVfsRealtimeWs, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, isScopeReady, listChildren, mount, mountRealtimeScope, normalizeItem, ping, pushChanges, queryClient, readItem, registerCleanup, resetAllSdkState, resolvePrincipalId, setCachedToken, setScope, setupRequireShim, signal, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, unmountRealtimeScope, updateItem, uploadFile, useAccounts, useAllChannels, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useScope, useScopeReady, useSearch, useTheme, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, vfsKeys };
1934
+ export { type AccountInfo, type Channel, type ChannelCard, type ChannelMessage, type ChannelMessagesOptions, type ChannelMessagesPage, type ChannelMessagesResponse, type ChannelsOptions, type ComponentOpener, ComponentRenderer, type CreateParams, type DeleteParams, EnforcementDeniedError, type EnforcementPayload, type FieldDescriptor, type FileRef, type GatewayParams, type GatewayResponse, type InfiniteChannelMessagesOptions, type ItemVersionsOptions, type ItemVersionsResult, type ItemsFilter, KernelProvider, type LinkParams, type MoveParams, type Notification, type NotificationsOptions, type OpenEnvelope, type OpenOptions, type PrincipalData, type ResolveParams, type ResolveResponse, type ResolveResultItem, type SessionEntry, type TypeDefinition, type TypeHelpers, type TypeSchema, type UnreadCountsOptions, type UpdateParams, type UploadItem, type UploadOptions, type UploadResult, type UseFileUploadReturn, type VFSEdge, type VFSItem, auth, awaitScopeReady, callTool, clearCachedToken, clearSession, createItem, disconnectSSE, disposeVfsRealtimeWs, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAssetUrl, getDefaultSort, getRequiredFormFields, getScope, getScopeVersion, getSessionEntry, initSession, initVfsRealtimeWs, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, isScopeReady, listChildren, mount, mountRealtimeScope, normalizeItem, ping, pushChanges, queryClient, readItem, registerCleanup, resetAllSdkState, resolvePrincipalId, setCachedToken, setScope, setupRequireShim, signal, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, unmountRealtimeScope, updateItem, uploadFile, useAccounts, useAllChannels, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useScope, useScopeReady, useSearch, useTheme, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, vfsKeys };
package/dist/index.d.ts CHANGED
@@ -664,6 +664,33 @@ interface ChannelMessage {
664
664
  intent_card?: Record<string, unknown>;
665
665
  thread_summary?: Array<Record<string, unknown>>;
666
666
  }
667
+ /** A parsed card item bundled with channel messages from the kernel v2 response. */
668
+ interface ChannelCard {
669
+ id: string;
670
+ path: string;
671
+ name: string;
672
+ createdAt: string;
673
+ action: string;
674
+ targetId?: string;
675
+ targetPath: string;
676
+ targetDisplayName: string;
677
+ targetDescription: string;
678
+ targetItemType: string;
679
+ /** Derived tool use ID (name without 'card-' prefix). */
680
+ toolId?: string;
681
+ /** Path of the parent message (for child cards). Undefined for sibling cards. */
682
+ parentMessagePath?: string;
683
+ visibility: string;
684
+ }
685
+ /** Full response from fetchChannelMessagesWithCards — includes bundled cards. */
686
+ interface ChannelMessagesResponse {
687
+ messages: ChannelMessage[];
688
+ /** Cards that are direct children of messages in this page. Keyed by message path. */
689
+ messageCards: Map<string, ChannelCard[]>;
690
+ /** Cards that are direct siblings (children of the channel itself). */
691
+ siblingCards: ChannelCard[];
692
+ mode: 'top_level' | 'thread';
693
+ }
667
694
  /**
668
695
  * Fetch channel messages via the kernel's `get-channel-messages` method.
669
696
  *
@@ -676,9 +703,24 @@ interface ChannelMessage {
676
703
  * If omitted, returns top-level messages.
677
704
  */
678
705
  declare function fetchChannelMessages(channelPath: string, parentMessageId?: string): Promise<ChannelMessage[]>;
706
+ /**
707
+ * Fetch channel messages WITH bundled cards from the kernel v2 response.
708
+ *
709
+ * The kernel's get-channel-messages (v2) returns messages interleaved with
710
+ * their associated cards (both sibling cards and child cards). This function
711
+ * parses both and groups child cards by their parent message path.
712
+ *
713
+ * This eliminates the N+1 query problem where the frontend previously made
714
+ * separate `list` calls for each message to fetch its cards.
715
+ */
716
+ declare function fetchChannelMessagesWithCards(channelPath: string, parentMessageId?: string): Promise<ChannelMessagesResponse>;
679
717
  /** Response shape from fetchChannelMessagesPage. */
680
718
  interface ChannelMessagesPage {
681
719
  messages: ChannelMessage[];
720
+ /** Cards grouped by parent message path (child cards of messages in this page). */
721
+ messageCards: Map<string, ChannelCard[]>;
722
+ /** Cards that are direct siblings of the channel (not nested under a message). */
723
+ siblingCards: ChannelCard[];
682
724
  /** Mode returned by kernel: 'top_level' or 'thread'. */
683
725
  mode: 'top_level' | 'thread';
684
726
  }
@@ -1482,14 +1524,24 @@ interface ChannelMessagesOptions {
1482
1524
  realtime?: boolean;
1483
1525
  enabled?: boolean;
1484
1526
  }
1485
- /** Fetch channel messages via the kernel's `get-channel-messages` method. */
1527
+ /**
1528
+ * Fetch channel messages via the kernel's `get-channel-messages` method.
1529
+ *
1530
+ * Now uses `fetchChannelMessagesWithCards` to get bundled cards in a single
1531
+ * request, eliminating the N+1 query problem. Cards are returned alongside
1532
+ * messages, grouped by parent message path.
1533
+ */
1486
1534
  declare function useChannelMessages(options: ChannelMessagesOptions): {
1487
1535
  messages: ChannelMessage[];
1536
+ /** Cards grouped by parent message path (child cards of messages). */
1537
+ messageCards: Map<string, ChannelCard[]>;
1538
+ /** Cards that are direct siblings of the channel (not nested under a message). */
1539
+ siblingCards: ChannelCard[];
1488
1540
  threads: ChannelMessage[];
1489
1541
  isLoading: boolean;
1490
1542
  isFetching: boolean;
1491
1543
  error: Error | null;
1492
- refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<ChannelMessage[], Error>>;
1544
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<ChannelMessagesResponse, Error>>;
1493
1545
  };
1494
1546
  /** Options for useInfiniteChannelMessages. */
1495
1547
  interface InfiniteChannelMessagesOptions {
@@ -1523,6 +1575,10 @@ interface InfiniteChannelMessagesOptions {
1523
1575
  */
1524
1576
  declare function useInfiniteChannelMessages(options: InfiniteChannelMessagesOptions): {
1525
1577
  messages: ChannelMessage[];
1578
+ /** Cards grouped by parent message path (child cards of messages). */
1579
+ messageCards: Map<string, ChannelCard[]>;
1580
+ /** Cards that are direct siblings of the channel (not nested under a message). */
1581
+ siblingCards: ChannelCard[];
1526
1582
  threads: ChannelMessage[];
1527
1583
  isLoading: boolean;
1528
1584
  isFetching: boolean;
@@ -1875,4 +1931,4 @@ declare function uploadFile(file: File | Blob, options: UploadOptions, onProgres
1875
1931
  */
1876
1932
  declare function useFileUpload(): UseFileUploadReturn;
1877
1933
 
1878
- export { type AccountInfo, type Channel, type ChannelMessage, type ChannelMessagesOptions, type ChannelMessagesPage, type ChannelsOptions, type ComponentOpener, ComponentRenderer, type CreateParams, type DeleteParams, EnforcementDeniedError, type EnforcementPayload, type FieldDescriptor, type FileRef, type GatewayParams, type GatewayResponse, type InfiniteChannelMessagesOptions, type ItemVersionsOptions, type ItemVersionsResult, type ItemsFilter, KernelProvider, type LinkParams, type MoveParams, type Notification, type NotificationsOptions, type OpenEnvelope, type OpenOptions, type PrincipalData, type ResolveParams, type ResolveResponse, type ResolveResultItem, type SessionEntry, type TypeDefinition, type TypeHelpers, type TypeSchema, type UnreadCountsOptions, type UpdateParams, type UploadItem, type UploadOptions, type UploadResult, type UseFileUploadReturn, type VFSEdge, type VFSItem, auth, awaitScopeReady, callTool, clearCachedToken, clearSession, createItem, disconnectSSE, disposeVfsRealtimeWs, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAssetUrl, getDefaultSort, getRequiredFormFields, getScope, getScopeVersion, getSessionEntry, initSession, initVfsRealtimeWs, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, isScopeReady, listChildren, mount, mountRealtimeScope, normalizeItem, ping, pushChanges, queryClient, readItem, registerCleanup, resetAllSdkState, resolvePrincipalId, setCachedToken, setScope, setupRequireShim, signal, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, unmountRealtimeScope, updateItem, uploadFile, useAccounts, useAllChannels, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useScope, useScopeReady, useSearch, useTheme, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, vfsKeys };
1934
+ export { type AccountInfo, type Channel, type ChannelCard, type ChannelMessage, type ChannelMessagesOptions, type ChannelMessagesPage, type ChannelMessagesResponse, type ChannelsOptions, type ComponentOpener, ComponentRenderer, type CreateParams, type DeleteParams, EnforcementDeniedError, type EnforcementPayload, type FieldDescriptor, type FileRef, type GatewayParams, type GatewayResponse, type InfiniteChannelMessagesOptions, type ItemVersionsOptions, type ItemVersionsResult, type ItemsFilter, KernelProvider, type LinkParams, type MoveParams, type Notification, type NotificationsOptions, type OpenEnvelope, type OpenOptions, type PrincipalData, type ResolveParams, type ResolveResponse, type ResolveResultItem, type SessionEntry, type TypeDefinition, type TypeHelpers, type TypeSchema, type UnreadCountsOptions, type UpdateParams, type UploadItem, type UploadOptions, type UploadResult, type UseFileUploadReturn, type VFSEdge, type VFSItem, auth, awaitScopeReady, callTool, clearCachedToken, clearSession, createItem, disconnectSSE, disposeVfsRealtimeWs, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAssetUrl, getDefaultSort, getRequiredFormFields, getScope, getScopeVersion, getSessionEntry, initSession, initVfsRealtimeWs, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, isScopeReady, listChildren, mount, mountRealtimeScope, normalizeItem, ping, pushChanges, queryClient, readItem, registerCleanup, resetAllSdkState, resolvePrincipalId, setCachedToken, setScope, setupRequireShim, signal, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, unmountRealtimeScope, updateItem, uploadFile, useAccounts, useAllChannels, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useScope, useScopeReady, useSearch, useTheme, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, vfsKeys };
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ __export(src_exports, {
30
30
  emitEvent: () => emitEvent,
31
31
  fetchChannelMessages: () => fetchChannelMessages,
32
32
  fetchChannelMessagesPage: () => fetchChannelMessagesPage,
33
+ fetchChannelMessagesWithCards: () => fetchChannelMessagesWithCards,
33
34
  fetchEdgesForItem: () => fetchEdgesForItem,
34
35
  fetchItemHistory: () => fetchItemHistory,
35
36
  fetchItemVersions: () => fetchItemVersions,
@@ -765,6 +766,26 @@ async function fetchItems(filter) {
765
766
  return { items: [], total_hint: 0 };
766
767
  }
767
768
  }
769
+ function parseChannelCards(rawItems) {
770
+ return rawItems.filter((i) => i.item_type === "card").map((i) => {
771
+ const td = i.type_data || {};
772
+ return {
773
+ id: i.id || "",
774
+ path: i.path || "",
775
+ name: i.name || (i.path || "").split("/").pop() || "",
776
+ createdAt: i.created_at || "",
777
+ action: td.action || "created",
778
+ targetId: td.target_id || void 0,
779
+ targetPath: td.target_path || "",
780
+ targetDisplayName: td.target_display_name || "",
781
+ targetDescription: td.target_description || "",
782
+ targetItemType: td.target_item_type || "",
783
+ toolId: (i.name || "").startsWith("card-") ? (i.name || "").substring(5) : void 0,
784
+ parentMessagePath: i.parent_message_path || void 0,
785
+ visibility: td.visibility || "private"
786
+ };
787
+ }).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
788
+ }
768
789
  function parseChannelMessages(rawItems) {
769
790
  return rawItems.filter((i) => i.item_type === "message").map((i) => {
770
791
  const td = i.type_data || {};
@@ -803,6 +824,40 @@ async function fetchChannelMessages(channelPath, parentMessageId) {
803
824
  return [];
804
825
  }
805
826
  }
827
+ async function fetchChannelMessagesWithCards(channelPath, parentMessageId) {
828
+ try {
829
+ const params = { channel_path: channelPath };
830
+ if (parentMessageId) params.parent_message_id = parentMessageId;
831
+ const response = await gatewayCall("get-channel-messages", params);
832
+ const raw = response;
833
+ const items = raw.messages || [];
834
+ const messages = parseChannelMessages(items);
835
+ const cards = parseChannelCards(items);
836
+ const messageCards = /* @__PURE__ */ new Map();
837
+ const siblingCards = [];
838
+ for (const card of cards) {
839
+ if (card.parentMessagePath) {
840
+ const existing = messageCards.get(card.parentMessagePath) || [];
841
+ existing.push(card);
842
+ messageCards.set(card.parentMessagePath, existing);
843
+ } else {
844
+ siblingCards.push(card);
845
+ }
846
+ }
847
+ return {
848
+ messages,
849
+ messageCards,
850
+ siblingCards,
851
+ mode: raw.mode || "top_level"
852
+ };
853
+ } catch (err) {
854
+ console.error(
855
+ `[gateway] Failed to fetch channel messages with cards for ${channelPath}:`,
856
+ err
857
+ );
858
+ return { messages: [], messageCards: /* @__PURE__ */ new Map(), siblingCards: [], mode: "top_level" };
859
+ }
860
+ }
806
861
  async function fetchChannelMessagesPage(channelPath, options) {
807
862
  try {
808
863
  const params = { channel_path: channelPath };
@@ -813,8 +868,22 @@ async function fetchChannelMessagesPage(channelPath, options) {
813
868
  const response = await gatewayCall("get-channel-messages", params);
814
869
  const raw = response;
815
870
  const items = raw.messages || [];
871
+ const cards = parseChannelCards(items);
872
+ const messageCards = /* @__PURE__ */ new Map();
873
+ const siblingCards = [];
874
+ for (const card of cards) {
875
+ if (card.parentMessagePath) {
876
+ const existing = messageCards.get(card.parentMessagePath) || [];
877
+ existing.push(card);
878
+ messageCards.set(card.parentMessagePath, existing);
879
+ } else {
880
+ siblingCards.push(card);
881
+ }
882
+ }
816
883
  return {
817
884
  messages: parseChannelMessages(items),
885
+ messageCards,
886
+ siblingCards,
818
887
  mode: raw.mode || "top_level"
819
888
  };
820
889
  } catch (err) {
@@ -822,7 +891,7 @@ async function fetchChannelMessagesPage(channelPath, options) {
822
891
  `[gateway] Failed to fetch channel messages page for ${channelPath}:`,
823
892
  err
824
893
  );
825
- return { messages: [], mode: "top_level" };
894
+ return { messages: [], messageCards: /* @__PURE__ */ new Map(), siblingCards: [], mode: "top_level" };
826
895
  }
827
896
  }
828
897
  function invalidateChildren(path) {
@@ -2262,7 +2331,7 @@ function useChannelMessages(options) {
2262
2331
  const debounceRef = useRef(null);
2263
2332
  const query = useQuery({
2264
2333
  queryKey: stableKey,
2265
- queryFn: () => fetchChannelMessages(channelPath, parentMessageId),
2334
+ queryFn: () => fetchChannelMessagesWithCards(channelPath, parentMessageId),
2266
2335
  enabled: isEnabled
2267
2336
  });
2268
2337
  useEffect(() => {
@@ -2276,7 +2345,7 @@ function useChannelMessages(options) {
2276
2345
  }, 500);
2277
2346
  },
2278
2347
  (data) => {
2279
- return data.item_type === "message" && typeof data.path === "string" && data.path.startsWith(channelPath);
2348
+ return (data.item_type === "message" || data.item_type === "card") && typeof data.path === "string" && data.path.startsWith(channelPath);
2280
2349
  }
2281
2350
  );
2282
2351
  return () => {
@@ -2284,9 +2353,16 @@ function useChannelMessages(options) {
2284
2353
  if (debounceRef.current) clearTimeout(debounceRef.current);
2285
2354
  };
2286
2355
  }, [realtime, isEnabled, channelPath, stableKey, qc]);
2287
- const messages = query.data ?? [];
2356
+ const response = query.data;
2357
+ const messages = response?.messages ?? [];
2358
+ const messageCards = response?.messageCards ?? /* @__PURE__ */ new Map();
2359
+ const siblingCards = response?.siblingCards ?? [];
2288
2360
  return {
2289
2361
  messages,
2362
+ /** Cards grouped by parent message path (child cards of messages). */
2363
+ messageCards,
2364
+ /** Cards that are direct siblings of the channel (not nested under a message). */
2365
+ siblingCards,
2290
2366
  threads: useMemo(() => messages.filter((m) => m.reply_count > 0), [messages]),
2291
2367
  isLoading: query.isLoading,
2292
2368
  isFetching: query.isFetching,
@@ -2338,17 +2414,60 @@ function useInfiniteChannelMessages(options) {
2338
2414
  }
2339
2415
  return flat.sort((a, b) => a.seq - b.seq);
2340
2416
  }, [query.data?.pages]);
2417
+ const { messageCards, siblingCards } = useMemo(() => {
2418
+ const mc = /* @__PURE__ */ new Map();
2419
+ const sc = [];
2420
+ if (!query.data?.pages) return { messageCards: mc, siblingCards: sc };
2421
+ const seenCards = /* @__PURE__ */ new Set();
2422
+ for (const page of query.data.pages) {
2423
+ for (const [path, cards] of page.messageCards) {
2424
+ for (const card of cards) {
2425
+ if (seenCards.has(card.id)) continue;
2426
+ seenCards.add(card.id);
2427
+ const existing = mc.get(path) || [];
2428
+ existing.push(card);
2429
+ mc.set(path, existing);
2430
+ }
2431
+ }
2432
+ for (const card of page.siblingCards) {
2433
+ if (seenCards.has(card.id)) continue;
2434
+ seenCards.add(card.id);
2435
+ sc.push(card);
2436
+ }
2437
+ }
2438
+ return { messageCards: mc, siblingCards: sc };
2439
+ }, [query.data?.pages]);
2440
+ const qc = useQueryClient();
2441
+ const debounceRef = useRef(null);
2442
+ const stableKey = useMemo(
2443
+ () => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit],
2444
+ [channelPath, parentMessageId, limit]
2445
+ );
2341
2446
  useEffect(() => {
2342
2447
  if (!realtime || !channelPath || !queryEnabled) return;
2343
- const unsub = subscribeToEvents(channelPath, (event) => {
2344
- if (event.event_type === "vfs_change") {
2345
- query.refetch();
2448
+ const unsub = subscribeToEvents(
2449
+ "vfs_change",
2450
+ () => {
2451
+ if (debounceRef.current) clearTimeout(debounceRef.current);
2452
+ debounceRef.current = setTimeout(() => {
2453
+ qc.invalidateQueries({ queryKey: stableKey });
2454
+ }, 500);
2455
+ },
2456
+ (data) => {
2457
+ return (data.item_type === "message" || data.item_type === "card") && typeof data.path === "string" && data.path.startsWith(channelPath);
2346
2458
  }
2347
- });
2348
- return unsub;
2349
- }, [realtime, channelPath, queryEnabled]);
2459
+ );
2460
+ return () => {
2461
+ unsub();
2462
+ if (debounceRef.current) clearTimeout(debounceRef.current);
2463
+ };
2464
+ }, [realtime, channelPath, queryEnabled, stableKey, qc]);
2350
2465
  return {
2351
2466
  messages,
2467
+ /** Cards grouped by parent message path (child cards of messages). */
2468
+ messageCards,
2469
+ /** Cards that are direct siblings of the channel (not nested under a message). */
2470
+ siblingCards,
2352
2471
  threads: messages.filter((m) => m.reply_count > 0),
2353
2472
  isLoading: query.isLoading,
2354
2473
  isFetching: query.isFetching,
@@ -3115,6 +3234,6 @@ function useFileUpload() {
3115
3234
  // src/index.ts
3116
3235
  __registerSdkExports(src_exports);
3117
3236
 
3118
- export { ComponentRenderer, EnforcementDeniedError, KernelProvider, auth, awaitScopeReady, callTool, clearCachedToken, clearSession, createItem, disconnectSSE, disposeVfsRealtimeWs, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAssetUrl, getDefaultSort, getRequiredFormFields, getScope, getScopeVersion, getSessionEntry, initSession, initVfsRealtimeWs, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, isScopeReady, listChildren, mount, mountRealtimeScope, normalizeItem, ping, pushChanges, queryClient, readItem, registerCleanup, resetAllSdkState, resolvePrincipalId, setCachedToken, setScope, setupRequireShim, signal, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, unmountRealtimeScope, updateItem, uploadFile, useAccounts, useAllChannels, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useScope, useScopeReady, useSearch, useTheme, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, vfsKeys };
3237
+ export { ComponentRenderer, EnforcementDeniedError, KernelProvider, auth, awaitScopeReady, callTool, clearCachedToken, clearSession, createItem, disconnectSSE, disposeVfsRealtimeWs, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAssetUrl, getDefaultSort, getRequiredFormFields, getScope, getScopeVersion, getSessionEntry, initSession, initVfsRealtimeWs, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, isScopeReady, listChildren, mount, mountRealtimeScope, normalizeItem, ping, pushChanges, queryClient, readItem, registerCleanup, resetAllSdkState, resolvePrincipalId, setCachedToken, setScope, setupRequireShim, signal, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, unmountRealtimeScope, updateItem, uploadFile, useAccounts, useAllChannels, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useScope, useScopeReady, useSearch, useTheme, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, vfsKeys };
3119
3238
  //# sourceMappingURL=index.js.map
3120
3239
  //# sourceMappingURL=index.js.map