@ai4b-team/fsaos-gateway-sdk 4.2.0 → 4.2.2
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/iife/gateway.js +5 -5
- package/dist/iife/gateway.js.map +3 -3
- package/dist/iife/ui.js +1 -1
- package/dist/index.cjs +39 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +39 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1324,6 +1324,10 @@ interface ChannelMessagesPage {
|
|
|
1324
1324
|
*/
|
|
1325
1325
|
declare function fetchChannelMessagesPage(channelPath: string, options?: {
|
|
1326
1326
|
parentMessageId?: string;
|
|
1327
|
+
/** List conversation roots before pagination, using the chat audience rules. */
|
|
1328
|
+
conversationsOnly?: boolean;
|
|
1329
|
+
/** Page human channel messages; receive system activity separately. */
|
|
1330
|
+
transcriptOnly?: boolean;
|
|
1327
1331
|
limit?: number;
|
|
1328
1332
|
before_seq?: number;
|
|
1329
1333
|
after_seq?: number;
|
|
@@ -2312,10 +2316,14 @@ interface InfiniteChannelMessagesOptions {
|
|
|
2312
2316
|
/** VFS path of the channel. Required. */
|
|
2313
2317
|
channelPath: string | undefined | null;
|
|
2314
2318
|
/**
|
|
2315
|
-
* If set, fetches thread replies
|
|
2316
|
-
*
|
|
2319
|
+
* If set, fetches thread replies. Both modes start with the latest page
|
|
2320
|
+
* and support older pages; threads also support explicit forward paging.
|
|
2317
2321
|
*/
|
|
2318
2322
|
parentMessageId?: string;
|
|
2323
|
+
/** Return conversation roots, excluding activity before the page limit. */
|
|
2324
|
+
conversationsOnly?: boolean;
|
|
2325
|
+
/** Page top-level human messages with a separate, bounded activity snapshot. */
|
|
2326
|
+
transcriptOnly?: boolean;
|
|
2319
2327
|
/** Messages per page. Default 50, max 200. */
|
|
2320
2328
|
limit?: number;
|
|
2321
2329
|
/** Enable SSE-driven auto-refresh. Default: true. */
|
|
@@ -2331,7 +2339,8 @@ interface InfiniteChannelMessagesOptions {
|
|
|
2331
2339
|
* loads older messages using `before_seq` = lowest seq in current data.
|
|
2332
2340
|
*
|
|
2333
2341
|
* - **Thread mode** (parentMessageId set): forward pagination.
|
|
2334
|
-
* Initial fetch returns the
|
|
2342
|
+
* Initial fetch returns the latest N replies. `fetchPreviousPage` loads older
|
|
2343
|
+
* replies using before_seq. `fetchNextPage` loads newer
|
|
2335
2344
|
* replies using `after_seq` = highest seq in current data.
|
|
2336
2345
|
*
|
|
2337
2346
|
* Returns a flat `messages` array (deduped, sorted by seq ASC) plus
|
|
@@ -2352,10 +2361,10 @@ declare function useInfiniteChannelMessages(options: InfiniteChannelMessagesOpti
|
|
|
2352
2361
|
error: Error | null;
|
|
2353
2362
|
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_tanstack_react_query.InfiniteData<ChannelMessagesPage, unknown>, Error>>;
|
|
2354
2363
|
hasPreviousPage: boolean;
|
|
2355
|
-
fetchPreviousPage: (options?: _tanstack_react_query.
|
|
2364
|
+
fetchPreviousPage: (options?: _tanstack_react_query.FetchNextPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<ChannelMessagesPage, unknown>, Error>>;
|
|
2356
2365
|
isFetchingPreviousPage: boolean;
|
|
2357
2366
|
hasNextPage: boolean;
|
|
2358
|
-
fetchNextPage: (options?: _tanstack_react_query.
|
|
2367
|
+
fetchNextPage: (options?: _tanstack_react_query.FetchPreviousPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<ChannelMessagesPage, unknown>, Error>>;
|
|
2359
2368
|
isFetchingNextPage: boolean;
|
|
2360
2369
|
};
|
|
2361
2370
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1324,6 +1324,10 @@ interface ChannelMessagesPage {
|
|
|
1324
1324
|
*/
|
|
1325
1325
|
declare function fetchChannelMessagesPage(channelPath: string, options?: {
|
|
1326
1326
|
parentMessageId?: string;
|
|
1327
|
+
/** List conversation roots before pagination, using the chat audience rules. */
|
|
1328
|
+
conversationsOnly?: boolean;
|
|
1329
|
+
/** Page human channel messages; receive system activity separately. */
|
|
1330
|
+
transcriptOnly?: boolean;
|
|
1327
1331
|
limit?: number;
|
|
1328
1332
|
before_seq?: number;
|
|
1329
1333
|
after_seq?: number;
|
|
@@ -2312,10 +2316,14 @@ interface InfiniteChannelMessagesOptions {
|
|
|
2312
2316
|
/** VFS path of the channel. Required. */
|
|
2313
2317
|
channelPath: string | undefined | null;
|
|
2314
2318
|
/**
|
|
2315
|
-
* If set, fetches thread replies
|
|
2316
|
-
*
|
|
2319
|
+
* If set, fetches thread replies. Both modes start with the latest page
|
|
2320
|
+
* and support older pages; threads also support explicit forward paging.
|
|
2317
2321
|
*/
|
|
2318
2322
|
parentMessageId?: string;
|
|
2323
|
+
/** Return conversation roots, excluding activity before the page limit. */
|
|
2324
|
+
conversationsOnly?: boolean;
|
|
2325
|
+
/** Page top-level human messages with a separate, bounded activity snapshot. */
|
|
2326
|
+
transcriptOnly?: boolean;
|
|
2319
2327
|
/** Messages per page. Default 50, max 200. */
|
|
2320
2328
|
limit?: number;
|
|
2321
2329
|
/** Enable SSE-driven auto-refresh. Default: true. */
|
|
@@ -2331,7 +2339,8 @@ interface InfiniteChannelMessagesOptions {
|
|
|
2331
2339
|
* loads older messages using `before_seq` = lowest seq in current data.
|
|
2332
2340
|
*
|
|
2333
2341
|
* - **Thread mode** (parentMessageId set): forward pagination.
|
|
2334
|
-
* Initial fetch returns the
|
|
2342
|
+
* Initial fetch returns the latest N replies. `fetchPreviousPage` loads older
|
|
2343
|
+
* replies using before_seq. `fetchNextPage` loads newer
|
|
2335
2344
|
* replies using `after_seq` = highest seq in current data.
|
|
2336
2345
|
*
|
|
2337
2346
|
* Returns a flat `messages` array (deduped, sorted by seq ASC) plus
|
|
@@ -2352,10 +2361,10 @@ declare function useInfiniteChannelMessages(options: InfiniteChannelMessagesOpti
|
|
|
2352
2361
|
error: Error | null;
|
|
2353
2362
|
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_tanstack_react_query.InfiniteData<ChannelMessagesPage, unknown>, Error>>;
|
|
2354
2363
|
hasPreviousPage: boolean;
|
|
2355
|
-
fetchPreviousPage: (options?: _tanstack_react_query.
|
|
2364
|
+
fetchPreviousPage: (options?: _tanstack_react_query.FetchNextPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<ChannelMessagesPage, unknown>, Error>>;
|
|
2356
2365
|
isFetchingPreviousPage: boolean;
|
|
2357
2366
|
hasNextPage: boolean;
|
|
2358
|
-
fetchNextPage: (options?: _tanstack_react_query.
|
|
2367
|
+
fetchNextPage: (options?: _tanstack_react_query.FetchPreviousPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<ChannelMessagesPage, unknown>, Error>>;
|
|
2359
2368
|
isFetchingNextPage: boolean;
|
|
2360
2369
|
};
|
|
2361
2370
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2086,7 +2086,7 @@ async function fetchChannelMessages(channelPath, parentMessageId) {
|
|
|
2086
2086
|
`[gateway] Failed to fetch channel messages for ${channelPath}:`,
|
|
2087
2087
|
err
|
|
2088
2088
|
);
|
|
2089
|
-
|
|
2089
|
+
throw err;
|
|
2090
2090
|
}
|
|
2091
2091
|
}
|
|
2092
2092
|
async function fetchChannelMessagesWithCards(channelPath, parentMessageId) {
|
|
@@ -2121,18 +2121,26 @@ async function fetchChannelMessagesWithCards(channelPath, parentMessageId) {
|
|
|
2121
2121
|
`[gateway] Failed to fetch channel messages with cards for ${channelPath}:`,
|
|
2122
2122
|
err
|
|
2123
2123
|
);
|
|
2124
|
-
|
|
2124
|
+
throw err;
|
|
2125
2125
|
}
|
|
2126
2126
|
}
|
|
2127
2127
|
async function fetchChannelMessagesPage(channelPath, options) {
|
|
2128
2128
|
try {
|
|
2129
2129
|
const params = { channel_path: channelPath };
|
|
2130
2130
|
if (options?.parentMessageId) params.parent_message_id = options.parentMessageId;
|
|
2131
|
+
if (options?.conversationsOnly) params.conversations_only = true;
|
|
2132
|
+
if (options?.transcriptOnly) params.transcript_only = true;
|
|
2131
2133
|
if (options?.limit) params.limit = options.limit;
|
|
2132
2134
|
if (options?.before_seq != null) params.before_seq = options.before_seq;
|
|
2133
2135
|
if (options?.after_seq != null) params.after_seq = options.after_seq;
|
|
2134
2136
|
const response = await gatewayCall("get-channel-messages", params);
|
|
2135
2137
|
const raw = response;
|
|
2138
|
+
if (options?.conversationsOnly && raw.conversations_only !== true) {
|
|
2139
|
+
throw new Error("This server does not support conversation history lists yet. Update the message reader.");
|
|
2140
|
+
}
|
|
2141
|
+
if (options?.transcriptOnly && raw.transcript_only !== true) {
|
|
2142
|
+
throw new Error("This server does not support channel transcript pages yet. Update the message reader.");
|
|
2143
|
+
}
|
|
2136
2144
|
const items = raw.messages || [];
|
|
2137
2145
|
const cards = parseChannelCards(items);
|
|
2138
2146
|
const messageCards = /* @__PURE__ */ new Map();
|
|
@@ -2158,7 +2166,7 @@ async function fetchChannelMessagesPage(channelPath, options) {
|
|
|
2158
2166
|
`[gateway] Failed to fetch channel messages page for ${channelPath}:`,
|
|
2159
2167
|
err
|
|
2160
2168
|
);
|
|
2161
|
-
|
|
2169
|
+
throw err;
|
|
2162
2170
|
}
|
|
2163
2171
|
}
|
|
2164
2172
|
function invalidateChildren(path) {
|
|
@@ -3865,31 +3873,32 @@ function useChannelMessages(options) {
|
|
|
3865
3873
|
}
|
|
3866
3874
|
function useInfiniteChannelMessages(options) {
|
|
3867
3875
|
useScopeKey();
|
|
3868
|
-
const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true } = options;
|
|
3876
|
+
const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true, conversationsOnly = false, transcriptOnly = false } = options;
|
|
3869
3877
|
const isThread = !!parentMessageId;
|
|
3870
3878
|
const queryEnabled = enabled2 && !!channelPath;
|
|
3871
3879
|
const query = useInfiniteQuery({
|
|
3872
|
-
queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit],
|
|
3880
|
+
queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : [], ...transcriptOnly ? ["transcript"] : []],
|
|
3873
3881
|
queryFn: async ({ pageParam }) => {
|
|
3874
3882
|
return fetchChannelMessagesPage(channelPath, {
|
|
3875
3883
|
parentMessageId,
|
|
3876
3884
|
limit,
|
|
3877
|
-
|
|
3878
|
-
|
|
3885
|
+
conversationsOnly,
|
|
3886
|
+
transcriptOnly,
|
|
3887
|
+
before_seq: pageParam?.before_seq,
|
|
3888
|
+
after_seq: pageParam?.after_seq
|
|
3879
3889
|
});
|
|
3880
3890
|
},
|
|
3881
3891
|
initialPageParam: void 0,
|
|
3882
|
-
|
|
3892
|
+
getPreviousPageParam: (lastPage) => {
|
|
3883
3893
|
if (!isThread) return void 0;
|
|
3884
3894
|
if (lastPage.messages.length < limit) return void 0;
|
|
3885
3895
|
const maxSeq = lastPage.messages[lastPage.messages.length - 1]?.seq;
|
|
3886
|
-
return maxSeq;
|
|
3896
|
+
return maxSeq == null ? void 0 : { after_seq: maxSeq };
|
|
3887
3897
|
},
|
|
3888
|
-
|
|
3889
|
-
if (isThread) return void 0;
|
|
3898
|
+
getNextPageParam: (firstPage) => {
|
|
3890
3899
|
if (firstPage.messages.length < limit) return void 0;
|
|
3891
3900
|
const minSeq = firstPage.messages[0]?.seq;
|
|
3892
|
-
return minSeq;
|
|
3901
|
+
return minSeq == null ? void 0 : { before_seq: minSeq };
|
|
3893
3902
|
},
|
|
3894
3903
|
enabled: queryEnabled
|
|
3895
3904
|
});
|
|
@@ -3933,8 +3942,8 @@ function useInfiniteChannelMessages(options) {
|
|
|
3933
3942
|
const qc = useQueryClient();
|
|
3934
3943
|
const debounceRef = useRef(null);
|
|
3935
3944
|
const stableKey = useMemo(
|
|
3936
|
-
() => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit],
|
|
3937
|
-
[channelPath, parentMessageId, limit]
|
|
3945
|
+
() => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : [], ...transcriptOnly ? ["transcript"] : []],
|
|
3946
|
+
[channelPath, parentMessageId, limit, conversationsOnly, transcriptOnly]
|
|
3938
3947
|
);
|
|
3939
3948
|
useEffect(() => {
|
|
3940
3949
|
if (!realtime || !channelPath || !queryEnabled) return;
|
|
@@ -3943,6 +3952,10 @@ function useInfiniteChannelMessages(options) {
|
|
|
3943
3952
|
let tailAgain = false;
|
|
3944
3953
|
let disposed = false;
|
|
3945
3954
|
const tailOnce = async () => {
|
|
3955
|
+
if (conversationsOnly || transcriptOnly) {
|
|
3956
|
+
reload();
|
|
3957
|
+
return;
|
|
3958
|
+
}
|
|
3946
3959
|
const currentData = qc.getQueryData(stableKey);
|
|
3947
3960
|
if (!currentData?.pages?.length) {
|
|
3948
3961
|
reload();
|
|
@@ -3981,7 +3994,7 @@ function useInfiniteChannelMessages(options) {
|
|
|
3981
3994
|
qc.setQueryData(stableKey, (old) => {
|
|
3982
3995
|
if (!old) return old;
|
|
3983
3996
|
const pages = [...old.pages];
|
|
3984
|
-
const lastIdx =
|
|
3997
|
+
const lastIdx = 0;
|
|
3985
3998
|
const lastPage = pages[lastIdx];
|
|
3986
3999
|
const existingIds = new Set(lastPage.messages.map((m) => m.id));
|
|
3987
4000
|
const uniqueNew = newPage.messages.filter((m) => !existingIds.has(m.id));
|
|
@@ -4033,7 +4046,7 @@ function useInfiniteChannelMessages(options) {
|
|
|
4033
4046
|
void tail();
|
|
4034
4047
|
}, 500);
|
|
4035
4048
|
},
|
|
4036
|
-
(data) => channelMessageChange(
|
|
4049
|
+
(data) => (conversationsOnly || transcriptOnly) && data?.item_type === "message" && (qc.getQueryData(stableKey)?.pages ?? []).some((page) => page.messages.some((root) => root.id === data.parent_id)) || channelMessageChange(
|
|
4037
4050
|
data,
|
|
4038
4051
|
channelPath,
|
|
4039
4052
|
parentMessageId,
|
|
@@ -4045,11 +4058,11 @@ function useInfiniteChannelMessages(options) {
|
|
|
4045
4058
|
unsub();
|
|
4046
4059
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
4047
4060
|
};
|
|
4048
|
-
}, [realtime, channelPath, queryEnabled, stableKey, qc, parentMessageId, limit]);
|
|
4061
|
+
}, [realtime, channelPath, queryEnabled, stableKey, qc, parentMessageId, limit, conversationsOnly, transcriptOnly]);
|
|
4049
4062
|
return {
|
|
4050
4063
|
messages,
|
|
4051
|
-
// Activity is a current
|
|
4052
|
-
activityMessages: query.data?.pages
|
|
4064
|
+
// Activity is a current snapshot, independent of transcript/reply pages.
|
|
4065
|
+
activityMessages: query.data?.pages[0]?.activityMessages ?? [],
|
|
4053
4066
|
/** Cards grouped by parent message path (child cards of messages). */
|
|
4054
4067
|
messageCards,
|
|
4055
4068
|
/** Cards that are direct siblings of the channel (not nested under a message). */
|
|
@@ -4061,14 +4074,14 @@ function useInfiniteChannelMessages(options) {
|
|
|
4061
4074
|
isFetching: query.isFetching,
|
|
4062
4075
|
error: query.error,
|
|
4063
4076
|
refetch: query.refetch,
|
|
4064
|
-
// Backward pagination (
|
|
4065
|
-
hasPreviousPage: query.
|
|
4066
|
-
fetchPreviousPage: query.
|
|
4067
|
-
isFetchingPreviousPage: query.
|
|
4077
|
+
// Backward pagination (channels and threads: load older)
|
|
4078
|
+
hasPreviousPage: query.hasNextPage ?? false,
|
|
4079
|
+
fetchPreviousPage: query.fetchNextPage,
|
|
4080
|
+
isFetchingPreviousPage: query.isFetchingNextPage ?? false,
|
|
4068
4081
|
// Forward pagination (thread: load newer)
|
|
4069
|
-
hasNextPage: query.
|
|
4070
|
-
fetchNextPage: query.
|
|
4071
|
-
isFetchingNextPage: query.
|
|
4082
|
+
hasNextPage: query.hasPreviousPage ?? false,
|
|
4083
|
+
fetchNextPage: query.fetchPreviousPage,
|
|
4084
|
+
isFetchingNextPage: query.isFetchingPreviousPage ?? false
|
|
4072
4085
|
};
|
|
4073
4086
|
}
|
|
4074
4087
|
var CHANNEL_AI_MODES = ["open", "active", "strict", "hand_raise"];
|