@ai4b-team/fsaos-gateway-sdk 4.1.0 → 4.2.1

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.js CHANGED
@@ -23,6 +23,8 @@ __export(src_exports, {
23
23
  InteractionTrackingError: () => InteractionTrackingError,
24
24
  KernelProvider: () => KernelProvider,
25
25
  QueryClientProvider: () => QueryClientProvider,
26
+ acceptInvite: () => acceptInvite,
27
+ answerInput: () => answerInput,
26
28
  assignPersonalSection: () => assignPersonalSection,
27
29
  auth: () => auth,
28
30
  awaitAnchorReady: () => awaitAnchorReady,
@@ -33,6 +35,7 @@ __export(src_exports, {
33
35
  clearCachedToken: () => clearCachedToken,
34
36
  clearSession: () => clearSession,
35
37
  configureGatewayReads: () => configureGatewayReads,
38
+ createAgent: () => createAgent,
36
39
  createItem: () => createItem,
37
40
  disconnectSSE: () => disconnectSSE,
38
41
  disposeVfsRealtimeWs: () => disposeVfsRealtimeWs,
@@ -89,6 +92,7 @@ __export(src_exports, {
89
92
  invalidatePathAndParent: () => invalidatePathAndParent,
90
93
  invalidateSubtree: () => invalidateSubtree,
91
94
  invalidateTypes: () => invalidateTypes,
95
+ inviteMember: () => inviteMember,
92
96
  isAnchorReady: () => isAnchorReady,
93
97
  isChannelPath: () => isChannelPath,
94
98
  isListableItemsFilter: () => isListableItemsFilter,
@@ -112,6 +116,7 @@ __export(src_exports, {
112
116
  resetAllSdkState: () => resetAllSdkState,
113
117
  resolvePrincipalId: () => resolvePrincipalId,
114
118
  resubscribePath: () => resubscribePath,
119
+ seatMember: () => seatMember,
115
120
  selectMount: () => selectMount,
116
121
  serverDeadlinePassed: () => serverDeadlinePassed,
117
122
  serverMsUntil: () => serverMsUntil,
@@ -138,9 +143,11 @@ __export(src_exports, {
138
143
  unmountRealtimeScope: () => unmountRealtimeScope,
139
144
  updateItem: () => updateItem,
140
145
  uploadFile: () => uploadFile,
146
+ useAcceptInvite: () => useAcceptInvite,
141
147
  useAccounts: () => useAccounts,
142
148
  useAgentTimeline: () => useAgentTimeline,
143
149
  useAllChannels: () => useAllChannels,
150
+ useAnswerInput: () => useAnswerInput,
144
151
  useArrangement: () => useArrangement,
145
152
  useArtifactStream: () => useArtifactStream,
146
153
  useAsset: () => useAsset,
@@ -150,6 +157,7 @@ __export(src_exports, {
150
157
  useChildren: () => useChildren,
151
158
  useComponent: () => useComponent,
152
159
  useCreate: () => useCreate,
160
+ useCreateAgent: () => useCreateAgent,
153
161
  useDelete: () => useDelete,
154
162
  useDmChannels: () => useDmChannels,
155
163
  useEdges: () => useEdges,
@@ -159,6 +167,7 @@ __export(src_exports, {
159
167
  useInfiniteChannelMessages: () => useInfiniteChannelMessages,
160
168
  useInfiniteChildren: () => useInfiniteChildren,
161
169
  useInfiniteItems: () => useInfiniteItems,
170
+ useInviteMember: () => useInviteMember,
162
171
  useItem: () => useItem,
163
172
  useItemById: () => useItemById,
164
173
  useItemHistory: () => useItemHistory,
@@ -186,6 +195,7 @@ __export(src_exports, {
186
195
  useScope: () => useScope,
187
196
  useScopeReady: () => useScopeReady,
188
197
  useSearch: () => useSearch,
198
+ useSeatMember: () => useSeatMember,
189
199
  useTheme: () => useTheme,
190
200
  useTimelineHistory: () => useTimelineHistory,
191
201
  useTool: () => useTool,
@@ -2076,7 +2086,7 @@ async function fetchChannelMessages(channelPath, parentMessageId) {
2076
2086
  `[gateway] Failed to fetch channel messages for ${channelPath}:`,
2077
2087
  err
2078
2088
  );
2079
- return [];
2089
+ throw err;
2080
2090
  }
2081
2091
  }
2082
2092
  async function fetchChannelMessagesWithCards(channelPath, parentMessageId) {
@@ -2111,18 +2121,22 @@ async function fetchChannelMessagesWithCards(channelPath, parentMessageId) {
2111
2121
  `[gateway] Failed to fetch channel messages with cards for ${channelPath}:`,
2112
2122
  err
2113
2123
  );
2114
- return { messages: [], messageCards: /* @__PURE__ */ new Map(), siblingCards: [], mode: "top_level" };
2124
+ throw err;
2115
2125
  }
2116
2126
  }
2117
2127
  async function fetchChannelMessagesPage(channelPath, options) {
2118
2128
  try {
2119
2129
  const params = { channel_path: channelPath };
2120
2130
  if (options?.parentMessageId) params.parent_message_id = options.parentMessageId;
2131
+ if (options?.conversationsOnly) params.conversations_only = true;
2121
2132
  if (options?.limit) params.limit = options.limit;
2122
2133
  if (options?.before_seq != null) params.before_seq = options.before_seq;
2123
2134
  if (options?.after_seq != null) params.after_seq = options.after_seq;
2124
2135
  const response = await gatewayCall("get-channel-messages", params);
2125
2136
  const raw = response;
2137
+ if (options?.conversationsOnly && raw.conversations_only !== true) {
2138
+ throw new Error("This server does not support conversation history lists yet. Update the message reader.");
2139
+ }
2126
2140
  const items = raw.messages || [];
2127
2141
  const cards = parseChannelCards(items);
2128
2142
  const messageCards = /* @__PURE__ */ new Map();
@@ -2148,7 +2162,7 @@ async function fetchChannelMessagesPage(channelPath, options) {
2148
2162
  `[gateway] Failed to fetch channel messages page for ${channelPath}:`,
2149
2163
  err
2150
2164
  );
2151
- return { messages: [], messageCards: /* @__PURE__ */ new Map(), siblingCards: [], mode: "top_level" };
2165
+ throw err;
2152
2166
  }
2153
2167
  }
2154
2168
  function invalidateChildren(path) {
@@ -3855,31 +3869,31 @@ function useChannelMessages(options) {
3855
3869
  }
3856
3870
  function useInfiniteChannelMessages(options) {
3857
3871
  useScopeKey();
3858
- const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true } = options;
3872
+ const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true, conversationsOnly = false } = options;
3859
3873
  const isThread = !!parentMessageId;
3860
3874
  const queryEnabled = enabled2 && !!channelPath;
3861
3875
  const query = useInfiniteQuery({
3862
- queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit],
3876
+ queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : []],
3863
3877
  queryFn: async ({ pageParam }) => {
3864
3878
  return fetchChannelMessagesPage(channelPath, {
3865
3879
  parentMessageId,
3866
3880
  limit,
3867
- before_seq: isThread ? void 0 : pageParam,
3868
- after_seq: isThread ? pageParam : void 0
3881
+ conversationsOnly,
3882
+ before_seq: pageParam?.before_seq,
3883
+ after_seq: pageParam?.after_seq
3869
3884
  });
3870
3885
  },
3871
3886
  initialPageParam: void 0,
3872
- getNextPageParam: (lastPage) => {
3887
+ getPreviousPageParam: (lastPage) => {
3873
3888
  if (!isThread) return void 0;
3874
3889
  if (lastPage.messages.length < limit) return void 0;
3875
3890
  const maxSeq = lastPage.messages[lastPage.messages.length - 1]?.seq;
3876
- return maxSeq;
3891
+ return maxSeq == null ? void 0 : { after_seq: maxSeq };
3877
3892
  },
3878
- getPreviousPageParam: (firstPage) => {
3879
- if (isThread) return void 0;
3893
+ getNextPageParam: (firstPage) => {
3880
3894
  if (firstPage.messages.length < limit) return void 0;
3881
3895
  const minSeq = firstPage.messages[0]?.seq;
3882
- return minSeq;
3896
+ return minSeq == null ? void 0 : { before_seq: minSeq };
3883
3897
  },
3884
3898
  enabled: queryEnabled
3885
3899
  });
@@ -3923,8 +3937,8 @@ function useInfiniteChannelMessages(options) {
3923
3937
  const qc = useQueryClient();
3924
3938
  const debounceRef = useRef(null);
3925
3939
  const stableKey = useMemo(
3926
- () => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit],
3927
- [channelPath, parentMessageId, limit]
3940
+ () => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : []],
3941
+ [channelPath, parentMessageId, limit, conversationsOnly]
3928
3942
  );
3929
3943
  useEffect(() => {
3930
3944
  if (!realtime || !channelPath || !queryEnabled) return;
@@ -3933,6 +3947,10 @@ function useInfiniteChannelMessages(options) {
3933
3947
  let tailAgain = false;
3934
3948
  let disposed = false;
3935
3949
  const tailOnce = async () => {
3950
+ if (conversationsOnly) {
3951
+ reload();
3952
+ return;
3953
+ }
3936
3954
  const currentData = qc.getQueryData(stableKey);
3937
3955
  if (!currentData?.pages?.length) {
3938
3956
  reload();
@@ -3971,7 +3989,7 @@ function useInfiniteChannelMessages(options) {
3971
3989
  qc.setQueryData(stableKey, (old) => {
3972
3990
  if (!old) return old;
3973
3991
  const pages = [...old.pages];
3974
- const lastIdx = pages.length - 1;
3992
+ const lastIdx = 0;
3975
3993
  const lastPage = pages[lastIdx];
3976
3994
  const existingIds = new Set(lastPage.messages.map((m) => m.id));
3977
3995
  const uniqueNew = newPage.messages.filter((m) => !existingIds.has(m.id));
@@ -4023,7 +4041,7 @@ function useInfiniteChannelMessages(options) {
4023
4041
  void tail();
4024
4042
  }, 500);
4025
4043
  },
4026
- (data) => channelMessageChange(
4044
+ (data) => conversationsOnly && data?.item_type === "message" && (qc.getQueryData(stableKey)?.pages ?? []).some((page) => page.messages.some((root) => root.id === data.parent_id)) || channelMessageChange(
4027
4045
  data,
4028
4046
  channelPath,
4029
4047
  parentMessageId,
@@ -4035,11 +4053,11 @@ function useInfiniteChannelMessages(options) {
4035
4053
  unsub();
4036
4054
  if (debounceRef.current) clearTimeout(debounceRef.current);
4037
4055
  };
4038
- }, [realtime, channelPath, queryEnabled, stableKey, qc, parentMessageId, limit]);
4056
+ }, [realtime, channelPath, queryEnabled, stableKey, qc, parentMessageId, limit, conversationsOnly]);
4039
4057
  return {
4040
4058
  messages,
4041
4059
  // Activity is a current thread snapshot, not another reply page.
4042
- activityMessages: query.data?.pages.at(-1)?.activityMessages ?? [],
4060
+ activityMessages: query.data?.pages[0]?.activityMessages ?? [],
4043
4061
  /** Cards grouped by parent message path (child cards of messages). */
4044
4062
  messageCards,
4045
4063
  /** Cards that are direct siblings of the channel (not nested under a message). */
@@ -4051,14 +4069,14 @@ function useInfiniteChannelMessages(options) {
4051
4069
  isFetching: query.isFetching,
4052
4070
  error: query.error,
4053
4071
  refetch: query.refetch,
4054
- // Backward pagination (top-level: load older)
4055
- hasPreviousPage: query.hasPreviousPage ?? false,
4056
- fetchPreviousPage: query.fetchPreviousPage,
4057
- isFetchingPreviousPage: query.isFetchingPreviousPage ?? false,
4072
+ // Backward pagination (channels and threads: load older)
4073
+ hasPreviousPage: query.hasNextPage ?? false,
4074
+ fetchPreviousPage: query.fetchNextPage,
4075
+ isFetchingPreviousPage: query.isFetchingNextPage ?? false,
4058
4076
  // Forward pagination (thread: load newer)
4059
- hasNextPage: query.hasNextPage ?? false,
4060
- fetchNextPage: query.fetchNextPage,
4061
- isFetchingNextPage: query.isFetchingNextPage ?? false
4077
+ hasNextPage: query.hasPreviousPage ?? false,
4078
+ fetchNextPage: query.fetchPreviousPage,
4079
+ isFetchingNextPage: query.isFetchingPreviousPage ?? false
4062
4080
  };
4063
4081
  }
4064
4082
  var CHANNEL_AI_MODES = ["open", "active", "strict", "hand_raise"];
@@ -5454,6 +5472,71 @@ function setupRequireShim() {
5454
5472
  };
5455
5473
  window.__FSAOS_MOUNT__ = gateway.mount;
5456
5474
  }
5475
+ function inviteMember(params) {
5476
+ return gatewayCall("invite-member", params);
5477
+ }
5478
+ function acceptInvite(params) {
5479
+ return gatewayCall("accept-invite", params);
5480
+ }
5481
+ function seatMember(params) {
5482
+ const context = {};
5483
+ if (params.role) context.role = params.role;
5484
+ return gatewayCall("link", {
5485
+ source_id: params.chat_id,
5486
+ target_id: params.member_id,
5487
+ edge_type: "has_member",
5488
+ context
5489
+ });
5490
+ }
5491
+ function createAgent(params) {
5492
+ return gatewayCall("create-agent", params);
5493
+ }
5494
+ function answerInput(params) {
5495
+ if (!params.input_request_id && !params.input_request) {
5496
+ return Promise.reject(new Error("answerInput needs input_request_id or the input_request object read from the step."));
5497
+ }
5498
+ return gatewayCall("todo-control", { action: "answer_input", ...params });
5499
+ }
5500
+ function useInviteMember() {
5501
+ return useMutation$1({ mutationFn: inviteMember });
5502
+ }
5503
+ function useAcceptInvite() {
5504
+ const qc = useQueryClient();
5505
+ return useMutation$1({
5506
+ mutationFn: acceptInvite,
5507
+ onSuccess: () => {
5508
+ qc.invalidateQueries({ queryKey: ["memberships"] });
5509
+ }
5510
+ });
5511
+ }
5512
+ function useSeatMember() {
5513
+ const qc = useQueryClient();
5514
+ return useMutation$1({
5515
+ mutationFn: seatMember,
5516
+ onSuccess: (_data, variables) => {
5517
+ qc.invalidateQueries({ queryKey: vfsKeys.edges(variables.chat_id) });
5518
+ qc.invalidateQueries({ queryKey: vfsKeys.edges(variables.member_id) });
5519
+ }
5520
+ });
5521
+ }
5522
+ function useCreateAgent() {
5523
+ const qc = useQueryClient();
5524
+ return useMutation$1({
5525
+ mutationFn: createAgent,
5526
+ onSuccess: () => {
5527
+ qc.invalidateQueries({ queryKey: ["memberships"] });
5528
+ }
5529
+ });
5530
+ }
5531
+ function useAnswerInput() {
5532
+ const qc = useQueryClient();
5533
+ return useMutation$1({
5534
+ mutationFn: answerInput,
5535
+ onSuccess: (_data, variables) => {
5536
+ qc.invalidateQueries({ queryKey: vfsKeys.itemById(variables.step_id) });
5537
+ }
5538
+ });
5539
+ }
5457
5540
 
5458
5541
  // src/schema-utils.ts
5459
5542
  function keyToLabel(key) {
@@ -6253,6 +6336,6 @@ function usePersonalSections(contextId, collection) {
6253
6336
  // src/index.ts
6254
6337
  __registerSdkExports(src_exports);
6255
6338
 
6256
- export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, InteractionTrackingError, KernelProvider, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getHomeAnchor, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, loadMounts, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, replaceMounts, resetAllSdkState, resolvePrincipalId, resubscribePath, selectMount, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAccounts, useAgentTimeline, useAllChannels, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useTheme, useTimelineHistory, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, useUpdatePrincipal, vfsKeys, waitForPathReady };
6339
+ export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, InteractionTrackingError, KernelProvider, acceptInvite, answerInput, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, createAgent, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getHomeAnchor, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, inviteMember, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, loadMounts, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, replaceMounts, resetAllSdkState, resolvePrincipalId, resubscribePath, seatMember, selectMount, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAcceptInvite, useAccounts, useAgentTimeline, useAllChannels, useAnswerInput, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useCreateAgent, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useInviteMember, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useSeatMember, useTheme, useTimelineHistory, useTool, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, useUpdatePrincipal, vfsKeys, waitForPathReady };
6257
6340
  //# sourceMappingURL=index.js.map
6258
6341
  //# sourceMappingURL=index.js.map