@ai4b-team/fsaos-gateway-sdk 5.6.0 → 5.6.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 +4 -4
- package/dist/iife/ui.js +1 -1
- package/dist/index.cjs +220 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +220 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1658,6 +1658,11 @@ declare function mount(): void;
|
|
|
1658
1658
|
*/
|
|
1659
1659
|
declare function setupRequireShim(): void;
|
|
1660
1660
|
|
|
1661
|
+
/** Preserve the history boundary when a live edit removes a cached message. */
|
|
1662
|
+
type TranscriptPage = ChannelMessagesPage & {
|
|
1663
|
+
olderBefore?: number;
|
|
1664
|
+
};
|
|
1665
|
+
|
|
1661
1666
|
/**
|
|
1662
1667
|
* Returns whether scope has been established. Useful for gating UI that
|
|
1663
1668
|
* depends on scope-aware data.
|
|
@@ -2778,12 +2783,12 @@ declare function useInfiniteChannelMessages(options: InfiniteChannelMessagesOpti
|
|
|
2778
2783
|
isLoading: boolean;
|
|
2779
2784
|
isFetching: boolean;
|
|
2780
2785
|
error: Error | null;
|
|
2781
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_tanstack_react_query.InfiniteData<
|
|
2786
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_tanstack_react_query.InfiniteData<TranscriptPage, unknown>, Error>>;
|
|
2782
2787
|
hasPreviousPage: boolean;
|
|
2783
|
-
fetchPreviousPage: (options?: _tanstack_react_query.FetchNextPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<
|
|
2788
|
+
fetchPreviousPage: (options?: _tanstack_react_query.FetchNextPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<TranscriptPage, unknown>, Error>>;
|
|
2784
2789
|
isFetchingPreviousPage: boolean;
|
|
2785
2790
|
hasNextPage: boolean;
|
|
2786
|
-
fetchNextPage: (options?: _tanstack_react_query.FetchPreviousPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<
|
|
2791
|
+
fetchNextPage: (options?: _tanstack_react_query.FetchPreviousPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<TranscriptPage, unknown>, Error>>;
|
|
2787
2792
|
isFetchingNextPage: boolean;
|
|
2788
2793
|
};
|
|
2789
2794
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1658,6 +1658,11 @@ declare function mount(): void;
|
|
|
1658
1658
|
*/
|
|
1659
1659
|
declare function setupRequireShim(): void;
|
|
1660
1660
|
|
|
1661
|
+
/** Preserve the history boundary when a live edit removes a cached message. */
|
|
1662
|
+
type TranscriptPage = ChannelMessagesPage & {
|
|
1663
|
+
olderBefore?: number;
|
|
1664
|
+
};
|
|
1665
|
+
|
|
1661
1666
|
/**
|
|
1662
1667
|
* Returns whether scope has been established. Useful for gating UI that
|
|
1663
1668
|
* depends on scope-aware data.
|
|
@@ -2778,12 +2783,12 @@ declare function useInfiniteChannelMessages(options: InfiniteChannelMessagesOpti
|
|
|
2778
2783
|
isLoading: boolean;
|
|
2779
2784
|
isFetching: boolean;
|
|
2780
2785
|
error: Error | null;
|
|
2781
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_tanstack_react_query.InfiniteData<
|
|
2786
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_tanstack_react_query.InfiniteData<TranscriptPage, unknown>, Error>>;
|
|
2782
2787
|
hasPreviousPage: boolean;
|
|
2783
|
-
fetchPreviousPage: (options?: _tanstack_react_query.FetchNextPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<
|
|
2788
|
+
fetchPreviousPage: (options?: _tanstack_react_query.FetchNextPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<TranscriptPage, unknown>, Error>>;
|
|
2784
2789
|
isFetchingPreviousPage: boolean;
|
|
2785
2790
|
hasNextPage: boolean;
|
|
2786
|
-
fetchNextPage: (options?: _tanstack_react_query.FetchPreviousPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<
|
|
2791
|
+
fetchNextPage: (options?: _tanstack_react_query.FetchPreviousPageOptions) => Promise<_tanstack_react_query.InfiniteQueryObserverResult<_tanstack_react_query.InfiniteData<TranscriptPage, unknown>, Error>>;
|
|
2787
2792
|
isFetchingNextPage: boolean;
|
|
2788
2793
|
};
|
|
2789
2794
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1746,7 +1746,7 @@ function normalizeItem(raw) {
|
|
|
1746
1746
|
const path = raw.path || raw.item_path || "";
|
|
1747
1747
|
const segments = path.split("/");
|
|
1748
1748
|
segments.pop();
|
|
1749
|
-
const
|
|
1749
|
+
const parentPath2 = segments.join("/");
|
|
1750
1750
|
const typeData = raw.type_data || {};
|
|
1751
1751
|
if (typeData.allowed_parent_types && !typeData.accepts) {
|
|
1752
1752
|
typeData.accepts = typeData.allowed_parent_types;
|
|
@@ -1757,7 +1757,7 @@ function normalizeItem(raw) {
|
|
|
1757
1757
|
name: raw.name || raw.item_name || "",
|
|
1758
1758
|
item_type: raw.item_type || "unknown",
|
|
1759
1759
|
path,
|
|
1760
|
-
parent_path:
|
|
1760
|
+
parent_path: parentPath2,
|
|
1761
1761
|
is_active: raw.is_active !== false,
|
|
1762
1762
|
has_children: raw.has_children ?? false,
|
|
1763
1763
|
created_at: raw.created_at || nowISO(),
|
|
@@ -2388,9 +2388,9 @@ function invalidatePathAndParent(path, fallbackParent) {
|
|
|
2388
2388
|
invalidateChildren(path);
|
|
2389
2389
|
const segments = path.split("/");
|
|
2390
2390
|
segments.pop();
|
|
2391
|
-
const
|
|
2392
|
-
if (
|
|
2393
|
-
invalidateChildren(
|
|
2391
|
+
const parentPath2 = segments.join("/") || fallbackParent;
|
|
2392
|
+
if (parentPath2) {
|
|
2393
|
+
invalidateChildren(parentPath2);
|
|
2394
2394
|
}
|
|
2395
2395
|
}
|
|
2396
2396
|
function invalidateSubtree(path) {
|
|
@@ -2528,22 +2528,22 @@ function handleVfsChange(data) {
|
|
|
2528
2528
|
if (!path) return;
|
|
2529
2529
|
const segments = path.split("/");
|
|
2530
2530
|
segments.pop();
|
|
2531
|
-
const
|
|
2532
|
-
let changes = pendingChanges.get(
|
|
2531
|
+
const parentPath2 = segments.join("/") || "/root";
|
|
2532
|
+
let changes = pendingChanges.get(parentPath2);
|
|
2533
2533
|
if (!changes) {
|
|
2534
2534
|
changes = /* @__PURE__ */ new Map();
|
|
2535
|
-
pendingChanges.set(
|
|
2535
|
+
pendingChanges.set(parentPath2, changes);
|
|
2536
2536
|
}
|
|
2537
2537
|
changes.set(path, { action, itemId: typeof data.item_id === "string" ? data.item_id : void 0 });
|
|
2538
|
-
const existing = debounceTimers.get(
|
|
2538
|
+
const existing = debounceTimers.get(parentPath2);
|
|
2539
2539
|
if (existing) clearTimeout(existing);
|
|
2540
2540
|
const timer = setTimeout(() => {
|
|
2541
|
-
debounceTimers.delete(
|
|
2542
|
-
const flushed = pendingChanges.get(
|
|
2543
|
-
pendingChanges.delete(
|
|
2544
|
-
if (flushed) applyInvalidation(
|
|
2541
|
+
debounceTimers.delete(parentPath2);
|
|
2542
|
+
const flushed = pendingChanges.get(parentPath2);
|
|
2543
|
+
pendingChanges.delete(parentPath2);
|
|
2544
|
+
if (flushed) applyInvalidation(parentPath2, flushed);
|
|
2545
2545
|
}, DEBOUNCE_MS);
|
|
2546
|
-
debounceTimers.set(
|
|
2546
|
+
debounceTimers.set(parentPath2, timer);
|
|
2547
2547
|
}
|
|
2548
2548
|
function handleCcmChange(data) {
|
|
2549
2549
|
if (!data || typeof data !== "object") return;
|
|
@@ -2565,7 +2565,7 @@ function handleCcmChange(data) {
|
|
|
2565
2565
|
}, DEBOUNCE_MS);
|
|
2566
2566
|
debounceTimers.set(debounceKey, timer);
|
|
2567
2567
|
}
|
|
2568
|
-
function applyInvalidation(
|
|
2568
|
+
function applyInvalidation(parentPath2, changes) {
|
|
2569
2569
|
const client2 = getQueryClient();
|
|
2570
2570
|
for (const [path, change] of changes) {
|
|
2571
2571
|
if ((change.action || "").toUpperCase() === "DELETE") {
|
|
@@ -2579,7 +2579,7 @@ function applyInvalidation(parentPath, changes) {
|
|
|
2579
2579
|
client2.invalidateQueries({ queryKey: vfsKeys.itemById(change.itemId) });
|
|
2580
2580
|
}
|
|
2581
2581
|
}
|
|
2582
|
-
client2.invalidateQueries({ queryKey: vfsKeys.children(
|
|
2582
|
+
client2.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
|
|
2583
2583
|
const changed = [...changes.keys()];
|
|
2584
2584
|
client2.invalidateQueries({
|
|
2585
2585
|
predicate: (query) => {
|
|
@@ -2954,9 +2954,57 @@ function channelMessageChange(event, channelPath, parentId, messages) {
|
|
|
2954
2954
|
});
|
|
2955
2955
|
}
|
|
2956
2956
|
|
|
2957
|
-
// src/channel-realtime.ts
|
|
2957
|
+
// src/channel-transcript-realtime.ts
|
|
2958
2958
|
var watches = /* @__PURE__ */ new WeakMap();
|
|
2959
|
-
|
|
2959
|
+
var parentPath = (path) => path.slice(0, path.lastIndexOf("/"));
|
|
2960
|
+
var actionOf = (change) => change.action?.toLowerCase();
|
|
2961
|
+
function isNewPost(change, channel) {
|
|
2962
|
+
return change.item_type === "message" && actionOf(change) === "insert" && parentPath(change.path) === channel && !change.old_path;
|
|
2963
|
+
}
|
|
2964
|
+
function affectedMessages(page, ids, paths) {
|
|
2965
|
+
return page.messages.filter((message) => ids.has(message.id) || paths.has(message.path));
|
|
2966
|
+
}
|
|
2967
|
+
function updateTranscript(cached, targets, revised, tail) {
|
|
2968
|
+
const pages = cached.pages.slice();
|
|
2969
|
+
const replacements = new Map(revised?.messages.map((message) => [message.id, message]));
|
|
2970
|
+
for (const [index, affected] of targets) {
|
|
2971
|
+
const page = pages[index];
|
|
2972
|
+
const wanted = new Set(affected.map((message) => message.id));
|
|
2973
|
+
const messageCards2 = new Map(page.messageCards);
|
|
2974
|
+
for (const message of affected) {
|
|
2975
|
+
messageCards2.delete(message.path);
|
|
2976
|
+
const replacement = replacements.get(message.id);
|
|
2977
|
+
const cards = replacement && revised?.messageCards.get(replacement.path);
|
|
2978
|
+
if (replacement && cards?.length) messageCards2.set(replacement.path, cards);
|
|
2979
|
+
}
|
|
2980
|
+
pages[index] = {
|
|
2981
|
+
...page,
|
|
2982
|
+
messages: page.messages.flatMap((message) => {
|
|
2983
|
+
if (!wanted.has(message.id)) return [message];
|
|
2984
|
+
const replacement = replacements.get(message.id);
|
|
2985
|
+
return replacement ? [replacement] : [];
|
|
2986
|
+
}),
|
|
2987
|
+
messageCards: messageCards2
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
const snapshot = tail ?? revised;
|
|
2991
|
+
const latest = pages[0];
|
|
2992
|
+
const messageCards = new Map(latest.messageCards);
|
|
2993
|
+
for (const message of latest.activityMessages ?? []) messageCards.delete(message.path);
|
|
2994
|
+
for (const message of [...snapshot.activityMessages ?? [], ...tail?.messages ?? []]) {
|
|
2995
|
+
const cards = snapshot.messageCards.get(message.path);
|
|
2996
|
+
if (cards?.length) messageCards.set(message.path, cards);
|
|
2997
|
+
}
|
|
2998
|
+
pages[0] = {
|
|
2999
|
+
...latest,
|
|
3000
|
+
messages: tail ? [...latest.messages, ...tail.messages] : latest.messages,
|
|
3001
|
+
activityMessages: snapshot.activityMessages,
|
|
3002
|
+
siblingCards: snapshot.siblingCards,
|
|
3003
|
+
messageCards
|
|
3004
|
+
};
|
|
3005
|
+
return { ...cached, pages };
|
|
3006
|
+
}
|
|
3007
|
+
function watchChannelTranscript(client2, key, channel, limit) {
|
|
2960
3008
|
let entries = watches.get(client2);
|
|
2961
3009
|
if (!entries) {
|
|
2962
3010
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -2964,6 +3012,133 @@ function watchChannels(client2, key, normalize) {
|
|
|
2964
3012
|
}
|
|
2965
3013
|
const hash = JSON.stringify(key);
|
|
2966
3014
|
let watch = entries.get(hash);
|
|
3015
|
+
if (!watch) {
|
|
3016
|
+
let timer;
|
|
3017
|
+
let running2 = false;
|
|
3018
|
+
let stopped = false;
|
|
3019
|
+
const pending4 = /* @__PURE__ */ new Map();
|
|
3020
|
+
const current = () => client2.getQueryData(key);
|
|
3021
|
+
const query = () => client2.getQueryCache().find({ queryKey: key, exact: true });
|
|
3022
|
+
const reload = () => refreshQuery(client2, key, { exact: true });
|
|
3023
|
+
const read = (after_seq, before_seq) => fetchChannelMessagesPage(channel, { transcriptOnly: true, limit, after_seq, before_seq });
|
|
3024
|
+
const schedule2 = () => {
|
|
3025
|
+
if (stopped || running2 || timer || !pending4.size) return;
|
|
3026
|
+
timer = setTimeout(() => {
|
|
3027
|
+
timer = void 0;
|
|
3028
|
+
void flush();
|
|
3029
|
+
}, 500);
|
|
3030
|
+
};
|
|
3031
|
+
const flush = async () => {
|
|
3032
|
+
running2 = true;
|
|
3033
|
+
const changes = [...pending4.values()];
|
|
3034
|
+
pending4.clear();
|
|
3035
|
+
const owner = query();
|
|
3036
|
+
try {
|
|
3037
|
+
if (owner?.state.fetchStatus === "fetching") await owner.promise?.catch(() => void 0);
|
|
3038
|
+
if (stopped || owner !== query()) return;
|
|
3039
|
+
const cached = current();
|
|
3040
|
+
if (!cached?.pages.length) {
|
|
3041
|
+
await reload();
|
|
3042
|
+
return;
|
|
3043
|
+
}
|
|
3044
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3045
|
+
const paths = /* @__PURE__ */ new Set();
|
|
3046
|
+
const possiblyAdmitted = /* @__PURE__ */ new Set();
|
|
3047
|
+
let append = false;
|
|
3048
|
+
for (const change of changes) {
|
|
3049
|
+
if (isNewPost(change, channel)) {
|
|
3050
|
+
append = true;
|
|
3051
|
+
continue;
|
|
3052
|
+
}
|
|
3053
|
+
if (change.inserted) append = true;
|
|
3054
|
+
if (change.item_type === "message" && parentPath(change.path) === channel && !change.inserted && actionOf(change) !== "delete") possiblyAdmitted.add(change.path);
|
|
3055
|
+
if (change.item_id) ids.add(change.item_id);
|
|
3056
|
+
if (change.parent_id) ids.add(change.parent_id);
|
|
3057
|
+
for (const path of [change.path, change.old_path]) {
|
|
3058
|
+
if (path && isChannelPath(path, channel)) {
|
|
3059
|
+
paths.add(path);
|
|
3060
|
+
paths.add(parentPath(path));
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
const targets = /* @__PURE__ */ new Map();
|
|
3065
|
+
let low = Infinity;
|
|
3066
|
+
let high = 0;
|
|
3067
|
+
if (ids.size || paths.size) {
|
|
3068
|
+
cached.pages.forEach((page, index) => {
|
|
3069
|
+
const affected = affectedMessages(page, ids, paths);
|
|
3070
|
+
if (affected.length) targets.set(index, affected);
|
|
3071
|
+
for (const message of affected) {
|
|
3072
|
+
possiblyAdmitted.delete(message.path);
|
|
3073
|
+
low = Math.min(low, message.seq);
|
|
3074
|
+
high = Math.max(high, message.seq);
|
|
3075
|
+
}
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
for (const activity of cached.pages[0].activityMessages ?? []) possiblyAdmitted.delete(activity.path);
|
|
3079
|
+
if (possiblyAdmitted.size) {
|
|
3080
|
+
await reload();
|
|
3081
|
+
return;
|
|
3082
|
+
}
|
|
3083
|
+
if (targets.size && (!Number.isSafeInteger(low) || low < 1 || !Number.isSafeInteger(high + 1))) {
|
|
3084
|
+
await reload();
|
|
3085
|
+
return;
|
|
3086
|
+
}
|
|
3087
|
+
const latest = cached.pages.find((page) => page.messages.length)?.messages.at(-1)?.seq ?? 0;
|
|
3088
|
+
const [revised, tail] = await Promise.all([
|
|
3089
|
+
targets.size ? read(low - 1, high + 1) : void 0,
|
|
3090
|
+
append || !targets.size ? read(latest) : void 0
|
|
3091
|
+
]);
|
|
3092
|
+
if (stopped || owner !== query()) return;
|
|
3093
|
+
const settled = current();
|
|
3094
|
+
if (owner?.state.fetchStatus === "fetching" || cached.pages.some((page, index) => settled?.pages[index] !== page) || revised && revised.messages.length >= limit && (revised.messages.at(-1)?.seq ?? 0) < high || tail && tail.messages.length >= limit) {
|
|
3095
|
+
await reload();
|
|
3096
|
+
return;
|
|
3097
|
+
}
|
|
3098
|
+
client2.setQueryData(key, (data) => data && updateTranscript(data, targets, revised, tail));
|
|
3099
|
+
} catch {
|
|
3100
|
+
if (!stopped && owner === query()) await reload();
|
|
3101
|
+
} finally {
|
|
3102
|
+
running2 = false;
|
|
3103
|
+
schedule2();
|
|
3104
|
+
}
|
|
3105
|
+
};
|
|
3106
|
+
const stop = subscribeToEvents("vfs_change", (change) => {
|
|
3107
|
+
const id = change.item_id ?? change.path;
|
|
3108
|
+
const previous = pending4.get(id);
|
|
3109
|
+
pending4.set(id, previous && (previous.inserted || isNewPost(previous, channel)) && actionOf(change) === "update" && previous.path === change.path ? { ...change, inserted: true } : change);
|
|
3110
|
+
schedule2();
|
|
3111
|
+
}, (change) => channelMessageChange(change, channel, void 0, []) || !!change.old_path && channelMessageChange({ ...change, path: change.old_path }, channel, void 0, []) || change.item_type === "message" && !!change.parent_id && isChannelPath(change.path, channel) && !!current()?.pages.some((page) => page.messages.some((root) => root.id === change.parent_id)));
|
|
3112
|
+
watch = { users: 0, stop: () => {
|
|
3113
|
+
stopped = true;
|
|
3114
|
+
stop();
|
|
3115
|
+
if (timer) clearTimeout(timer);
|
|
3116
|
+
pending4.clear();
|
|
3117
|
+
} };
|
|
3118
|
+
entries.set(hash, watch);
|
|
3119
|
+
}
|
|
3120
|
+
watch.users++;
|
|
3121
|
+
let released = false;
|
|
3122
|
+
return () => {
|
|
3123
|
+
if (released) return;
|
|
3124
|
+
released = true;
|
|
3125
|
+
if (--watch.users === 0) {
|
|
3126
|
+
watch.stop();
|
|
3127
|
+
entries.delete(hash);
|
|
3128
|
+
}
|
|
3129
|
+
};
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
// src/channel-realtime.ts
|
|
3133
|
+
var watches2 = /* @__PURE__ */ new WeakMap();
|
|
3134
|
+
function watchChannels(client2, key, normalize) {
|
|
3135
|
+
let entries = watches2.get(client2);
|
|
3136
|
+
if (!entries) {
|
|
3137
|
+
entries = /* @__PURE__ */ new Map();
|
|
3138
|
+
watches2.set(client2, entries);
|
|
3139
|
+
}
|
|
3140
|
+
const hash = JSON.stringify(key);
|
|
3141
|
+
let watch = entries.get(hash);
|
|
2967
3142
|
if (!watch) {
|
|
2968
3143
|
let stopped = false;
|
|
2969
3144
|
let timer;
|
|
@@ -3079,12 +3254,12 @@ function watchChannels(client2, key, normalize) {
|
|
|
3079
3254
|
}
|
|
3080
3255
|
|
|
3081
3256
|
// src/message-replies-realtime.ts
|
|
3082
|
-
var
|
|
3257
|
+
var watches3 = /* @__PURE__ */ new WeakMap();
|
|
3083
3258
|
function watchMessageReplies(client2, key, target) {
|
|
3084
|
-
let entries =
|
|
3259
|
+
let entries = watches3.get(client2);
|
|
3085
3260
|
if (!entries) {
|
|
3086
3261
|
entries = /* @__PURE__ */ new Map();
|
|
3087
|
-
|
|
3262
|
+
watches3.set(client2, entries);
|
|
3088
3263
|
}
|
|
3089
3264
|
const hash = JSON.stringify(key);
|
|
3090
3265
|
let watch = entries.get(hash);
|
|
@@ -4556,24 +4731,25 @@ function useMessageReplies(options) {
|
|
|
4556
4731
|
[active, realtime, client2, key, messageId]
|
|
4557
4732
|
);
|
|
4558
4733
|
const messages = useMemo(() => {
|
|
4734
|
+
if (!active || query.isError) return [];
|
|
4559
4735
|
const seen = /* @__PURE__ */ new Set();
|
|
4560
4736
|
return (query.data?.pages ?? []).flatMap((page) => page.messages).filter((message) => {
|
|
4561
4737
|
if (seen.has(message.id)) return false;
|
|
4562
4738
|
seen.add(message.id);
|
|
4563
4739
|
return true;
|
|
4564
4740
|
});
|
|
4565
|
-
}, [query.data]);
|
|
4741
|
+
}, [active, query.data, query.isError]);
|
|
4566
4742
|
return { ...query, messages };
|
|
4567
4743
|
}
|
|
4568
4744
|
function useInfiniteChannelMessages(options) {
|
|
4569
|
-
useScopeKey();
|
|
4745
|
+
const scopeKey = useScopeKey();
|
|
4570
4746
|
const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true, conversationsOnly = false, transcriptOnly = false } = options;
|
|
4571
4747
|
const isThread = !!parentMessageId;
|
|
4572
4748
|
const queryEnabled = enabled2 && !!channelPath;
|
|
4573
4749
|
const query = useInfiniteQuery({
|
|
4574
4750
|
queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : [], ...transcriptOnly ? ["transcript"] : []],
|
|
4575
4751
|
queryFn: async ({ pageParam }) => {
|
|
4576
|
-
|
|
4752
|
+
const page = await fetchChannelMessagesPage(channelPath, {
|
|
4577
4753
|
parentMessageId,
|
|
4578
4754
|
limit,
|
|
4579
4755
|
conversationsOnly,
|
|
@@ -4581,6 +4757,7 @@ function useInfiniteChannelMessages(options) {
|
|
|
4581
4757
|
before_seq: pageParam?.before_seq,
|
|
4582
4758
|
after_seq: pageParam?.after_seq
|
|
4583
4759
|
});
|
|
4760
|
+
return transcriptOnly && page.messages.length >= limit ? { ...page, olderBefore: page.messages[0]?.seq } : page;
|
|
4584
4761
|
},
|
|
4585
4762
|
initialPageParam: void 0,
|
|
4586
4763
|
getPreviousPageParam: (lastPage) => {
|
|
@@ -4590,6 +4767,7 @@ function useInfiniteChannelMessages(options) {
|
|
|
4590
4767
|
return maxSeq == null ? void 0 : { after_seq: maxSeq };
|
|
4591
4768
|
},
|
|
4592
4769
|
getNextPageParam: (firstPage) => {
|
|
4770
|
+
if (transcriptOnly) return firstPage.olderBefore == null ? void 0 : { before_seq: firstPage.olderBefore };
|
|
4593
4771
|
if (firstPage.messages.length < limit) return void 0;
|
|
4594
4772
|
const minSeq = firstPage.messages[0]?.seq;
|
|
4595
4773
|
return minSeq == null ? void 0 : { before_seq: minSeq };
|
|
@@ -4615,8 +4793,10 @@ function useInfiniteChannelMessages(options) {
|
|
|
4615
4793
|
const sc = [];
|
|
4616
4794
|
if (!query.data?.pages) return { messageCards: mc, siblingCards: sc };
|
|
4617
4795
|
const seenCards = /* @__PURE__ */ new Set();
|
|
4618
|
-
for (const page of query.data.pages) {
|
|
4796
|
+
for (const [index, page] of query.data.pages.entries()) {
|
|
4797
|
+
const pagePaths = transcriptOnly && index > 0 ? new Set(page.messages.map((message) => message.path)) : null;
|
|
4619
4798
|
for (const [path, cards] of page.messageCards) {
|
|
4799
|
+
if (pagePaths && !pagePaths.has(path)) continue;
|
|
4620
4800
|
for (const card of cards) {
|
|
4621
4801
|
if (seenCards.has(card.id)) continue;
|
|
4622
4802
|
seenCards.add(card.id);
|
|
@@ -4625,6 +4805,7 @@ function useInfiniteChannelMessages(options) {
|
|
|
4625
4805
|
mc.set(path, existing);
|
|
4626
4806
|
}
|
|
4627
4807
|
}
|
|
4808
|
+
if (transcriptOnly && index > 0) continue;
|
|
4628
4809
|
for (const card of page.siblingCards) {
|
|
4629
4810
|
if (seenCards.has(card.id)) continue;
|
|
4630
4811
|
seenCards.add(card.id);
|
|
@@ -4632,21 +4813,22 @@ function useInfiniteChannelMessages(options) {
|
|
|
4632
4813
|
}
|
|
4633
4814
|
}
|
|
4634
4815
|
return { messageCards: mc, siblingCards: sc };
|
|
4635
|
-
}, [query.data?.pages]);
|
|
4816
|
+
}, [query.data?.pages, transcriptOnly]);
|
|
4636
4817
|
const qc = useQueryClient();
|
|
4637
4818
|
const debounceRef = useRef(null);
|
|
4638
4819
|
const stableKey = useMemo(
|
|
4639
4820
|
() => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : [], ...transcriptOnly ? ["transcript"] : []],
|
|
4640
|
-
[channelPath, parentMessageId, limit, conversationsOnly, transcriptOnly]
|
|
4821
|
+
[channelPath, parentMessageId, limit, conversationsOnly, transcriptOnly, scopeKey]
|
|
4641
4822
|
);
|
|
4642
4823
|
useEffect(() => {
|
|
4643
4824
|
if (!realtime || !channelPath || !queryEnabled) return;
|
|
4825
|
+
if (transcriptOnly) return watchChannelTranscript(qc, stableKey, channelPath, limit);
|
|
4644
4826
|
const reload = () => void refreshQuery(qc, stableKey, { exact: true });
|
|
4645
4827
|
let tailRunning = false;
|
|
4646
4828
|
let tailAgain = false;
|
|
4647
4829
|
let disposed = false;
|
|
4648
4830
|
const tailOnce = async () => {
|
|
4649
|
-
if (conversationsOnly
|
|
4831
|
+
if (conversationsOnly) {
|
|
4650
4832
|
reload();
|
|
4651
4833
|
return;
|
|
4652
4834
|
}
|
|
@@ -4740,7 +4922,7 @@ function useInfiniteChannelMessages(options) {
|
|
|
4740
4922
|
void tail();
|
|
4741
4923
|
}, 500);
|
|
4742
4924
|
},
|
|
4743
|
-
(data) =>
|
|
4925
|
+
(data) => conversationsOnly && data?.item_type === "message" && (qc.getQueryData(stableKey)?.pages ?? []).some((page) => page.messages.some((root) => root.id === data.parent_id)) || channelMessageChange(
|
|
4744
4926
|
data,
|
|
4745
4927
|
channelPath,
|
|
4746
4928
|
parentMessageId,
|
|
@@ -4971,9 +5153,9 @@ function useCreate() {
|
|
|
4971
5153
|
return useMutation$1({
|
|
4972
5154
|
mutationFn: (params) => gatewayCall("create", params),
|
|
4973
5155
|
onSuccess: (_data, variables) => {
|
|
4974
|
-
const
|
|
4975
|
-
if (
|
|
4976
|
-
qc.invalidateQueries({ queryKey: vfsKeys.children(
|
|
5156
|
+
const parentPath2 = variables.parent_path;
|
|
5157
|
+
if (parentPath2) {
|
|
5158
|
+
qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
|
|
4977
5159
|
}
|
|
4978
5160
|
}
|
|
4979
5161
|
});
|
|
@@ -4988,9 +5170,9 @@ function useUpdate() {
|
|
|
4988
5170
|
qc.invalidateQueries({ queryKey: vfsKeys.item(path) });
|
|
4989
5171
|
const segments = path.split("/");
|
|
4990
5172
|
segments.pop();
|
|
4991
|
-
const
|
|
4992
|
-
if (
|
|
4993
|
-
qc.invalidateQueries({ queryKey: vfsKeys.children(
|
|
5173
|
+
const parentPath2 = segments.join("/");
|
|
5174
|
+
if (parentPath2) {
|
|
5175
|
+
qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
|
|
4994
5176
|
}
|
|
4995
5177
|
}
|
|
4996
5178
|
}
|
|
@@ -5026,9 +5208,9 @@ function useDelete() {
|
|
|
5026
5208
|
qc.removeQueries({ queryKey: vfsKeys.item(path) });
|
|
5027
5209
|
const segments = path.split("/");
|
|
5028
5210
|
segments.pop();
|
|
5029
|
-
const
|
|
5030
|
-
if (
|
|
5031
|
-
qc.invalidateQueries({ queryKey: vfsKeys.children(
|
|
5211
|
+
const parentPath2 = segments.join("/");
|
|
5212
|
+
if (parentPath2) {
|
|
5213
|
+
qc.invalidateQueries({ queryKey: vfsKeys.children(parentPath2) });
|
|
5032
5214
|
}
|
|
5033
5215
|
}
|
|
5034
5216
|
}
|