@jsb188/graphql 1.1.11 → 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 +205 -0
- package/cache/config.ts +65 -28
- package/cache/index.helpers.ts +96 -0
- package/cache/index.ts +364 -808
- package/cache/mounted-queries.ts +33 -0
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +107 -22
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +13 -39
- package/client/index.ts +4 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +122 -232
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +156 -0
- package/gql/fragments/aiChatFragments.ts +35 -11
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +76 -0
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +49 -21
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +12 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +574 -145
- package/gql/fragments/sheetFragments.ts +86 -424
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +32 -4
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +64 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +34 -4
- package/gql/mutations/audienceMutations.ts +58 -0
- package/gql/mutations/authMutations.ts +24 -28
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +10 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +389 -417
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +1 -1
- package/gql/mutations/workflowMutations.ts +94 -0
- package/gql/queries/agentMemoryQueries.ts +12 -2
- package/gql/queries/agentNoteQueries.ts +86 -0
- package/gql/queries/aiChatQueries.ts +63 -12
- package/gql/queries/audienceQueries.ts +104 -0
- package/gql/queries/authQueries.ts +20 -4
- package/gql/queries/billingQueries.ts +114 -9
- package/gql/queries/dataTableQueries.ts +43 -75
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +48 -64
- package/gql/queries/emailReplyReportQueries.ts +127 -0
- package/gql/queries/fieldDocQueries.ts +128 -98
- package/gql/queries/inboundContactQueries.ts +15 -4
- package/gql/queries/index.ts +5 -3
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +86 -12
- package/gql/queries/organizationQueries.ts +44 -12
- package/gql/queries/qrCodeQueries.ts +27 -0
- package/gql/queries/scheduleQueries.ts +401 -278
- package/gql/queries/sheetQueries.ts +94 -165
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +61 -12
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +920 -715
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +89 -0
- package/hooks/use-agentNote-qry.ts +162 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +57 -0
- package/hooks/use-aiChat-mtn.ts +104 -115
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +254 -387
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +170 -0
- package/hooks/use-audience-qry.helpers.ts +39 -0
- package/hooks/use-audience-qry.ts +245 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +69 -914
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +44 -174
- 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-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-library-qry.ts +233 -0
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +231 -348
- package/hooks/use-schedule-qry.ts +208 -139
- package/hooks/use-schedule-reactive.ts +218 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +88 -237
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +84 -23
- package/hooks/use-workflow-qry.ts +60 -61
- package/libs/ai-chat-link-events.ts +78 -0
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +45 -0
- package/libs/sheet-realtime-packet.ts +53 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/emailPreference.ts +69 -0
- package/loaders/rest.ts +12 -0
- package/package.json +77 -25
- package/schedule.d.ts +1183 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/types.d.ts +48 -25
- package/cache/index.test.ts +0 -881
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-managed-session.test.ts +0 -574
- package/client/request-no-store.test.ts +0 -157
- package/client/sse-ticket.test.ts +0 -26
- package/deno.lock +0 -170
- package/deno.test.json +0 -10
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/fragments/campaignFragments.ts +0 -277
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/mutations/campaignMutations.ts +0 -215
- package/gql/queries/agentDocQueries.ts +0 -120
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -127
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-campaign-mtn.ts +0 -377
- package/hooks/use-campaign-qry.ts +0 -257
- package/loaders/campaign.ts +0 -137
- package/tsconfig.json +0 -13
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
2
|
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
|
-
import {
|
|
4
|
-
deleteAgentMemoryMtn,
|
|
5
|
-
editAgentMemoryMtn,
|
|
6
|
-
} from '../gql/mutations/agentMemoryMutations.ts';
|
|
3
|
+
import { createAgentMemoryMtn, deleteAgentMemoryMtn, editAgentMemoryMtn } from '../gql/mutations/agentMemoryMutations.ts';
|
|
7
4
|
import { useMutation } from './index.ts';
|
|
8
5
|
|
|
6
|
+
/*
|
|
7
|
+
* Add an explicitly authored memory for an authorized organization, member, or contact.
|
|
8
|
+
*/
|
|
9
|
+
export function useCreateAgentMemory(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
10
|
+
const { onCompleted, ...rest } = params;
|
|
11
|
+
const [createAgentMemory, values, handlers] = useMutation(createAgentMemoryMtn, {
|
|
12
|
+
openModalPopUp,
|
|
13
|
+
onCompleted: (data, error, variables) => onCompleted?.(data?.createAgentMemory, error, variables),
|
|
14
|
+
...rest,
|
|
15
|
+
});
|
|
16
|
+
return { createAgentMemory, ...values, ...handlers };
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
/**
|
|
10
20
|
* Edit one agent memory: its wording, its permanent flag, or its status.
|
|
11
21
|
*
|
|
@@ -14,24 +24,18 @@ import { useMutation } from './index.ts';
|
|
|
14
24
|
* makes rather than something the assistant can do to itself.
|
|
15
25
|
*/
|
|
16
26
|
|
|
17
|
-
export function useEditAgentMemory(
|
|
18
|
-
params: UseMutationParams = {},
|
|
19
|
-
openModalPopUp?: OpenModalPopUpFn,
|
|
20
|
-
) {
|
|
27
|
+
export function useEditAgentMemory(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
21
28
|
const { onCompleted, ...rest } = params;
|
|
22
29
|
|
|
23
|
-
const [editAgentMemory, mtnValues, mtnHandlers] = useMutation(
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
onCompleted: (data, error, variables) => {
|
|
28
|
-
const updatedAgentMemory = data?.editAgentMemory;
|
|
30
|
+
const [editAgentMemory, mtnValues, mtnHandlers] = useMutation(editAgentMemoryMtn, {
|
|
31
|
+
openModalPopUp,
|
|
32
|
+
onCompleted: (data, error, variables) => {
|
|
33
|
+
const updatedAgentMemory = data?.editAgentMemory;
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
...rest,
|
|
35
|
+
onCompleted?.(updatedAgentMemory, error, variables);
|
|
33
36
|
},
|
|
34
|
-
|
|
37
|
+
...rest,
|
|
38
|
+
});
|
|
35
39
|
|
|
36
40
|
return {
|
|
37
41
|
editAgentMemory,
|
|
@@ -48,22 +52,16 @@ export function useEditAgentMemory(
|
|
|
48
52
|
* existed.
|
|
49
53
|
*/
|
|
50
54
|
|
|
51
|
-
export function useDeleteAgentMemory(
|
|
52
|
-
params: UseMutationParams = {},
|
|
53
|
-
openModalPopUp?: OpenModalPopUpFn,
|
|
54
|
-
) {
|
|
55
|
+
export function useDeleteAgentMemory(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
55
56
|
const { onCompleted, ...rest } = params;
|
|
56
57
|
|
|
57
|
-
const [deleteAgentMemory, mtnValues, mtnHandlers] = useMutation(
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
onCompleted: (data, error, variables) => {
|
|
62
|
-
onCompleted?.(data?.deleteAgentMemory, error, variables);
|
|
63
|
-
},
|
|
64
|
-
...rest,
|
|
58
|
+
const [deleteAgentMemory, mtnValues, mtnHandlers] = useMutation(deleteAgentMemoryMtn, {
|
|
59
|
+
openModalPopUp,
|
|
60
|
+
onCompleted: (data, error, variables) => {
|
|
61
|
+
onCompleted?.(data?.deleteAgentMemory, error, variables);
|
|
65
62
|
},
|
|
66
|
-
|
|
63
|
+
...rest,
|
|
64
|
+
});
|
|
67
65
|
|
|
68
66
|
return {
|
|
69
67
|
deleteAgentMemory,
|
|
@@ -2,9 +2,12 @@ import { useQuery } from './index.ts';
|
|
|
2
2
|
import type {
|
|
3
3
|
AgentMemoryScopeEnum,
|
|
4
4
|
AgentMemoryStatusEnum,
|
|
5
|
+
AgentMemorySurfaceEnum,
|
|
6
|
+
AgentMemoryGQL,
|
|
5
7
|
} from '@jsb188/mday/types/agentMemory.d.ts';
|
|
6
8
|
import { agentMemoriesQry } from '../gql/queries/agentMemoryQueries.ts';
|
|
7
9
|
import type { UseQueryParams } from '../types.d.ts';
|
|
10
|
+
import { useReactiveFragmentMap } from '../client/index.ts';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Constants
|
|
@@ -15,15 +18,17 @@ const AGENT_MEMORIES_LIMIT = 200;
|
|
|
15
18
|
/**
|
|
16
19
|
* Fetch the assistant's memories for one organization.
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* colleague's private rows regardless of what is requested here.
|
|
21
|
+
* Organization managers may inspect current members' organization-scoped
|
|
22
|
+
* ACCOUNT rows; other viewers receive only their own ACCOUNT memory.
|
|
21
23
|
*/
|
|
22
24
|
|
|
23
25
|
export function useAgentMemories(
|
|
24
26
|
variables: {
|
|
25
27
|
organizationId?: string | null;
|
|
26
28
|
scope?: AgentMemoryScopeEnum | null;
|
|
29
|
+
accountId?: string | null;
|
|
30
|
+
inboundContactId?: string | null;
|
|
31
|
+
surface?: AgentMemorySurfaceEnum | null;
|
|
27
32
|
status?: AgentMemoryStatusEnum | null;
|
|
28
33
|
},
|
|
29
34
|
params: UseQueryParams = {},
|
|
@@ -42,3 +47,10 @@ export function useAgentMemories(
|
|
|
42
47
|
...rest,
|
|
43
48
|
};
|
|
44
49
|
}
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* Observe memory changes using the same fragment identity emitted by the server.
|
|
53
|
+
*/
|
|
54
|
+
export function useReactiveAgentMemories(memories?: AgentMemoryGQL[] | null) {
|
|
55
|
+
return useReactiveFragmentMap(memories || null, 'agentMemoryFragment');
|
|
56
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { removeAgentNoteLinkMtn } from '../gql/mutations/aiChatLinkMutations.ts';
|
|
2
|
+
import type { UseMutationParams, UseMutationParamsExtra } from '@jsb188/graphql/types.d';
|
|
3
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
|
+
import {
|
|
6
|
+
deleteAgentNoteMtn,
|
|
7
|
+
markAgentNoteReadMtn,
|
|
8
|
+
refreshAgentNoteMtn,
|
|
9
|
+
updateAgentNoteMtn,
|
|
10
|
+
} from '../gql/mutations/agentNoteMutations.ts';
|
|
11
|
+
import { useMutation } from './index.ts';
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* Expose read marking for views whose explicit open action outlives detail mounts.
|
|
15
|
+
*/
|
|
16
|
+
export function useMarkAgentNoteReadMutation() {
|
|
17
|
+
const [markAgentNoteRead] = useMutation(markAgentNoteReadMtn);
|
|
18
|
+
return { markAgentNoteRead };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Stamp that a person opened one agent note, once per mounted (organization,
|
|
23
|
+
* note) pair. The realtime refetches of an open note never stamp a read, so a
|
|
24
|
+
* page left open does not keep the note from being archived. Best-effort:
|
|
25
|
+
* errors are ignored.
|
|
26
|
+
*/
|
|
27
|
+
export function useMarkAgentNoteRead(variables: { organizationId?: string | null; agentNoteId?: string | null }, skip = false) {
|
|
28
|
+
const { markAgentNoteRead } = useMarkAgentNoteReadMutation();
|
|
29
|
+
const markRef = useRef(markAgentNoteRead);
|
|
30
|
+
markRef.current = markAgentNoteRead;
|
|
31
|
+
const { organizationId, agentNoteId } = variables;
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (skip || !organizationId || !agentNoteId) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
void markRef.current({ variables: { organizationId, agentNoteId } }).catch(() => {
|
|
38
|
+
// The read stamp is best-effort; the note itself still loads
|
|
39
|
+
});
|
|
40
|
+
}, [skip, organizationId, agentNoteId]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Explicitly update flat pin/archive and source automatic-creation arguments. Restoration checks freshness;
|
|
45
|
+
* server events publish the accepted state and list membership.
|
|
46
|
+
*/
|
|
47
|
+
export function useUpdateAgentNote(params: UseMutationParamsExtra = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
48
|
+
const { onCompleted, ...rest } = params;
|
|
49
|
+
const [updateAgentNote, values, handlers] = useMutation(updateAgentNoteMtn, {
|
|
50
|
+
openModalPopUp,
|
|
51
|
+
onCompleted: (data, error, variables) => onCompleted?.(data?.updateAgentNote, error, variables),
|
|
52
|
+
...rest,
|
|
53
|
+
});
|
|
54
|
+
return { updateAgentNote, ...values, ...handlers };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
* Refresh the shared fragment cache with the latest saved note, even when no
|
|
59
|
+
* job is queued. Server events deliver any subsequent background refresh.
|
|
60
|
+
*/
|
|
61
|
+
export function useRefreshAgentNote(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
62
|
+
const { onCompleted, ...rest } = params;
|
|
63
|
+
const [refreshAgentNote, values, handlers] = useMutation(refreshAgentNoteMtn, {
|
|
64
|
+
openModalPopUp,
|
|
65
|
+
onCompleted: (data, error, variables) => onCompleted?.(data?.refreshAgentNote, error, variables),
|
|
66
|
+
...rest,
|
|
67
|
+
});
|
|
68
|
+
return { refreshAgentNote, ...values, ...handlers };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* Delete one note and its exclusively owned tables; shared tables remain standalone.
|
|
73
|
+
* INSIGHT deletion requires table-edit permission.
|
|
74
|
+
*/
|
|
75
|
+
export function useDeleteAgentNote(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
76
|
+
const { onCompleted, ...rest } = params;
|
|
77
|
+
const [deleteAgentNote, values, handlers] = useMutation(deleteAgentNoteMtn, {
|
|
78
|
+
openModalPopUp,
|
|
79
|
+
onCompleted: (data, error, variables) => onCompleted?.(data?.deleteAgentNote, error, variables),
|
|
80
|
+
...rest,
|
|
81
|
+
});
|
|
82
|
+
return { deleteAgentNote, ...values, ...handlers };
|
|
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
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
2
|
+
import type { AgentNoteBootstrapProgressGQL, AgentNoteGQL, AgentNoteKindEnum } from '@jsb188/mday/types/agentNote.d.ts';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { agentNoteBootstrapProgressQry, agentNoteQry, agentNotesQry, searchAgentNotesQry } from '../gql/queries/agentNoteQueries.ts';
|
|
5
|
+
import type { UseQueryParams } from '../types.d.ts';
|
|
6
|
+
import { useReactiveFragment, useReactiveFragmentMap } from './index.ts';
|
|
7
|
+
import { useMarkAgentNoteRead } from './use-agentNote-mtn.ts';
|
|
8
|
+
import { getAgentNoteResponseRevision, getVisibleAgentNote } from './use-agentNote-recovery.helpers.ts';
|
|
9
|
+
import { useRecoverableAgentNoteQuery } from './use-agentNote-recovery.ts';
|
|
10
|
+
|
|
11
|
+
export type AgentNotesVariables = {
|
|
12
|
+
organizationId?: string | null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SearchAgentNotesVariables = AgentNotesVariables & {
|
|
16
|
+
query: string;
|
|
17
|
+
includeArchived?: boolean | null;
|
|
18
|
+
kinds?: readonly AgentNoteKindEnum[] | null;
|
|
19
|
+
limit?: number | null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type AgentNoteVariables = {
|
|
23
|
+
organizationId?: string | null;
|
|
24
|
+
agentNoteId?: string | null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Read the safe initial-review status and recover missed status changes after reconnecting.
|
|
29
|
+
*/
|
|
30
|
+
export function useAgentNoteBootstrapProgress(variables: { organizationId?: string | null }, params: UseQueryParams = {}) {
|
|
31
|
+
const { data, ...rest } = useRecoverableAgentNoteQuery(agentNoteBootstrapProgressQry, variables.organizationId, {
|
|
32
|
+
...params,
|
|
33
|
+
variables,
|
|
34
|
+
skip: !variables.organizationId || !!params.skip,
|
|
35
|
+
revalidateOnMount: true,
|
|
36
|
+
});
|
|
37
|
+
const progress: AgentNoteBootstrapProgressGQL | null = rest.error ? null : data?.agentNoteBootstrapProgress || null;
|
|
38
|
+
return { progress, ...rest };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* Fetch every visible homepage note once per organization. Local groups and
|
|
43
|
+
* display limits share this collection and never change its query variables.
|
|
44
|
+
*/
|
|
45
|
+
export function useAgentNotes(variables: AgentNotesVariables, params: UseQueryParams = {}) {
|
|
46
|
+
const { data, ...rest } = useRecoverableAgentNoteQuery(agentNotesQry, variables.organizationId, {
|
|
47
|
+
...params,
|
|
48
|
+
variables: {
|
|
49
|
+
organizationId: variables.organizationId,
|
|
50
|
+
},
|
|
51
|
+
skip: !variables.organizationId || !!params.skip,
|
|
52
|
+
});
|
|
53
|
+
const agentNotes: AgentNoteGQL[] | null = useReactiveFragmentMap(
|
|
54
|
+
data?.agentNotes || null,
|
|
55
|
+
getFragmentBaseName(FRAGMENT_NAMES.agentNote),
|
|
56
|
+
rest.updatedCount,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const visibleAgentNotes = useMemo(() => agentNotes?.filter((note) => !note.__deleted && !note.archivedAt) ?? null, [agentNotes]);
|
|
60
|
+
return { agentNotes: visibleAgentNotes, ...rest };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Search active and archived notes without pagination. The accepted query
|
|
65
|
+
* identifies the result so a debounced input can keep older rows visible
|
|
66
|
+
* without presenting them as matches for a newer draft.
|
|
67
|
+
*/
|
|
68
|
+
export function useSearchAgentNotes(variables: SearchAgentNotesVariables, params: UseQueryParams = {}) {
|
|
69
|
+
const query = variables.query.trim();
|
|
70
|
+
const { data, ...rest } = useRecoverableAgentNoteQuery(searchAgentNotesQry, variables.organizationId, {
|
|
71
|
+
...params,
|
|
72
|
+
variables: {
|
|
73
|
+
organizationId: variables.organizationId,
|
|
74
|
+
query,
|
|
75
|
+
kinds: variables.kinds,
|
|
76
|
+
includeArchived: variables.includeArchived ?? true,
|
|
77
|
+
limit: variables.limit ?? 16,
|
|
78
|
+
},
|
|
79
|
+
skip: !variables.organizationId || !query || !!params.skip,
|
|
80
|
+
revalidateOnMount: true,
|
|
81
|
+
});
|
|
82
|
+
const revision = getAgentNoteResponseRevision({ ...data, error: rest.error }, 'searchAgentNotes');
|
|
83
|
+
const agentNotes: AgentNoteGQL[] | null = useReactiveFragmentMap(
|
|
84
|
+
revision === null ? null : data.searchAgentNotes.items,
|
|
85
|
+
getFragmentBaseName(FRAGMENT_NAMES.agentNote),
|
|
86
|
+
rest.updatedCount,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const visibleAgentNotes = useMemo(
|
|
90
|
+
() =>
|
|
91
|
+
agentNotes?.filter(
|
|
92
|
+
(note) =>
|
|
93
|
+
!note.__deleted &&
|
|
94
|
+
(variables.includeArchived !== false || !note.archivedAt) &&
|
|
95
|
+
(!variables.kinds?.length || variables.kinds.includes(note.kind)),
|
|
96
|
+
) ?? null,
|
|
97
|
+
[agentNotes, variables.includeArchived, variables.kinds],
|
|
98
|
+
);
|
|
99
|
+
return { agentNotes: visibleAgentNotes, acceptedQuery: revision === null ? null : query, revision, ...rest };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/*
|
|
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.
|
|
108
|
+
*/
|
|
109
|
+
export function useAgentNote(
|
|
110
|
+
variables: AgentNoteVariables,
|
|
111
|
+
params: UseQueryParams & { markRead?: boolean; cacheFirst?: boolean } = {},
|
|
112
|
+
) {
|
|
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.
|
|
122
|
+
const useCachedNote = !!(
|
|
123
|
+
cacheFirst &&
|
|
124
|
+
reactiveNote &&
|
|
125
|
+
(reactiveNote.__deleted || (reactiveNote.body !== undefined && Array.isArray(reactiveNote.links)))
|
|
126
|
+
);
|
|
127
|
+
// Preserve hook order while skipping the automatic request for cached details, missing IDs, or caller skip.
|
|
128
|
+
const { data, ...rest } = useRecoverableAgentNoteQuery(agentNoteQry, organizationId, {
|
|
129
|
+
...queryParams,
|
|
130
|
+
variables,
|
|
131
|
+
skip: skip || useCachedNote,
|
|
132
|
+
});
|
|
133
|
+
useMarkAgentNoteRead(variables, skip || !markRead);
|
|
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;
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
...rest,
|
|
140
|
+
agentNote: skip
|
|
141
|
+
? null
|
|
142
|
+
: getVisibleAgentNote(useCachedNote ? { agentNote: reactiveNote } : data, reactiveNote || queryNote, rest.error),
|
|
143
|
+
loading: useCachedNote ? false : rest.loading,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
* Observe the shared note identity, including full details previously loaded by another view.
|
|
149
|
+
*/
|
|
150
|
+
export function useReactiveAgentNoteFragment(agentNoteId?: string | null, currentData?: AgentNoteGQL | null, queryCount?: number) {
|
|
151
|
+
const note: AgentNoteGQL | null = useReactiveFragment(
|
|
152
|
+
currentData || null,
|
|
153
|
+
agentNoteId ? [makeFragmentKey(FRAGMENT_NAMES.agentNote, agentNoteId)] : [],
|
|
154
|
+
queryCount,
|
|
155
|
+
);
|
|
156
|
+
return note?.id === agentNoteId ? note : null;
|
|
157
|
+
}
|
|
158
|
+
|
|
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));
|
|
162
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type AgentNoteQueryName = 'agentNote' | 'agentNotes' | 'searchAgentNotes';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* The note resolver reports missing and unreadable notes with the same 404.
|
|
5
|
+
* Preserve that privacy boundary without treating other errors as absence.
|
|
6
|
+
* Server formatting may encode the error code numerically.
|
|
7
|
+
*/
|
|
8
|
+
export function isAgentNoteMissingError(error: unknown): boolean {
|
|
9
|
+
if (!error || typeof error !== 'object') return false;
|
|
10
|
+
const value = error as { errorCode?: unknown; statusCode?: unknown };
|
|
11
|
+
return String(value.errorCode) === '20232' && value.statusCode === 404;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* A retained fragment cannot resurrect a detail that the current authorized
|
|
16
|
+
* read declared missing, including the resolver's exact typed 404 result.
|
|
17
|
+
*/
|
|
18
|
+
export function getVisibleAgentNote<T>(
|
|
19
|
+
data: { agentNote?: T | null } | null | undefined,
|
|
20
|
+
fragment: (T & { __deleted?: boolean }) | null,
|
|
21
|
+
error: unknown,
|
|
22
|
+
): T | null {
|
|
23
|
+
return !data || data.agentNote === null || fragment?.__deleted || isAgentNoteMissingError(error) ? null : fragment;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Accept only complete authorized note responses. A missing detail
|
|
28
|
+
* (agentNote: null), including the exact 20232/404 result, confirms absence.
|
|
29
|
+
*/
|
|
30
|
+
export function agentNoteRecoveryReadSucceeded(result: unknown, queryName: AgentNoteQueryName): boolean {
|
|
31
|
+
if (!result || typeof result !== 'object') return false;
|
|
32
|
+
const response = result as Record<string, unknown>;
|
|
33
|
+
const search = response.searchAgentNotes as { items?: unknown; revision?: unknown } | null | undefined;
|
|
34
|
+
const validSearch =
|
|
35
|
+
queryName !== 'searchAgentNotes' ||
|
|
36
|
+
(Array.isArray(search?.items) && typeof search.revision === 'string' && /^\d+$/.test(search.revision));
|
|
37
|
+
const missingDetail = queryName === 'agentNote' && response.agentNote === null && isAgentNoteMissingError(response.error);
|
|
38
|
+
return (
|
|
39
|
+
validSearch &&
|
|
40
|
+
(!response.error || missingDetail) &&
|
|
41
|
+
!response.aborted &&
|
|
42
|
+
!response.skipped &&
|
|
43
|
+
!response.__clientResultRejected &&
|
|
44
|
+
Object.hasOwn(response, queryName)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Read a revision only when the same successful response contains the search
|
|
50
|
+
* items. A separate revision request cannot certify another content snapshot.
|
|
51
|
+
*/
|
|
52
|
+
export function getAgentNoteResponseRevision(result: unknown, queryName: AgentNoteQueryName): string | null {
|
|
53
|
+
if (queryName !== 'searchAgentNotes' || !agentNoteRecoveryReadSucceeded(result, queryName)) return null;
|
|
54
|
+
const snapshot = (result as { searchAgentNotes?: { items?: unknown; revision?: unknown } }).searchAgentNotes;
|
|
55
|
+
return Array.isArray(snapshot?.items) && typeof snapshot.revision === 'string' && /^\d+$/.test(snapshot.revision)
|
|
56
|
+
? snapshot.revision
|
|
57
|
+
: null;
|
|
58
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getAuthToken, getManagedAccessTokenBinding, managedAccessTokensShareBinding } from '@jsb188/app/utils/api.ts';
|
|
2
|
+
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
3
|
+
import { useCurrentAccount } from '@jsb188/react/states';
|
|
4
|
+
import { useLayoutEffect, useMemo, useRef } from 'react';
|
|
5
|
+
import type { GraphQLQueryOptions } from '../types.d.ts';
|
|
6
|
+
import { useQuery } from './index.ts';
|
|
7
|
+
|
|
8
|
+
/* Allow transparent token renewal only within the same authenticated session. */
|
|
9
|
+
function sameAuthenticationContext(initialToken: string | null, currentToken: string | null) {
|
|
10
|
+
return (
|
|
11
|
+
initialToken === currentToken || !!(initialToken && currentToken && managedAccessTokensShareBinding(initialToken, currentToken))
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/*
|
|
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
|
+
*/
|
|
21
|
+
export function useRecoverableAgentNoteQuery(query: any, organizationId: string | null | undefined, options: GraphQLQueryOptions) {
|
|
22
|
+
const { account } = useCurrentAccount();
|
|
23
|
+
const authToken = options.authToken || getAuthToken();
|
|
24
|
+
const session = authToken ? getManagedAccessTokenBinding(authToken) : null;
|
|
25
|
+
const scopeKey = JSON.stringify([account?.id, organizationId, session || authToken]);
|
|
26
|
+
const queryName = query.definitions[0].name.value;
|
|
27
|
+
const queryKey = `#${queryName}:${makeGraphQLVariablesKey(options.variables)}`;
|
|
28
|
+
const current = useRef({ scopeKey, queryKey, active: !options.skip });
|
|
29
|
+
const requestScope = useMemo(() => ({ active: false }), [scopeKey, queryKey, options.skip]);
|
|
30
|
+
|
|
31
|
+
/* Publish only committed scope changes to pending network-response guards. */
|
|
32
|
+
useLayoutEffect(() => {
|
|
33
|
+
current.current = { scopeKey, queryKey, active: !options.skip };
|
|
34
|
+
requestScope.active = !options.skip;
|
|
35
|
+
return () => {
|
|
36
|
+
current.current.active = false;
|
|
37
|
+
requestScope.active = false;
|
|
38
|
+
};
|
|
39
|
+
}, [scopeKey, queryKey, options.skip, requestScope]);
|
|
40
|
+
|
|
41
|
+
/* Reject a late result before the shared GraphQL client normalizes it. */
|
|
42
|
+
const isCurrent = () =>
|
|
43
|
+
requestScope.active &&
|
|
44
|
+
current.current.active &&
|
|
45
|
+
current.current.scopeKey === scopeKey &&
|
|
46
|
+
current.current.queryKey === queryKey &&
|
|
47
|
+
sameAuthenticationContext(authToken, options.authToken || getAuthToken());
|
|
48
|
+
const result = useQuery(query, {
|
|
49
|
+
...options,
|
|
50
|
+
requestTimeoutMs: 30_000,
|
|
51
|
+
rejectInvalidatedResults: true,
|
|
52
|
+
shouldAcceptResult: (data, variables) =>
|
|
53
|
+
isCurrent() && (!options.shouldAcceptResult || options.shouldAcceptResult(data, variables)),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return { ...result, data: !options.skip && result.queryKey === queryKey ? result.data : null };
|
|
57
|
+
}
|