@jsb188/graphql 1.1.12 → 1.1.13
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/LICENSE +21 -0
- package/audience.d.ts +14 -152
- package/cache/config.ts +35 -32
- package/cache/index.helpers.ts +1 -1
- package/cache/index.ts +73 -44
- package/cache/mounted-queries.ts +33 -0
- package/cache/persist.ts +10 -4
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- package/client/draft-persistence.ts +10 -39
- package/client/index.ts +2 -1
- package/client/request.ts +9 -34
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentNoteFragments.ts +8 -2
- package/gql/fragments/aiChatFragments.ts +0 -2
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +1 -66
- package/gql/fragments/emailFragments.ts +27 -4
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/inboundContactFragments.ts +1 -1
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/organizationFragments.ts +4 -2
- package/gql/fragments/scheduleFragments.ts +241 -324
- package/gql/fragments/sheetFragments.ts +4 -53
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +20 -4
- package/gql/mutations/agentNoteMutations.ts +2 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +4 -6
- package/gql/mutations/audienceMutations.ts +0 -13
- package/gql/mutations/authMutations.ts +12 -60
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/index.ts +3 -1
- package/gql/mutations/organizationMutations.ts +2 -2
- package/gql/mutations/scheduleMutations.ts +61 -787
- package/gql/mutations/storageMutations.ts +1 -0
- package/gql/mutations/workflowMutations.ts +76 -0
- package/gql/queries/agentMemoryQueries.ts +6 -2
- package/gql/queries/agentNoteQueries.ts +26 -29
- package/gql/queries/aiChatQueries.ts +39 -40
- package/gql/queries/audienceQueries.ts +31 -55
- package/gql/queries/authQueries.ts +16 -6
- package/gql/queries/billingQueries.ts +26 -10
- package/gql/queries/dataTableQueries.ts +24 -15
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +39 -12
- package/gql/queries/emailReplyReportQueries.ts +60 -9
- package/gql/queries/fieldDocQueries.ts +36 -14
- package/gql/queries/inboundContactQueries.ts +11 -4
- package/gql/queries/index.ts +2 -2
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +31 -12
- package/gql/queries/organizationQueries.ts +31 -12
- package/gql/queries/qrCodeQueries.ts +11 -4
- package/gql/queries/scheduleQueries.ts +252 -505
- package/gql/queries/sheetQueries.ts +36 -14
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +53 -10
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.ts +79 -52
- package/hooks/use-agentNote-mtn.ts +7 -0
- package/hooks/use-agentNote-qry.ts +30 -58
- package/hooks/use-agentNote-recovery.ts +6 -21
- package/hooks/use-aiChat-mtn.ts +9 -4
- package/hooks/use-aiChat-qry.ts +28 -7
- package/hooks/use-audience-mtn.ts +0 -24
- package/hooks/use-audience-qry.helpers.ts +0 -24
- package/hooks/use-audience-qry.ts +1 -86
- package/hooks/use-dataTable-mtn.ts +3 -3
- package/hooks/use-dataTable-qry.ts +7 -2
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +1 -1
- package/hooks/use-email-qry.ts +18 -3
- package/hooks/use-emailOutreach-mtn.ts +211 -0
- package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
- package/hooks/use-emailOutreach-qry.ts +367 -0
- package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
- package/hooks/use-fieldDoc-qry.ts +1 -1
- package/hooks/use-library-qry.ts +233 -0
- package/hooks/use-qrCode-qry.ts +1 -1
- package/hooks/use-schedule-mtn.ts +10 -300
- package/hooks/use-schedule-qry.ts +168 -680
- package/hooks/use-schedule-reactive.ts +71 -339
- package/hooks/use-sheet-qry.ts +6 -1
- package/hooks/use-workflow-mtn.ts +45 -1
- package/hooks/use-workflow-qry.ts +22 -2
- package/libs/ai-chat-link-events.ts +78 -0
- package/libs/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +3 -3
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +3 -2
- package/libs/sheet-realtime-packet.ts +53 -0
- package/loaders/emailPreference.ts +18 -24
- package/package.json +44 -17
- package/schedule.d.ts +267 -874
- package/types.d.ts +3 -1
- package/cache/index.chat-activity.test.ts +0 -119
- package/cache/index.chat.test.ts +0 -92
- package/cache/index.regression.test.ts +0 -149
- package/cache/index.test.ts +0 -1209
- package/deno.lock +0 -187
- package/deno.test.json +0 -12
- package/gql/fragments/campaignFragments.ts +0 -566
- package/gql/mutations/campaignMutations.ts +0 -258
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -236
- package/hooks/index.helpers.test.ts +0 -50
- package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
- package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-audience-qry.helpers.test.ts +0 -80
- package/hooks/use-campaign-generation-recovery.ts +0 -53
- package/hooks/use-campaign-mtn.ts +0 -436
- package/hooks/use-campaign-qry.helpers.ts +0 -40
- package/hooks/use-campaign-qry.ts +0 -834
- package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
- package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
- package/hooks/use-publicFormEmail-mtn.ts +0 -27
- package/libs/fragment-recovery.test.ts +0 -326
- package/libs/fragment-recovery.ts +0 -325
- package/libs/orchestrator-realtime.helpers.test.ts +0 -229
- package/libs/orchestrator-realtime.helpers.ts +0 -317
- package/libs/orchestrator-realtime.ts +0 -433
- package/libs/request-cache-regression.test.ts +0 -122
- package/libs/request-managed-session.test.ts +0 -574
- package/libs/request-no-store.test.ts +0 -419
- package/libs/sheet-view-realtime-router.test.ts +0 -214
- package/libs/sse-ticket.test.ts +0 -26
- package/loaders/campaign.test.ts +0 -186
- package/loaders/campaign.ts +0 -110
- package/tests/agent-note-detail-cache.test.ts +0 -120
- package/tests/agent-note-search.test.ts +0 -444
- package/tsconfig.json +0 -13
package/hooks/index.ts
CHANGED
|
@@ -27,7 +27,9 @@ import {
|
|
|
27
27
|
loadFragment,
|
|
28
28
|
removeStaleCache,
|
|
29
29
|
} from '../cache/index.ts';
|
|
30
|
+
import { releaseMountedQueryKey, retainMountedQueryKey } from '../cache/mounted-queries.ts';
|
|
30
31
|
import { beginOptimisticUITransaction } from '../cache/optimistic-ui.ts';
|
|
32
|
+
import { getRealtimeLiveSince } from '../cache/realtime-live.ts';
|
|
31
33
|
import { graphqlRequest } from '../client/request.ts';
|
|
32
34
|
import { EAGER_QUERY_MAP } from '../gql/eagerQueryMap.ts';
|
|
33
35
|
import type {
|
|
@@ -185,6 +187,8 @@ type QueryObserverEventObj = {
|
|
|
185
187
|
target?: QueryResetTarget | null;
|
|
186
188
|
forceRefetch: boolean;
|
|
187
189
|
resetOnly: boolean;
|
|
190
|
+
// A reset-only event caused by this tab's own request: refetch instead of showing the notice
|
|
191
|
+
selfRefresh?: boolean;
|
|
188
192
|
};
|
|
189
193
|
|
|
190
194
|
const QUERY_OBSERVER_LISTENERS = new Set<(event: QueryObserverEventObj) => void>();
|
|
@@ -232,11 +236,15 @@ function synchronizeQueryRuntimeEpoch() {
|
|
|
232
236
|
* Check whether one query's cached data is older than its freshness window
|
|
233
237
|
* (options.persistTime, falling back to the query's expire time). Data that
|
|
234
238
|
* never came from the network in this session or persisted snapshot is
|
|
235
|
-
* always stale
|
|
239
|
+
* always stale, and so is data fetched before realtime delivery last resumed
|
|
240
|
+
* after a gap (it may have missed changes).
|
|
236
241
|
*/
|
|
237
242
|
|
|
238
243
|
function queryDataIsStale(queryName: string, queryKey: string, persistTime?: number): boolean {
|
|
239
|
-
|
|
244
|
+
const fetchedAt = getQueryLastFetchedAt(queryKey);
|
|
245
|
+
if (isQueryDataStale(queryName, fetchedAt, persistTime)) return true;
|
|
246
|
+
// persistTime: Infinity marks immutable data (log revisions); a gap cannot have changed it
|
|
247
|
+
return persistTime !== Infinity && fetchedAt !== undefined && fetchedAt < getRealtimeLiveSince();
|
|
240
248
|
}
|
|
241
249
|
|
|
242
250
|
/**
|
|
@@ -247,16 +255,21 @@ function makeQueryHookId() {
|
|
|
247
255
|
}
|
|
248
256
|
|
|
249
257
|
/**
|
|
250
|
-
*
|
|
258
|
+
* Preserve every selected root field from a successful operation's response, including additional roots and aliases.
|
|
251
259
|
*/
|
|
252
|
-
function getQueryDataFromAPIResult(
|
|
260
|
+
function getQueryDataFromAPIResult(query: any, apiResult: any) {
|
|
261
|
+
const operation = query.definitions.find((definition: any) => definition.kind === 'OperationDefinition');
|
|
262
|
+
const queryName = operation?.name?.value;
|
|
253
263
|
if (!apiResult || apiResult.aborted || apiResult.error || apiResult[queryName] === undefined) {
|
|
254
264
|
return null;
|
|
255
265
|
}
|
|
256
266
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
267
|
+
const data: Record<string, any> = {};
|
|
268
|
+
for (const selection of operation.selectionSet.selections) {
|
|
269
|
+
const name = selection.alias?.value || selection.name?.value;
|
|
270
|
+
if (name && apiResult[name] !== undefined) data[name] = apiResult[name];
|
|
271
|
+
}
|
|
272
|
+
return data;
|
|
260
273
|
}
|
|
261
274
|
|
|
262
275
|
/*
|
|
@@ -492,6 +505,7 @@ export function updateDataObservers(args: UpdateDataObserverArgs) {
|
|
|
492
505
|
target: args.queryTarget || null,
|
|
493
506
|
forceRefetch: !!args.forceRefetch,
|
|
494
507
|
resetOnly: !!args.resetOnly,
|
|
508
|
+
selfRefresh: !!args.selfRefresh,
|
|
495
509
|
};
|
|
496
510
|
|
|
497
511
|
const event = LAST_QUERY_OBSERVER_EVENT;
|
|
@@ -545,8 +559,11 @@ function queryObserverEventMatchesQuery(
|
|
|
545
559
|
return true;
|
|
546
560
|
}
|
|
547
561
|
|
|
548
|
-
|
|
549
|
-
|
|
562
|
+
const names = queryDefs.flatMap((definition: any) => [
|
|
563
|
+
definition.name.value,
|
|
564
|
+
...definition.selectionSet.selections.map((selection: any) => selection.alias?.value || selection.name?.value).filter(Boolean),
|
|
565
|
+
]);
|
|
566
|
+
return names.some((queryName: string) => {
|
|
550
567
|
const fullQueryKey = `#${queryName}:${variablesKey}`;
|
|
551
568
|
|
|
552
569
|
if (event.target) {
|
|
@@ -566,18 +583,19 @@ function queryObserverEventMatchesQuery(
|
|
|
566
583
|
}
|
|
567
584
|
|
|
568
585
|
/*
|
|
569
|
-
* Return the newest reset-only
|
|
586
|
+
* Return the newest reset-only event covering one exact query key, or null when there is none.
|
|
587
|
+
* Its eventSequence is the reset-only generation a result must acknowledge.
|
|
570
588
|
*/
|
|
571
|
-
function
|
|
572
|
-
let
|
|
589
|
+
function getLatestQueryResetOnlyEvent(query: any, variablesKey: string): QueryObserverEventObj | null {
|
|
590
|
+
let latestEvent: QueryObserverEventObj | null = null;
|
|
573
591
|
|
|
574
592
|
for (const event of QUERY_RESET_ONLY_EVENTS.values()) {
|
|
575
|
-
if (event.eventSequence >
|
|
576
|
-
|
|
593
|
+
if (event.eventSequence > (latestEvent?.eventSequence || 0) && queryObserverEventMatchesQuery(event, query, variablesKey, false)) {
|
|
594
|
+
latestEvent = event;
|
|
577
595
|
}
|
|
578
596
|
}
|
|
579
597
|
|
|
580
|
-
return
|
|
598
|
+
return latestEvent;
|
|
581
599
|
}
|
|
582
600
|
|
|
583
601
|
/*
|
|
@@ -656,9 +674,10 @@ export function useWatchQuery(query: any, variablesKey: string, lastUpdatedCount
|
|
|
656
674
|
refreshTimeActive: '', // This value resets when loading starts
|
|
657
675
|
});
|
|
658
676
|
|
|
659
|
-
const queryWatcher = useMemo<[number, boolean, string, string]>(() => {
|
|
660
|
-
const
|
|
661
|
-
const resetOnlyTime =
|
|
677
|
+
const queryWatcher = useMemo<[number, boolean, string, string, boolean]>(() => {
|
|
678
|
+
const latestResetOnlyEvent = getLatestQueryResetOnlyEvent(query, variablesKey);
|
|
679
|
+
const resetOnlyTime = latestResetOnlyEvent ? String(latestResetOnlyEvent.eventSequence) : '';
|
|
680
|
+
const resetOnlySelfRefresh = !!latestResetOnlyEvent?.selfRefresh;
|
|
662
681
|
|
|
663
682
|
if (qryObserver.name) {
|
|
664
683
|
const queryDefs = query.definitions.filter((d: any) => d.kind === 'OperationDefinition');
|
|
@@ -669,33 +688,21 @@ export function useWatchQuery(query: any, variablesKey: string, lastUpdatedCount
|
|
|
669
688
|
|
|
670
689
|
if (qryTriggerTime) {
|
|
671
690
|
clearQueryResetStatus(queryName, variablesKey);
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
const matchedQry = queryDefs.find((d: any) => {
|
|
678
|
-
const queryName = d.name.value;
|
|
679
|
-
const fullQueryKey = `#${queryName}:${variablesKey}`;
|
|
680
|
-
const queryNameKey = `#${queryName}:`;
|
|
681
|
-
|
|
682
|
-
if (qryObserver.target) {
|
|
683
|
-
return queryCacheKeyMatchesResetTarget(fullQueryKey, qryObserver.target);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
if (qryObserver.name.startsWith('^')) {
|
|
687
|
-
try {
|
|
688
|
-
return new RegExp(qryObserver.name).test(fullQueryKey);
|
|
689
|
-
} catch (_err) {
|
|
690
|
-
return false;
|
|
691
|
+
// Forced events already have a shared refresh sequence. A second, locally consumed
|
|
692
|
+
// timestamp would make another reader refetch again after that sequence completes.
|
|
693
|
+
if (!qryObserver.forceRefetch) {
|
|
694
|
+
console.dev(`... (1) Query [${queryName}:${variablesKey}] is being force refetched via observer.`);
|
|
695
|
+
return [lastUpdatedCount + 1, true, qryTriggerTime, resetOnlyTime, resetOnlySelfRefresh];
|
|
691
696
|
}
|
|
692
697
|
}
|
|
698
|
+
}
|
|
693
699
|
|
|
694
|
-
|
|
695
|
-
|
|
700
|
+
const matchedQry = queryDefs.find((definition: any) =>
|
|
701
|
+
queryObserverEventMatchesQuery(qryObserver, { definitions: [definition] }, variablesKey, false),
|
|
702
|
+
);
|
|
696
703
|
|
|
697
704
|
if (!matchedQry) {
|
|
698
|
-
return [lastUpdatedCount, false, '', resetOnlyTime];
|
|
705
|
+
return [lastUpdatedCount, false, '', resetOnlyTime, resetOnlySelfRefresh];
|
|
699
706
|
}
|
|
700
707
|
|
|
701
708
|
const matchedQueryName = matchedQry.name.value;
|
|
@@ -710,10 +717,10 @@ export function useWatchQuery(query: any, variablesKey: string, lastUpdatedCount
|
|
|
710
717
|
console.dev(`... (2) Query [${matchedQueryId}] is being force refetched via observer.`);
|
|
711
718
|
}
|
|
712
719
|
|
|
713
|
-
return [newUpdatedCount, forceRefetch, '', resetOnlyTime];
|
|
720
|
+
return [newUpdatedCount, forceRefetch, '', resetOnlyTime, resetOnlySelfRefresh];
|
|
714
721
|
}
|
|
715
722
|
|
|
716
|
-
return [lastUpdatedCount, false, '', resetOnlyTime];
|
|
723
|
+
return [lastUpdatedCount, false, '', resetOnlyTime, resetOnlySelfRefresh];
|
|
717
724
|
}, [lastUpdatedCount, qryObserver, query, variablesKey]);
|
|
718
725
|
|
|
719
726
|
useEffect(() => {
|
|
@@ -745,6 +752,8 @@ export function useWatchQuery(query: any, variablesKey: string, lastUpdatedCount
|
|
|
745
752
|
updatedCount: queryWatcher[0],
|
|
746
753
|
forceRefetch: queryWatcher[1],
|
|
747
754
|
resetOnlyTime: queryWatcher[3],
|
|
755
|
+
// The newest reset-only event was caused by this tab's own request
|
|
756
|
+
resetOnlySelfRefresh: queryWatcher[4],
|
|
748
757
|
qryReset,
|
|
749
758
|
};
|
|
750
759
|
}
|
|
@@ -1222,7 +1231,7 @@ export function prefetchQuery(
|
|
|
1222
1231
|
const variablesKey = makeGraphQLVariablesKey(variables);
|
|
1223
1232
|
const queryKey = `#${queryName}:${variablesKey}`;
|
|
1224
1233
|
const requestForceSequence = getLatestQueryForceRefreshSequence(query, variablesKey);
|
|
1225
|
-
const requestResetOnlySequence =
|
|
1234
|
+
const requestResetOnlySequence = getLatestQueryResetOnlyEvent(query, variablesKey)?.eventSequence || 0;
|
|
1226
1235
|
const resetOnlyPending = requestResetOnlySequence > (QUERY_RESET_ONLY_ACKNOWLEDGMENTS.get(queryKey) || 0);
|
|
1227
1236
|
|
|
1228
1237
|
// A complete cached result means there is nothing to warm
|
|
@@ -1262,7 +1271,7 @@ export function prefetchQuery(
|
|
|
1262
1271
|
return queryPromise
|
|
1263
1272
|
.then((apiResult) => {
|
|
1264
1273
|
if (!apiResult?.aborted) acknowledgeQueryForceRefresh(queryKey, requestForceSequence);
|
|
1265
|
-
if (requestResetOnlySequence && getQueryDataFromAPIResult(
|
|
1274
|
+
if (requestResetOnlySequence && getQueryDataFromAPIResult(query, apiResult)) {
|
|
1266
1275
|
acknowledgeQueryResetOnlySequence(queryKey, requestResetOnlySequence);
|
|
1267
1276
|
}
|
|
1268
1277
|
|
|
@@ -1537,9 +1546,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1537
1546
|
const screenIsFocused = useScreenIsFocusedValue();
|
|
1538
1547
|
const updateObservers = useUpdateObservers();
|
|
1539
1548
|
|
|
1540
|
-
//
|
|
1541
|
-
// Multiple queries can be chained using this hook,
|
|
1542
|
-
// but only the first query is used for tracking reactivity.
|
|
1549
|
+
// Track one operation and its shared request key; resets for any selected root also invalidate this operation.
|
|
1543
1550
|
const queryName = query.definitions?.[0]?.name?.value;
|
|
1544
1551
|
const queryKey = `#${queryName}:${variablesKey}`;
|
|
1545
1552
|
const activation = useRef<QueryActivation>({ queryKey: null, checked: false });
|
|
@@ -1553,6 +1560,8 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1553
1560
|
ownQueryObserverCount: 0,
|
|
1554
1561
|
reconnectedAt: null as number | null,
|
|
1555
1562
|
transientRetryAttemptCount: 0,
|
|
1563
|
+
// The newest reset-only generation of this hook's own key whose refetch failed; effects do not retry it
|
|
1564
|
+
failedResetOnly: { queryKey: '', sequence: 0 },
|
|
1556
1565
|
mounted: true,
|
|
1557
1566
|
init: false,
|
|
1558
1567
|
});
|
|
@@ -1586,6 +1595,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1586
1595
|
const {
|
|
1587
1596
|
updatedCount,
|
|
1588
1597
|
resetOnlyTime,
|
|
1598
|
+
resetOnlySelfRefresh,
|
|
1589
1599
|
qryReset: { triggerTime, refreshTime },
|
|
1590
1600
|
} = useWatchQuery(query, variablesKey, qryValues.lastUpdatedCount, qryValues.loading);
|
|
1591
1601
|
const { data: cachedQuerySnapshot, ready: queryCacheSnapshotReady } = useHydrationSafeQueryCacheSnapshot(query, variablesKey);
|
|
@@ -1598,10 +1608,18 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1598
1608
|
QUERY_RESET_ONLY_ACKNOWLEDGMENTS.get(queryKey) || 0,
|
|
1599
1609
|
);
|
|
1600
1610
|
const resetOnlyPending = resetOnlySequence > acknowledgedResetOnlySequence;
|
|
1611
|
+
// One automatic refetch per reset-only generation: after it failed, the effects below do not retry it
|
|
1612
|
+
// (a newer event, the notice, explicit refetches and other variables still refetch), so a failing request cannot loop.
|
|
1613
|
+
const failedResetOnly = tracker.current.failedResetOnly;
|
|
1614
|
+
const resetOnlyAutoRefetch =
|
|
1615
|
+
resetOnlyPending && (failedResetOnly.queryKey !== queryKey || resetOnlySequence > failedResetOnly.sequence);
|
|
1601
1616
|
// RESET_ONLY never replaces a displayed result: the cached pages are gone, but the
|
|
1602
1617
|
// mounted list holds until the user acts on its refresh notice (resetOnlyTime).
|
|
1603
1618
|
// Cold mounts and changed filters still fetch because they have no complete matching result.
|
|
1604
|
-
|
|
1619
|
+
// A reset caused by this tab's own request refetches at once, as if the user had clicked the notice;
|
|
1620
|
+
// after that attempt failed it falls back to the notice, like a failed click.
|
|
1621
|
+
const deferResetOnly =
|
|
1622
|
+
resetOnlyPending && (!resetOnlySelfRefresh || !resetOnlyAutoRefetch) && qryValuesMatchVariables && effectiveQueryDataIsComplete;
|
|
1605
1623
|
const forceRefreshPending =
|
|
1606
1624
|
getLatestQueryForceRefreshSequence(query, variablesKey) > (FORCE_QUERY_REFRESH.acknowledged.get(queryKey) || 0);
|
|
1607
1625
|
|
|
@@ -1629,7 +1647,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1629
1647
|
// Cold loads and explicit refreshes also satisfy this activation's entry check.
|
|
1630
1648
|
claimQueryActivation(activation.current, qryQueryKey);
|
|
1631
1649
|
const requestForceSequence = getLatestQueryForceRefreshSequence(query, qryVariablesKey);
|
|
1632
|
-
const requestResetOnlySequence =
|
|
1650
|
+
const requestResetOnlySequence = getLatestQueryResetOnlyEvent(query, qryVariablesKey)?.eventSequence || 0;
|
|
1633
1651
|
const requestResetOnlyTime = qryVariablesKey === variablesKey && requestResetOnlySequence ? String(requestResetOnlySequence) : '';
|
|
1634
1652
|
const pendingQuery = QRY_PROMISES.get(qryQueryKey);
|
|
1635
1653
|
|
|
@@ -1698,9 +1716,12 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1698
1716
|
|
|
1699
1717
|
acknowledgeQueryForceRefresh(qryQueryKey, pendingForceSequence);
|
|
1700
1718
|
const cachedResult = fetchCachedData(query, qryVariablesKey);
|
|
1701
|
-
const apiResultData = getQueryDataFromAPIResult(
|
|
1719
|
+
const apiResultData = getQueryDataFromAPIResult(query, apiResult);
|
|
1702
1720
|
const data = cachedResult || apiResultData;
|
|
1703
1721
|
const completedResetOnlyTime = apiResultData && !apiResult?.error ? pendingResetOnlyTime : '';
|
|
1722
|
+
if (apiResult?.error && pendingResetOnlyTime) {
|
|
1723
|
+
tracker.current.failedResetOnly = { queryKey: qryQueryKey, sequence: pendingResetOnlySequence };
|
|
1724
|
+
}
|
|
1704
1725
|
if (pendingResetOnlySequence && apiResultData && !apiResult?.error) {
|
|
1705
1726
|
acknowledgeQueryResetOnlySequence(qryQueryKey, pendingResetOnlySequence);
|
|
1706
1727
|
}
|
|
@@ -1817,6 +1838,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1817
1838
|
},
|
|
1818
1839
|
onError: (error: ServerErrorObj | null) => {
|
|
1819
1840
|
acknowledgeQueryForceRefresh(qryQueryKey, requestForceSequence);
|
|
1841
|
+
if (requestResetOnlyTime) tracker.current.failedResetOnly = { queryKey: qryQueryKey, sequence: requestResetOnlySequence };
|
|
1820
1842
|
if (tracker.current.abortCtrl === queryAbortController) {
|
|
1821
1843
|
tracker.current.activeQueryKey = null;
|
|
1822
1844
|
tracker.current.ownQueryObserverCount = 0;
|
|
@@ -1895,6 +1917,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1895
1917
|
// A rejected result must obey the same bounded attempt limit as a failed
|
|
1896
1918
|
// refresh. Later invalidations retain their own unacknowledged sequence.
|
|
1897
1919
|
acknowledgeQueryForceRefresh(qryQueryKey, requestForceSequence);
|
|
1920
|
+
if (requestResetOnlyTime) tracker.current.failedResetOnly = { queryKey: qryQueryKey, sequence: requestResetOnlySequence };
|
|
1898
1921
|
setQryValues((currentValues: GraphQLQueryValues) => ({
|
|
1899
1922
|
...currentValues,
|
|
1900
1923
|
loading: false,
|
|
@@ -1974,9 +1997,12 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
1974
1997
|
|
|
1975
1998
|
useEffect(() => {
|
|
1976
1999
|
tracker.current.mounted = true;
|
|
2000
|
+
// Skipped hooks and hooks without a cached result register too; realtime changes reach them only through this
|
|
2001
|
+
retainMountedQueryKey(queryKey);
|
|
1977
2002
|
|
|
1978
2003
|
return () => {
|
|
1979
2004
|
tracker.current.mounted = false;
|
|
2005
|
+
releaseMountedQueryKey(queryKey);
|
|
1980
2006
|
unsetQueryTracker(queryKey, tracker.current.unique);
|
|
1981
2007
|
};
|
|
1982
2008
|
}, [queryKey]);
|
|
@@ -2008,7 +2034,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
2008
2034
|
queryCacheSnapshotReady &&
|
|
2009
2035
|
!skip &&
|
|
2010
2036
|
((triggerTime && triggerTime !== qryValues.lastRefreshTriggerTime) ||
|
|
2011
|
-
|
|
2037
|
+
resetOnlyAutoRefetch ||
|
|
2012
2038
|
forceRefreshPending ||
|
|
2013
2039
|
updatedCount !== qryValues.lastUpdatedCount ||
|
|
2014
2040
|
variablesKey !== qryValuesVariablesKey ||
|
|
@@ -2049,7 +2075,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
2049
2075
|
tracker.current.reconnectedAt = lastFetchedAt || Date.now();
|
|
2050
2076
|
}
|
|
2051
2077
|
|
|
2052
|
-
if ((
|
|
2078
|
+
if ((resetOnlyAutoRefetch || forceRefreshPending || !!triggerTime) && !qryValues.loading) {
|
|
2053
2079
|
// doLog(query, 'forceRefetchhing query at: $0|' + variablesKey + skip + updatedCount);
|
|
2054
2080
|
doQuery();
|
|
2055
2081
|
// isTest && console.log('FORCE REFETCH AT:', query.definitions[0].name.value);
|
|
@@ -2080,6 +2106,7 @@ export function useQuery(query: any, options?: GraphQLQueryOptions): GraphQLQuer
|
|
|
2080
2106
|
qryValuesVariablesKey,
|
|
2081
2107
|
qryValues.loading,
|
|
2082
2108
|
resetOnlyPending,
|
|
2109
|
+
resetOnlyAutoRefetch,
|
|
2083
2110
|
forceRefreshPending,
|
|
2084
2111
|
skip,
|
|
2085
2112
|
updatedCount,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { removeAgentNoteLinkMtn } from '../gql/mutations/aiChatLinkMutations.ts';
|
|
1
2
|
import type { UseMutationParams, UseMutationParamsExtra } from '@jsb188/graphql/types.d';
|
|
2
3
|
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
4
|
import { useEffect, useRef } from 'react';
|
|
@@ -80,3 +81,9 @@ export function useDeleteAgentNote(params: UseMutationParams = {}, openModalPopU
|
|
|
80
81
|
});
|
|
81
82
|
return { deleteAgentNote, ...values, ...handlers };
|
|
82
83
|
}
|
|
84
|
+
|
|
85
|
+
/* Remove a removable note link and let the returned shared detail fragment update every note surface. */
|
|
86
|
+
export function useRemoveAgentNoteLink() {
|
|
87
|
+
const [removeAgentNoteLink, values, handlers] = useMutation(removeAgentNoteLinkMtn);
|
|
88
|
+
return { removeAgentNoteLink, ...values, ...handlers };
|
|
89
|
+
}
|
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
2
|
-
import type {
|
|
3
|
-
AgentNoteBootstrapProgressGQL,
|
|
4
|
-
AgentNoteGQL,
|
|
5
|
-
AgentNoteKindEnum,
|
|
6
|
-
CampaignTemplateAgentNoteFocusGQL,
|
|
7
|
-
} from '@jsb188/mday/types/agentNote.d.ts';
|
|
2
|
+
import type { AgentNoteBootstrapProgressGQL, AgentNoteGQL, AgentNoteKindEnum } from '@jsb188/mday/types/agentNote.d.ts';
|
|
8
3
|
import { useMemo } from 'react';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
agentNoteBootstrapProgressQry,
|
|
12
|
-
agentNoteQry,
|
|
13
|
-
agentNotesQry,
|
|
14
|
-
campaignTemplateAgentNoteFocusQry,
|
|
15
|
-
searchAgentNotesQry,
|
|
16
|
-
} from '../gql/queries/agentNoteQueries.ts';
|
|
4
|
+
import { agentNoteBootstrapProgressQry, agentNoteQry, agentNotesQry, searchAgentNotesQry } from '../gql/queries/agentNoteQueries.ts';
|
|
17
5
|
import type { UseQueryParams } from '../types.d.ts';
|
|
18
|
-
import {
|
|
6
|
+
import { useReactiveFragment, useReactiveFragmentMap } from './index.ts';
|
|
19
7
|
import { useMarkAgentNoteRead } from './use-agentNote-mtn.ts';
|
|
20
8
|
import { getAgentNoteResponseRevision, getVisibleAgentNote } from './use-agentNote-recovery.helpers.ts';
|
|
21
9
|
import { useRecoverableAgentNoteQuery } from './use-agentNote-recovery.ts';
|
|
@@ -36,11 +24,6 @@ export type AgentNoteVariables = {
|
|
|
36
24
|
agentNoteId?: string | null;
|
|
37
25
|
};
|
|
38
26
|
|
|
39
|
-
export type CampaignTemplateAgentNoteFocusVariables = {
|
|
40
|
-
organizationId?: string | null;
|
|
41
|
-
campaignTemplateId?: string | null;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
27
|
/*
|
|
45
28
|
* Read the safe initial-review status and recover missed status changes after reconnecting.
|
|
46
29
|
*/
|
|
@@ -117,42 +100,46 @@ export function useSearchAgentNotes(variables: SearchAgentNotesVariables, params
|
|
|
117
100
|
}
|
|
118
101
|
|
|
119
102
|
/*
|
|
120
|
-
*
|
|
121
|
-
* (markAgentNoteRead, once per mounted note);
|
|
122
|
-
* content without refetching or stamping another read.
|
|
123
|
-
*
|
|
124
|
-
*
|
|
103
|
+
* Reuse full reactive note details from cache and only query when they are absent.
|
|
104
|
+
* Opening a note stamps one read (markAgentNoteRead, once per mounted note);
|
|
105
|
+
* realtime fragments update its content without refetching or stamping another read.
|
|
106
|
+
* Views that own the read stamp pass markRead: false. cacheFirst: false explicitly
|
|
107
|
+
* keeps the query active even when full details are cached.
|
|
125
108
|
*/
|
|
126
109
|
export function useAgentNote(
|
|
127
110
|
variables: AgentNoteVariables,
|
|
128
111
|
params: UseQueryParams & { markRead?: boolean; cacheFirst?: boolean } = {},
|
|
129
112
|
) {
|
|
130
|
-
const { markRead = true, cacheFirst =
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
//
|
|
113
|
+
const { markRead = true, cacheFirst = true, ...queryParams } = params;
|
|
114
|
+
const { organizationId, agentNoteId } = variables;
|
|
115
|
+
const skip = !organizationId || !agentNoteId || !!params.skip;
|
|
116
|
+
// Read and observe the fragment first; a separate loadFragment() would duplicate this cache lookup.
|
|
117
|
+
const observedNote = useReactiveAgentNoteFragment(agentNoteId);
|
|
118
|
+
// An observer can retain its previous note until its effect runs after an ID change.
|
|
119
|
+
// Only the requested note in the requested organization may satisfy this read or skip its query.
|
|
120
|
+
const reactiveNote = observedNote?.id === agentNoteId && observedNote?.organizationId === organizationId ? observedNote : null;
|
|
121
|
+
// Homepage summaries omit body and links; only full details or a deletion satisfy the cache read.
|
|
136
122
|
const useCachedNote = !!(
|
|
137
123
|
cacheFirst &&
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
(cachedNote.__deleted || (cachedNote.body !== undefined && Array.isArray(cachedNote.links)))
|
|
124
|
+
reactiveNote &&
|
|
125
|
+
(reactiveNote.__deleted || (reactiveNote.body !== undefined && Array.isArray(reactiveNote.links)))
|
|
141
126
|
);
|
|
142
|
-
|
|
127
|
+
// Preserve hook order while skipping the automatic request for cached details, missing IDs, or caller skip.
|
|
128
|
+
const { data, ...rest } = useRecoverableAgentNoteQuery(agentNoteQry, organizationId, {
|
|
143
129
|
...queryParams,
|
|
144
130
|
variables,
|
|
145
131
|
skip: skip || useCachedNote,
|
|
146
132
|
});
|
|
147
133
|
useMarkAgentNoteRead(variables, skip || !markRead);
|
|
148
|
-
|
|
134
|
+
// Prefer the reactive cache, with a matching query result as fallback until the observer catches up.
|
|
135
|
+
const queryNote: AgentNoteGQL | null =
|
|
136
|
+
data?.agentNote && data.agentNote.id === agentNoteId && data.agentNote.organizationId === organizationId ? data.agentNote : null;
|
|
149
137
|
|
|
150
138
|
return {
|
|
151
139
|
...rest,
|
|
152
|
-
agentNote:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
: getVisibleAgentNote(useCachedNote ? { agentNote: cachedNote } : data, agentNote, rest.error),
|
|
140
|
+
agentNote: skip
|
|
141
|
+
? null
|
|
142
|
+
: getVisibleAgentNote(useCachedNote ? { agentNote: reactiveNote } : data, reactiveNote || queryNote, rest.error),
|
|
156
143
|
loading: useCachedNote ? false : rest.loading,
|
|
157
144
|
};
|
|
158
145
|
}
|
|
@@ -169,22 +156,7 @@ export function useReactiveAgentNoteFragment(agentNoteId?: string | null, curren
|
|
|
169
156
|
return note?.id === agentNoteId ? note : null;
|
|
170
157
|
}
|
|
171
158
|
|
|
172
|
-
/*
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
* (focus is null when none is set; existing campaigns keep their own). The
|
|
176
|
-
* server resets this query when the focus is set or cleared.
|
|
177
|
-
*/
|
|
178
|
-
export function useCampaignTemplateAgentNoteFocus(variables: CampaignTemplateAgentNoteFocusVariables, params: UseQueryParams = {}) {
|
|
179
|
-
const { data, ...rest } = useQuery(campaignTemplateAgentNoteFocusQry, {
|
|
180
|
-
...params,
|
|
181
|
-
variables,
|
|
182
|
-
skip: !variables.organizationId || !variables.campaignTemplateId || !!params.skip,
|
|
183
|
-
});
|
|
184
|
-
const campaignTemplateAgentNoteFocus: CampaignTemplateAgentNoteFocusGQL | null = data?.campaignTemplateAgentNoteFocus || null;
|
|
185
|
-
|
|
186
|
-
return {
|
|
187
|
-
campaignTemplateAgentNoteFocus,
|
|
188
|
-
...rest,
|
|
189
|
-
};
|
|
159
|
+
/* Observe cached note metadata for a list of identities without fetching note bodies or marking notes read. */
|
|
160
|
+
export function useReactiveAgentNoteFragmentMap(currentData: { id: string }[] | null) {
|
|
161
|
+
return useReactiveFragmentMap(currentData, getFragmentBaseName(FRAGMENT_NAMES.agentNote));
|
|
190
162
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getAuthToken, getManagedAccessTokenBinding, managedAccessTokensShareBinding } from '@jsb188/app/utils/api.ts';
|
|
2
2
|
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
3
|
-
import { useCurrentAccount
|
|
4
|
-
import {
|
|
3
|
+
import { useCurrentAccount } from '@jsb188/react/states';
|
|
4
|
+
import { useLayoutEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import type { GraphQLQueryOptions } from '../types.d.ts';
|
|
6
6
|
import { useQuery } from './index.ts';
|
|
7
7
|
|
|
@@ -13,14 +13,13 @@ function sameAuthenticationContext(initialToken: string | null, currentToken: st
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/*
|
|
16
|
-
* Guard note responses before normalization
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* Guard note responses before normalization. Collection invalidations coalesce
|
|
17
|
+
* through the shared query lifecycle; a request overtaken by an invalidation
|
|
18
|
+
* cannot normalize stale rows. Point reads share this fence so their late
|
|
19
|
+
* results cannot regress collection data.
|
|
20
20
|
*/
|
|
21
21
|
export function useRecoverableAgentNoteQuery(query: any, organizationId: string | null | undefined, options: GraphQLQueryOptions) {
|
|
22
22
|
const { account } = useCurrentAccount();
|
|
23
|
-
const generation = useRealtimeConnectionGenerationValue();
|
|
24
23
|
const authToken = options.authToken || getAuthToken();
|
|
25
24
|
const session = authToken ? getManagedAccessTokenBinding(authToken) : null;
|
|
26
25
|
const scopeKey = JSON.stringify([account?.id, organizationId, session || authToken]);
|
|
@@ -53,20 +52,6 @@ export function useRecoverableAgentNoteQuery(query: any, organizationId: string
|
|
|
53
52
|
shouldAcceptResult: (data, variables) =>
|
|
54
53
|
isCurrent() && (!options.shouldAcceptResult || options.shouldAcceptResult(data, variables)),
|
|
55
54
|
});
|
|
56
|
-
const previousConnection = useRef({ generation, requestScope, pending: false });
|
|
57
|
-
|
|
58
|
-
/* Retain one reconnect recovery until loading settles, scoped to this query activation. */
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
const previous = previousConnection.current;
|
|
61
|
-
const pending = previous.requestScope === requestScope && (previous.pending || previous.generation !== generation);
|
|
62
|
-
previousConnection.current = { generation, requestScope, pending: pending && isCurrent() };
|
|
63
|
-
if (!previousConnection.current.pending || result.loading !== false) return;
|
|
64
|
-
|
|
65
|
-
previousConnection.current.pending = false;
|
|
66
|
-
void result.refetch().catch(() => {
|
|
67
|
-
// Query state owns the load error; do not create an unhandled reconnect rejection.
|
|
68
|
-
});
|
|
69
|
-
}, [generation, requestScope, result.loading]);
|
|
70
55
|
|
|
71
56
|
return { ...result, data: !options.skip && result.queryKey === queryKey ? result.data : null };
|
|
72
57
|
}
|
package/hooks/use-aiChat-mtn.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setAIChatLinkHiddenMtn } from '../gql/mutations/aiChatLinkMutations.ts';
|
|
1
2
|
import { FRAGMENT_NAMES, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
2
3
|
import { type OpenModalPopUpFn, useOpenModalPopUp } from '@jsb188/react/states';
|
|
3
4
|
import { useCallback, useEffect, useRef } from 'react';
|
|
@@ -68,7 +69,6 @@ export function useEditAIChat(params: UseMutationParams = {}) {
|
|
|
68
69
|
fragmentKey,
|
|
69
70
|
{
|
|
70
71
|
summary: nextSummary,
|
|
71
|
-
userManagedSummary: true,
|
|
72
72
|
},
|
|
73
73
|
null,
|
|
74
74
|
false,
|
|
@@ -83,9 +83,8 @@ export function useEditAIChat(params: UseMutationParams = {}) {
|
|
|
83
83
|
(currentFragment: any) =>
|
|
84
84
|
currentFragment?.summary === nextSummary
|
|
85
85
|
? {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
86
|
+
summary: previousFragment.summary,
|
|
87
|
+
}
|
|
89
88
|
: {},
|
|
90
89
|
null,
|
|
91
90
|
false,
|
|
@@ -245,3 +244,9 @@ export function useDeleteAIChat(params: UseMutationParams = {}) {
|
|
|
245
244
|
...mtnHandlers,
|
|
246
245
|
};
|
|
247
246
|
}
|
|
247
|
+
|
|
248
|
+
/* Hide or restore only the current chat's membership row; server reactivity owns list reconciliation. */
|
|
249
|
+
export function useSetAIChatLinkHidden(params: UseMutationParamsExtra = {}) {
|
|
250
|
+
const [setAIChatLinkHidden, values, handlers] = useMutation(setAIChatLinkHiddenMtn, params);
|
|
251
|
+
return { setAIChatLinkHidden, ...values, ...handlers };
|
|
252
|
+
}
|
package/hooks/use-aiChat-qry.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cacheAIChatRunUpdate } from '../libs/ai-chat-run-realtime.ts';
|
|
2
|
+
import type { AIChatLink } from '@jsb188/mday/types/linkedEntity.d.ts';
|
|
2
3
|
import type { AIChatRunData } from '@jsb188/app/types/ai.d.ts';
|
|
3
4
|
import { mergeAIChatRuns } from '@jsb188/mday/utils/aiChatWork.ts';
|
|
4
5
|
import { upsertLocalAIChatMessage, mergeSSEPayloadToLocalAIChatMessages, mergeLocalAIChatMessages } from './use-aiChat-qry.helpers.ts';
|
|
@@ -9,7 +10,7 @@ import SSE from '@jsb188/sse';
|
|
|
9
10
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
11
|
import { loadFragment, resetQuery, updateQuery } from '../cache/index.ts';
|
|
11
12
|
import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '../client/index.ts';
|
|
12
|
-
import { aiChatMessagesQry, aiChatWorkMessagesQry, aiChatQry, aiChatsQry } from '../gql/queries/aiChatQueries.ts';
|
|
13
|
+
import { aiChatLinksQry, aiChatMessagesQry, aiChatWorkMessagesQry, aiChatQry, aiChatsQry } from '../gql/queries/aiChatQueries.ts';
|
|
13
14
|
import {
|
|
14
15
|
clearAIChatSubmission,
|
|
15
16
|
finishAIChatGeneration,
|
|
@@ -43,12 +44,9 @@ function getGeneratingFragmentId(sseData: PublishPayload) {
|
|
|
43
44
|
return finished ? null : key;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string | null, params: UseQueryParams = {}) {
|
|
51
|
-
const { data, ...rest } = useQuery(aiChatQry, {
|
|
47
|
+
/* Fetch transcript details independently from sidebar membership so link resets cannot replace streaming messages. */
|
|
48
|
+
function useAIChatQuery(aiChatId?: string | null, params: UseQueryParams = {}) {
|
|
49
|
+
return useQuery(aiChatQry, {
|
|
52
50
|
variables: {
|
|
53
51
|
aiChatId,
|
|
54
52
|
includeWork: false,
|
|
@@ -57,6 +55,13 @@ export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string |
|
|
|
57
55
|
persistTime: 20 * 60 * 1000,
|
|
58
56
|
...params,
|
|
59
57
|
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Fetch AI chat and stream subsequent message updates.
|
|
62
|
+
*/
|
|
63
|
+
export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string | null, params: UseQueryParams = {}) {
|
|
64
|
+
const { data, ...rest } = useAIChatQuery(aiChatId, params);
|
|
60
65
|
|
|
61
66
|
const { updateObservers, variablesKey } = rest;
|
|
62
67
|
const [session, setSession] = useState({
|
|
@@ -385,3 +390,19 @@ export function useReactiveAIChatMessageMap(messages: any[]) {
|
|
|
385
390
|
}
|
|
386
391
|
|
|
387
392
|
export { upsertLocalAIChatMessage } from './use-aiChat-qry.helpers.ts';
|
|
393
|
+
|
|
394
|
+
/* Fetch sidebar membership only for its mounted web-chat host and observe the canonical link fragments. */
|
|
395
|
+
export function useAIChatLinks(aiChatId?: string | null, params: UseQueryParams = {}) {
|
|
396
|
+
const { data, updatedCount, ...state } = useQuery(aiChatLinksQry, {
|
|
397
|
+
...params,
|
|
398
|
+
variables: { aiChatId },
|
|
399
|
+
skip: !aiChatId || params.skip,
|
|
400
|
+
persistTime: params.persistTime ?? 20 * 60 * 1000,
|
|
401
|
+
});
|
|
402
|
+
const links = useReactiveAIChatLinkFragmentMap(data?.aiChatLinks, updatedCount);
|
|
403
|
+
return { links: useMemo(() => (links || []).filter((link) => !link.hiddenAt), [links]), ...state };
|
|
404
|
+
}
|
|
405
|
+
/* Share normalized fragment keys between list queries and run-footer readers. */
|
|
406
|
+
export function useReactiveAIChatLinkFragmentMap(links?: AIChatLink[] | null, updatedCount?: number): AIChatLink[] | null {
|
|
407
|
+
return useReactiveFragmentMap(links || null, getFragmentBaseName(FRAGMENT_NAMES.aiChatLink), updatedCount);
|
|
408
|
+
}
|
|
@@ -168,27 +168,3 @@ export function useSetAudienceAddressSuppression(
|
|
|
168
168
|
...mtnHandlers,
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
/*
|
|
173
|
-
* Replace a draft campaign’s selected lists using its expected editor version.
|
|
174
|
-
*/
|
|
175
|
-
export function useSetCampaignAudience(
|
|
176
|
-
params: UseMutationParams = {},
|
|
177
|
-
openModalPopUp?: OpenModalPopUpFn,
|
|
178
|
-
) {
|
|
179
|
-
const { onCompleted, ...rest } = params;
|
|
180
|
-
const [setCampaignAudience, mtnValues, mtnHandlers, updateObservers] =
|
|
181
|
-
useMutation(documents.setCampaignAudienceMtn, {
|
|
182
|
-
openModalPopUp,
|
|
183
|
-
onCompleted: (data, error, variables) => {
|
|
184
|
-
onCompleted?.(data?.setCampaignAudience, error, variables);
|
|
185
|
-
},
|
|
186
|
-
...rest,
|
|
187
|
-
});
|
|
188
|
-
return {
|
|
189
|
-
setCampaignAudience,
|
|
190
|
-
updateObservers,
|
|
191
|
-
...mtnValues,
|
|
192
|
-
...mtnHandlers,
|
|
193
|
-
};
|
|
194
|
-
}
|