@jsb188/graphql 1.1.10 → 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.
- package/cache/config.ts +64 -50
- package/cache/index.test.ts +671 -109
- package/cache/index.ts +1700 -1240
- package/cache/persist.ts +721 -0
- package/cache/store.ts +437 -0
- package/client/data-table-realtime-subscriptions.test.ts +740 -0
- package/client/data-table-realtime-subscriptions.ts +955 -0
- package/client/data-table-realtime.test.ts +792 -0
- package/client/data-table-realtime.ts +1218 -0
- package/client/fragment-realtime-sequence.ts +52 -0
- package/client/index.ts +2 -0
- package/client/open-sheet.ts +137 -0
- package/client/request-managed-session.test.ts +574 -0
- package/client/request-no-store.test.ts +157 -0
- package/client/request.ts +954 -163
- package/client/sse-ticket.test.ts +26 -0
- package/deno.lock +170 -0
- package/deno.test.json +8 -4
- package/drafts/index.ts +149 -0
- package/drafts/store.ts +397 -0
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +0 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentDocFragments.ts +46 -0
- package/gql/fragments/agentMemoryFragments.ts +19 -0
- package/gql/fragments/aiChatFragments.ts +16 -0
- package/gql/fragments/billingFragments.ts +0 -11
- package/gql/fragments/campaignFragments.ts +277 -0
- package/gql/fragments/dataTableFragments.ts +18 -128
- package/gql/fragments/emailFragments.ts +19 -9
- package/gql/fragments/fieldDocFragments.ts +82 -0
- package/gql/fragments/logFragments.ts +20 -79
- package/gql/fragments/organizationFragments.ts +43 -5
- package/gql/fragments/scheduleFragments.ts +155 -0
- package/gql/fragments/sheetFragments.ts +552 -22
- package/gql/fragments/storageFragments.ts +21 -0
- package/gql/fragments/workflowFragments.ts +28 -4
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentDocMutations.ts +177 -0
- package/gql/mutations/agentMemoryMutations.ts +36 -0
- package/gql/mutations/aiChatMutations.ts +17 -4
- package/gql/mutations/authMutations.ts +158 -17
- package/gql/mutations/campaignMutations.ts +215 -0
- package/gql/mutations/dataTableMutations.ts +48 -26
- package/gql/mutations/fieldDocMutations.ts +24 -0
- package/gql/mutations/index.ts +6 -1
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +13 -4
- package/gql/mutations/scheduleMutations.ts +423 -0
- package/gql/mutations/sheetMutations.ts +273 -56
- package/gql/mutations/storageMutations.ts +20 -0
- package/gql/mutations/workflowMutations.ts +42 -0
- package/gql/queries/agentDocQueries.ts +120 -0
- package/gql/queries/agentMemoryQueries.ts +22 -0
- package/gql/queries/aiChatQueries.ts +18 -2
- package/gql/queries/authQueries.ts +41 -0
- package/gql/queries/billingQueries.ts +23 -0
- package/gql/queries/campaignQueries.ts +127 -0
- package/gql/queries/dataTableQueries.ts +100 -11
- package/gql/queries/emailQueries.ts +55 -3
- package/gql/queries/fieldDocQueries.ts +158 -0
- package/gql/queries/index.ts +8 -2
- package/gql/queries/logQueries.ts +11 -28
- package/gql/queries/organizationQueries.ts +52 -1
- package/gql/queries/scheduleQueries.ts +315 -0
- package/gql/queries/sheetQueries.ts +336 -25
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +72 -3
- package/hooks/index.ts +2065 -971
- package/hooks/use-account-mtn.ts +76 -81
- package/hooks/use-agentDoc-mtn.ts +285 -0
- package/hooks/use-agentDoc-qry.ts +208 -0
- package/hooks/use-agentMemory-mtn.ts +73 -0
- package/hooks/use-agentMemory-qry.ts +44 -0
- package/hooks/use-aiChat-mtn.ts +232 -137
- package/hooks/use-aiChat-qry.ts +480 -222
- package/hooks/use-app-qry.ts +12 -9
- package/hooks/use-auth-mtn.ts +406 -252
- package/hooks/use-auth-qry.ts +51 -0
- package/hooks/use-campaign-mtn.ts +377 -0
- package/hooks/use-campaign-qry.ts +257 -0
- package/hooks/use-dataTable-mtn.ts +116 -33
- package/hooks/use-dataTable-qry.ts +859 -35
- package/hooks/use-email-qry.ts +194 -79
- package/hooks/use-fieldDoc-mtn.ts +50 -0
- package/hooks/use-fieldDoc-qry.ts +180 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +63 -55
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +72 -56
- package/hooks/use-log-qry.ts +93 -69
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +199 -129
- package/hooks/use-schedule-mtn.ts +416 -0
- package/hooks/use-schedule-qry.ts +157 -0
- package/hooks/use-sheet-mtn.ts +233 -47
- package/hooks/use-sheet-qry.ts +353 -70
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +104 -13
- package/hooks/use-workflow-mtn.ts +55 -0
- package/hooks/use-workflow-qry.ts +206 -48
- package/loaders/campaign.ts +137 -0
- package/package.json +94 -71
- package/sse.ts +157 -104
- package/tsconfig.json +11 -10
- package/types.d.ts +60 -30
- package/utils.ts +78 -49
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/mutations/billingMutations.ts +0 -34
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
|
@@ -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
|
+
}
|
package/hooks/use-aiChat-mtn.ts
CHANGED
|
@@ -1,38 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { UseMutationParams } from '../types.d.ts';
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
};
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
/**
|
|
@@ -40,100 +54,176 @@ export function useStartAIChat(params: UseMutationParams = {}) {
|
|
|
40
54
|
*/
|
|
41
55
|
|
|
42
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
|
+
);
|
|
43
68
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
+
};
|
|
61
123
|
}
|
|
62
124
|
|
|
63
125
|
/**
|
|
64
126
|
* Send a new message to AI Chat
|
|
65
127
|
*/
|
|
66
128
|
|
|
67
|
-
export function useAIChatTextarea(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
};
|
|
137
227
|
}
|
|
138
228
|
|
|
139
229
|
/**
|
|
@@ -141,28 +231,33 @@ export function useAIChatTextarea(variablesKey: string, params: UseMutationParam
|
|
|
141
231
|
*/
|
|
142
232
|
|
|
143
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
|
+
);
|
|
144
257
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
{
|
|
151
|
-
openModalPopUp,
|
|
152
|
-
onCompleted: (data: any, err: any, variables: any) => {
|
|
153
|
-
if (data?.deleteAIChat) {
|
|
154
|
-
updateFragment(`$aiChatFragment:${variables.aiChatId}`, { __deleted: true }, null, false, updateObservers);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
onCompleted?.(data, err, variables);
|
|
158
|
-
},
|
|
159
|
-
onError,
|
|
160
|
-
},
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
deleteAIChat,
|
|
165
|
-
...mtnValues,
|
|
166
|
-
...mtnHandlers,
|
|
167
|
-
};
|
|
258
|
+
return {
|
|
259
|
+
deleteAIChat,
|
|
260
|
+
...mtnValues,
|
|
261
|
+
...mtnHandlers,
|
|
262
|
+
};
|
|
168
263
|
}
|