@jsb188/graphql 1.1.8 → 1.1.11

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.
Files changed (122) hide show
  1. package/cache/config.ts +66 -42
  2. package/cache/index.test.ts +881 -0
  3. package/cache/index.ts +1815 -979
  4. package/cache/persist.ts +721 -0
  5. package/cache/store.ts +437 -0
  6. package/client/data-table-realtime-subscriptions.test.ts +740 -0
  7. package/client/data-table-realtime-subscriptions.ts +955 -0
  8. package/client/data-table-realtime.test.ts +792 -0
  9. package/client/data-table-realtime.ts +1218 -0
  10. package/client/fragment-realtime-sequence.ts +52 -0
  11. package/client/index.ts +4 -2
  12. package/client/open-sheet.ts +137 -0
  13. package/client/request-managed-session.test.ts +574 -0
  14. package/client/request-no-store.test.ts +157 -0
  15. package/client/request.ts +973 -143
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +10 -0
  19. package/drafts/index.ts +149 -0
  20. package/drafts/store.ts +397 -0
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +1 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentDocFragments.ts +46 -0
  26. package/gql/fragments/agentMemoryFragments.ts +19 -0
  27. package/gql/fragments/aiChatFragments.ts +17 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +102 -0
  31. package/gql/fragments/emailFragments.ts +36 -0
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/inboundContactFragments.ts +15 -0
  34. package/gql/fragments/integrationFragments.ts +22 -0
  35. package/gql/fragments/logFragments.ts +33 -64
  36. package/gql/fragments/organizationFragments.ts +94 -21
  37. package/gql/fragments/scheduleFragments.ts +155 -0
  38. package/gql/fragments/sheetFragments.ts +675 -0
  39. package/gql/fragments/storageFragments.ts +21 -1
  40. package/gql/fragments/workflowFragments.ts +67 -0
  41. package/gql/mutations/accountMutations.ts +24 -4
  42. package/gql/mutations/agentDocMutations.ts +177 -0
  43. package/gql/mutations/agentMemoryMutations.ts +36 -0
  44. package/gql/mutations/aiChatMutations.ts +43 -3
  45. package/gql/mutations/authMutations.ts +160 -19
  46. package/gql/mutations/campaignMutations.ts +215 -0
  47. package/gql/mutations/dataTableMutations.ts +106 -0
  48. package/gql/mutations/fieldDocMutations.ts +24 -0
  49. package/gql/mutations/inboundContactMutations.ts +24 -0
  50. package/gql/mutations/index.ts +17 -8
  51. package/gql/mutations/integrationMutations.ts +25 -0
  52. package/gql/mutations/logMutations.ts +10 -19
  53. package/gql/mutations/organizationMutations.ts +160 -2
  54. package/gql/mutations/scheduleMutations.ts +423 -0
  55. package/gql/mutations/sheetMutations.ts +385 -0
  56. package/gql/mutations/storageMutations.ts +21 -2
  57. package/gql/mutations/workflowMutations.ts +42 -0
  58. package/gql/queries/agentDocQueries.ts +120 -0
  59. package/gql/queries/agentMemoryQueries.ts +22 -0
  60. package/gql/queries/aiChatQueries.ts +18 -2
  61. package/gql/queries/authQueries.ts +41 -0
  62. package/gql/queries/billingQueries.ts +24 -1
  63. package/gql/queries/campaignQueries.ts +127 -0
  64. package/gql/queries/dataTableQueries.ts +134 -0
  65. package/gql/queries/emailQueries.ts +96 -0
  66. package/gql/queries/fieldDocQueries.ts +158 -0
  67. package/gql/queries/inboundContactQueries.ts +40 -0
  68. package/gql/queries/index.ts +17 -6
  69. package/gql/queries/logQueries.ts +42 -32
  70. package/gql/queries/organizationQueries.ts +113 -8
  71. package/gql/queries/scheduleQueries.ts +315 -0
  72. package/gql/queries/sheetQueries.ts +383 -0
  73. package/gql/queries/storageQueries.ts +38 -0
  74. package/gql/queries/workflowQueries.ts +99 -0
  75. package/hooks/index.ts +2104 -860
  76. package/hooks/use-account-mtn.ts +91 -48
  77. package/hooks/use-agentDoc-mtn.ts +285 -0
  78. package/hooks/use-agentDoc-qry.ts +208 -0
  79. package/hooks/use-agentMemory-mtn.ts +73 -0
  80. package/hooks/use-agentMemory-qry.ts +44 -0
  81. package/hooks/use-aiChat-mtn.ts +248 -97
  82. package/hooks/use-aiChat-qry.ts +501 -191
  83. package/hooks/use-app-qry.ts +14 -11
  84. package/hooks/use-auth-mtn.ts +410 -256
  85. package/hooks/use-auth-qry.ts +51 -0
  86. package/hooks/use-campaign-mtn.ts +377 -0
  87. package/hooks/use-campaign-qry.ts +257 -0
  88. package/hooks/use-dataTable-mtn.ts +170 -0
  89. package/hooks/use-dataTable-qry.ts +996 -0
  90. package/hooks/use-email-qry.ts +227 -0
  91. package/hooks/use-fieldDoc-mtn.ts +50 -0
  92. package/hooks/use-fieldDoc-qry.ts +180 -0
  93. package/hooks/use-inboundContact-mtn.ts +34 -0
  94. package/hooks/use-inboundContact-qry.ts +96 -0
  95. package/hooks/use-integration-mtn.ts +77 -0
  96. package/hooks/use-integration-qry.ts +30 -0
  97. package/hooks/use-log-mtn.ts +77 -61
  98. package/hooks/use-log-qry.ts +99 -72
  99. package/hooks/use-organization-mtn.ts +409 -80
  100. package/hooks/use-organization-qry.ts +211 -92
  101. package/hooks/use-schedule-mtn.ts +416 -0
  102. package/hooks/use-schedule-qry.ts +157 -0
  103. package/hooks/use-sheet-mtn.ts +367 -0
  104. package/hooks/use-sheet-qry.ts +440 -0
  105. package/hooks/use-storage-mtn.ts +83 -42
  106. package/hooks/use-storage-qry.ts +104 -13
  107. package/hooks/use-workflow-mtn.ts +55 -0
  108. package/hooks/use-workflow-qry.ts +230 -0
  109. package/loaders/campaign.ts +137 -0
  110. package/package.json +94 -52
  111. package/sse.ts +158 -105
  112. package/tsconfig.json +13 -0
  113. package/types.d.ts +60 -29
  114. package/utils.ts +77 -50
  115. package/gql/fragments/actionFragments.ts +0 -16
  116. package/gql/fragments/productFragments.ts +0 -63
  117. package/gql/fragments/reportFragments.ts +0 -48
  118. package/gql/mutations/billingMutations.ts +0 -34
  119. package/gql/queries/productQueries.ts +0 -70
  120. package/gql/queries/reportQueries.ts +0 -66
  121. package/hooks/use-product-qry.ts +0 -109
  122. package/hooks/use-report-qry.ts +0 -69
@@ -0,0 +1,73 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import {
4
+ deleteAgentMemoryMtn,
5
+ editAgentMemoryMtn,
6
+ } from '../gql/mutations/agentMemoryMutations.ts';
7
+ import { useMutation } from './index.ts';
8
+
9
+ /**
10
+ * Edit one agent memory: its wording, its permanent flag, or its status.
11
+ *
12
+ * "permanent" and status promotion are available only here and never to an
13
+ * agent tool, so protecting a fact and promoting one stay decisions a person
14
+ * makes rather than something the assistant can do to itself.
15
+ */
16
+
17
+ export function useEditAgentMemory(
18
+ params: UseMutationParams = {},
19
+ openModalPopUp?: OpenModalPopUpFn,
20
+ ) {
21
+ const { onCompleted, ...rest } = params;
22
+
23
+ const [editAgentMemory, mtnValues, mtnHandlers] = useMutation(
24
+ editAgentMemoryMtn,
25
+ {
26
+ openModalPopUp,
27
+ onCompleted: (data, error, variables) => {
28
+ const updatedAgentMemory = data?.editAgentMemory;
29
+
30
+ onCompleted?.(updatedAgentMemory, error, variables);
31
+ },
32
+ ...rest,
33
+ },
34
+ );
35
+
36
+ return {
37
+ editAgentMemory,
38
+ ...mtnValues,
39
+ ...mtnHandlers,
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Delete one agent memory.
45
+ *
46
+ * There is no soft delete and no revision history by design, so this is
47
+ * irreversible; only the per-log provenance snapshot records that the fact ever
48
+ * existed.
49
+ */
50
+
51
+ export function useDeleteAgentMemory(
52
+ params: UseMutationParams = {},
53
+ openModalPopUp?: OpenModalPopUpFn,
54
+ ) {
55
+ const { onCompleted, ...rest } = params;
56
+
57
+ const [deleteAgentMemory, mtnValues, mtnHandlers] = useMutation(
58
+ deleteAgentMemoryMtn,
59
+ {
60
+ openModalPopUp,
61
+ onCompleted: (data, error, variables) => {
62
+ onCompleted?.(data?.deleteAgentMemory, error, variables);
63
+ },
64
+ ...rest,
65
+ },
66
+ );
67
+
68
+ return {
69
+ deleteAgentMemory,
70
+ ...mtnValues,
71
+ ...mtnHandlers,
72
+ };
73
+ }
@@ -0,0 +1,44 @@
1
+ import { useQuery } from './index.ts';
2
+ import type {
3
+ AgentMemoryScopeEnum,
4
+ AgentMemoryStatusEnum,
5
+ } from '@jsb188/mday/types/agentMemory.d.ts';
6
+ import { agentMemoriesQry } from '../gql/queries/agentMemoryQueries.ts';
7
+ import type { UseQueryParams } from '../types.d.ts';
8
+
9
+ /**
10
+ * Constants
11
+ */
12
+
13
+ const AGENT_MEMORIES_LIMIT = 200;
14
+
15
+ /**
16
+ * Fetch the assistant's memories for one organization.
17
+ *
18
+ * ACCOUNT-scope rows are filtered to the signed-in viewer by the server; that
19
+ * scope is memory belonging to one person, so this list can never show a
20
+ * colleague's private rows regardless of what is requested here.
21
+ */
22
+
23
+ export function useAgentMemories(
24
+ variables: {
25
+ organizationId?: string | null;
26
+ scope?: AgentMemoryScopeEnum | null;
27
+ status?: AgentMemoryStatusEnum | null;
28
+ },
29
+ params: UseQueryParams = {},
30
+ ) {
31
+ const { data, ...rest } = useQuery(agentMemoriesQry, {
32
+ ...params,
33
+ variables: {
34
+ ...variables,
35
+ limit: AGENT_MEMORIES_LIMIT,
36
+ },
37
+ skip: !variables.organizationId || params.skip,
38
+ });
39
+
40
+ return {
41
+ agentMemories: data?.agentMemories,
42
+ ...rest,
43
+ };
44
+ }
@@ -1,112 +1,263 @@
1
- import { resetQuery, updateQuery } from '../cache/';
2
- import { useMutation } from '../client';
3
- import { updateAIChats } from './use-aiChat-qry';
4
- import { sendAIChatMessageMtn, startAIChatMtn, stopAIChatMessageMtn } from '../gql/mutations/aiChatMutations';
5
- import type { UseMutationParams } from '../types.d';
1
+ import {
2
+ FRAGMENT_NAMES,
3
+ makeFragmentKey,
4
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
6
5
  import { useOpenModalPopUp } from '@jsb188/react/states';
7
- import { useEffect, useRef } from 'react';
6
+ import { useCallback, useEffect, useRef } from 'react';
7
+ import {
8
+ loadFragment,
9
+ resetQuery,
10
+ updateFragment,
11
+ updateQuery,
12
+ } from '../cache/index.ts';
13
+ import { type GraphQLMutationFn, useMutation } from '../client/index.ts';
14
+ import {
15
+ deleteAIChatMtn,
16
+ editAIChatMtn,
17
+ sendAIChatMessageMtn,
18
+ startAIChatMtn,
19
+ stopAIChatMessageMtn,
20
+ } from '../gql/mutations/aiChatMutations.ts';
21
+ import type { UseMutationParams } from '../types.d.ts';
22
+ import { updateAIChats } from './use-aiChat-qry.ts';
8
23
 
9
24
  /**
10
25
  * Start AI chat
11
26
  */
12
27
 
13
28
  export function useStartAIChat(params: UseMutationParams = {}) {
29
+ const { onCompleted, onError } = params;
30
+ const openModalPopUp = useOpenModalPopUp();
14
31
 
15
- const { onCompleted, onError } = params;
16
- const openModalPopUp = useOpenModalPopUp();
17
-
18
- const [startAIChat, mtnValues,, updateObservers] = useMutation(
19
- startAIChatMtn,
20
- {
21
- openModalPopUp,
22
- onCompleted: (data: any, err: any, variables: any) => {
23
- onCompleted?.(data, err, variables);
24
-
25
- const aiChat = data.startAIChat?.node;
26
- updateAIChats(aiChat, updateObservers);
27
- },
28
- onError,
29
- },
30
- );
31
-
32
- return {
33
- startAIChat,
34
- ...mtnValues,
35
- };
32
+ const [startAIChat, mtnValues, , updateObservers] = useMutation(
33
+ startAIChatMtn,
34
+ {
35
+ openModalPopUp,
36
+ onCompleted: (data: any, err: any, variables: any) => {
37
+ onCompleted?.(data, err, variables);
38
+
39
+ const aiChat = data.startAIChat?.node;
40
+ updateAIChats(aiChat, variables?.organizationId, updateObservers);
41
+ },
42
+ onError,
43
+ },
44
+ );
45
+
46
+ return {
47
+ startAIChat,
48
+ ...mtnValues,
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Edit AI chat
54
+ */
55
+
56
+ export function useEditAIChat(params: UseMutationParams = {}) {
57
+ const { onCompleted, onError } = params;
58
+ const openModalPopUp = useOpenModalPopUp();
59
+
60
+ const [mutateAIChat, mtnValues, mtnHandlers, updateObservers] = useMutation(
61
+ editAIChatMtn,
62
+ {
63
+ openModalPopUp,
64
+ onCompleted,
65
+ onError,
66
+ },
67
+ );
68
+
69
+ /*
70
+ * Optimistically write a submitted summary to its fragment and roll it back
71
+ * only when the mutation fails before an authoritative response arrives.
72
+ */
73
+ const editAIChat = useCallback<GraphQLMutationFn>(
74
+ async (graphqlOptions, triedCount) => {
75
+ const aiChatId = graphqlOptions?.variables?.aiChatId;
76
+ const nextSummary = graphqlOptions?.variables?.summary;
77
+
78
+ if (!aiChatId || typeof nextSummary !== 'string') {
79
+ return mutateAIChat(graphqlOptions, triedCount);
80
+ }
81
+
82
+ const fragmentKey = makeFragmentKey(FRAGMENT_NAMES.aiChat, aiChatId);
83
+ const previousFragment = loadFragment(fragmentKey);
84
+ updateFragment(
85
+ fragmentKey,
86
+ {
87
+ summary: nextSummary,
88
+ userManagedSummary: true,
89
+ },
90
+ null,
91
+ false,
92
+ updateObservers,
93
+ );
94
+
95
+ const result = await mutateAIChat(graphqlOptions, triedCount);
96
+
97
+ if (result?.error && previousFragment) {
98
+ updateFragment(
99
+ fragmentKey,
100
+ (currentFragment: any) =>
101
+ currentFragment?.summary === nextSummary
102
+ ? {
103
+ summary: previousFragment.summary,
104
+ userManagedSummary: previousFragment.userManagedSummary,
105
+ }
106
+ : {},
107
+ null,
108
+ false,
109
+ updateObservers,
110
+ );
111
+ }
112
+
113
+ return result;
114
+ },
115
+ [mutateAIChat, updateObservers],
116
+ );
117
+
118
+ return {
119
+ editAIChat,
120
+ ...mtnValues,
121
+ ...mtnHandlers,
122
+ };
36
123
  }
37
124
 
38
125
  /**
39
126
  * Send a new message to AI Chat
40
127
  */
41
128
 
42
- export function useAIChatTextarea(variablesKey: string, params: UseMutationParams = {}) {
43
-
44
- const { onCompleted, onError } = params;
45
- const didSendRef = useRef(false);
46
- const openModalPopUp = useOpenModalPopUp();
47
-
48
- // Send AI chat message
49
-
50
- const [sendAIChatMessage, mtnValues1,, updateObservers] = useMutation(
51
- sendAIChatMessageMtn,
52
- {
53
- openModalPopUp,
54
- onCompleted: (data: any, err: any, variables: any) => {
55
- didSendRef.current = true;
56
-
57
- onCompleted?.(data, err, variables);
58
-
59
- const aiChatId = variables.aiChatId;
60
- const messageId = data.sendAIChatMessage?.node?.id;
61
-
62
- if (messageId && aiChatId && variablesKey) {
63
- updateQuery(`#aiChat:${variablesKey}`, (currentData: any) => {
64
- if (Array.isArray(currentData.messages?.data)) {
65
- currentData.messages.data.push([`$aiChatMessageFragment:${messageId}`]);
66
- }
67
- return currentData;
68
- }, false, updateObservers);
69
- } else if (data && !err) {
70
- console.dev(`Unknown error: {${messageId ? 'aiChatId' : 'messageId'}} was not found.`, 'warning');
71
- }
72
- },
73
- onError,
74
- },
75
- );
76
-
77
- // Stop AI chat message
78
-
79
- const [stopAIChatMessage, mtnValues2] = useMutation(
80
- stopAIChatMessageMtn,
81
- {
82
- openModalPopUp,
83
- onCompleted: (data: any, err: any, variables: any) => {
84
- onCompleted?.(data, err, variables);
85
- },
86
- onError,
87
- },
88
- );
89
-
90
- // Reset query on unmount if a message was sent;
91
- // This fixes an issue where in-progress messages that are stopped midway remain broken
92
- // as a result of the SSE pipe breaking at unmount.
93
-
94
- useEffect(() => {
95
- return () => {
96
- if (didSendRef.current) {
97
- resetQuery(`#aiChat:${variablesKey}`, true, updateObservers);
98
- }
99
- };
100
- }, []);
101
-
102
- return {
103
- send: {
104
- sendAIChatMessage,
105
- ...mtnValues1,
106
- },
107
- stop: {
108
- stopAIChatMessage,
109
- ...mtnValues2,
110
- }
111
- };
129
+ export function useAIChatTextarea(
130
+ variablesKey: string,
131
+ params: UseMutationParams = {},
132
+ ) {
133
+ const { onCompleted, onError } = params;
134
+ const didSendRef = useRef(false);
135
+ const openModalPopUp = useOpenModalPopUp();
136
+
137
+ // Send AI chat message
138
+
139
+ const [sendAIChatMessage, mtnValues1, , updateObservers] = useMutation(
140
+ sendAIChatMessageMtn,
141
+ {
142
+ openModalPopUp,
143
+ onCompleted: (data: any, err: any, variables: any) => {
144
+ didSendRef.current = true;
145
+
146
+ onCompleted?.(data, err, variables);
147
+
148
+ const aiChatId = variables.aiChatId;
149
+ const messageId = data.sendAIChatMessage?.node?.id;
150
+
151
+ if (messageId && aiChatId && variablesKey) {
152
+ const fragmentKey = makeFragmentKey(
153
+ FRAGMENT_NAMES.aiChatMessage,
154
+ messageId,
155
+ );
156
+
157
+ updateQuery(
158
+ `#aiChat:${variablesKey}`,
159
+ (currentData: any) => {
160
+ const currentList = currentData?.messages?.data;
161
+
162
+ // The updater receives the stored references by reference, so the
163
+ // new message must be appended into fresh objects; mutating them
164
+ // in place leaves the version stamp (and the persisted snapshot)
165
+ // unchanged, which drops the sent message on the next page load.
166
+ if (
167
+ !Array.isArray(currentList) ||
168
+ currentList.some((item: any) => item?.[0] === fragmentKey)
169
+ ) {
170
+ return currentData;
171
+ }
172
+
173
+ return {
174
+ ...currentData,
175
+ messages: {
176
+ ...currentData.messages,
177
+ data: [...currentList, [fragmentKey]],
178
+ },
179
+ };
180
+ },
181
+ false,
182
+ updateObservers,
183
+ );
184
+ } else if (data && !err) {
185
+ console.dev(
186
+ `Unknown error: {${messageId ? 'aiChatId' : 'messageId'}} was not found.`,
187
+ 'warning',
188
+ );
189
+ }
190
+ },
191
+ onError,
192
+ },
193
+ );
194
+
195
+ // Stop AI chat message
196
+
197
+ const [stopAIChatMessage, mtnValues2] = useMutation(stopAIChatMessageMtn, {
198
+ openModalPopUp,
199
+ onCompleted: (data: any, err: any, variables: any) => {
200
+ onCompleted?.(data, err, variables);
201
+ },
202
+ onError,
203
+ });
204
+
205
+ // Reset query on unmount if a message was sent;
206
+ // This fixes an issue where in-progress messages that are stopped midway remain broken
207
+ // as a result of the SSE pipe breaking at unmount.
208
+
209
+ useEffect(() => {
210
+ return () => {
211
+ if (didSendRef.current) {
212
+ resetQuery(`#aiChat:${variablesKey}`, true, updateObservers);
213
+ }
214
+ };
215
+ }, []);
216
+
217
+ return {
218
+ send: {
219
+ sendAIChatMessage,
220
+ ...mtnValues1,
221
+ },
222
+ stop: {
223
+ stopAIChatMessage,
224
+ ...mtnValues2,
225
+ },
226
+ };
227
+ }
228
+
229
+ /**
230
+ * Delete AI chat
231
+ */
232
+
233
+ export function useDeleteAIChat(params: UseMutationParams = {}) {
234
+ const { onCompleted, onError } = params;
235
+ const openModalPopUp = useOpenModalPopUp();
236
+
237
+ const [deleteAIChat, mtnValues, mtnHandlers, updateObservers] = useMutation(
238
+ deleteAIChatMtn,
239
+ {
240
+ openModalPopUp,
241
+ onCompleted: (data: any, err: any, variables: any) => {
242
+ if (data?.deleteAIChat) {
243
+ updateFragment(
244
+ makeFragmentKey(FRAGMENT_NAMES.aiChat, variables.aiChatId),
245
+ { __deleted: true },
246
+ null,
247
+ false,
248
+ updateObservers,
249
+ );
250
+ }
251
+
252
+ onCompleted?.(data, err, variables);
253
+ },
254
+ onError,
255
+ },
256
+ );
257
+
258
+ return {
259
+ deleteAIChat,
260
+ ...mtnValues,
261
+ ...mtnHandlers,
262
+ };
112
263
  }