@adminide-stack/yantra-mobile 12.0.28-alpha.51 → 12.0.28-alpha.58
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/lib/assets/icon.png +0 -0
- package/lib/components/CustomDrawer.js +358 -0
- package/lib/components/CustomDrawer.js.map +1 -0
- package/lib/components/GatewayToolbarButtonMobile.js +84 -0
- package/lib/components/GatewayToolbarButtonMobile.js.map +1 -0
- package/lib/components/YantraBrandLoader.js +94 -0
- package/lib/components/YantraBrandLoader.js.map +1 -0
- package/lib/compute.js +37 -5
- package/lib/compute.js.map +1 -1
- package/lib/config/constants.js +16 -0
- package/lib/config/constants.js.map +1 -0
- package/lib/config/env-config.js +74 -19
- package/lib/config/env-config.js.map +1 -1
- package/lib/contexts/GatewayContext.js +77 -0
- package/lib/contexts/GatewayContext.js.map +1 -0
- package/lib/graphql/agentGatewayDocuments.js +53 -0
- package/lib/graphql/agentGatewayDocuments.js.map +1 -0
- package/lib/hooks/useCdecliAutoConnect.js +219 -0
- package/lib/hooks/useCdecliAutoConnect.js.map +1 -0
- package/lib/hooks/useCdecliChannel.js +226 -0
- package/lib/hooks/useCdecliChannel.js.map +1 -0
- package/lib/hooks/useChatApi.js +220 -170
- package/lib/hooks/useChatApi.js.map +1 -1
- package/lib/hooks/useChatStream.js +232 -58
- package/lib/hooks/useChatStream.js.map +1 -1
- package/lib/hooks/useGatewayConnection.js +123 -0
- package/lib/hooks/useGatewayConnection.js.map +1 -0
- package/lib/hooks/useGatewayRegistry.js +28 -0
- package/lib/hooks/useGatewayRegistry.js.map +1 -0
- package/lib/hooks/usePrerequisiteIds.js +122 -0
- package/lib/hooks/usePrerequisiteIds.js.map +1 -0
- package/lib/hooks/useWorkspaceProvisioner.js +236 -0
- package/lib/hooks/useWorkspaceProvisioner.js.map +1 -0
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/routes.json +8 -5
- package/lib/screens/Home/HomeScreen.js +420 -97
- package/lib/screens/Home/HomeScreen.js.map +1 -1
- package/lib/screens/Home/components/ChatHistoryLanding.js +229 -0
- package/lib/screens/Home/components/ChatHistoryLanding.js.map +1 -0
- package/lib/screens/Home/components/DeepSearchModal.js +334 -0
- package/lib/screens/Home/components/DeepSearchModal.js.map +1 -0
- package/lib/screens/Home/deepSearchUtils.js +41 -0
- package/lib/screens/Home/deepSearchUtils.js.map +1 -0
- package/lib/screens/NewChat/index.js +75 -0
- package/lib/screens/NewChat/index.js.map +1 -0
- package/lib/services/agentSessionManager.js +451 -0
- package/lib/services/agentSessionManager.js.map +1 -0
- package/lib/services/gatewayApiKeyBridge.js +4 -0
- package/lib/services/gatewayApiKeyBridge.js.map +1 -0
- package/lib/services/gatewayClient.js +470 -0
- package/lib/services/gatewayClient.js.map +1 -0
- package/lib/utils/gatewaySelectionStorage.js +21 -0
- package/lib/utils/gatewaySelectionStorage.js.map +1 -0
- package/package.json +7 -3
package/lib/hooks/useChatApi.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {SortEnum,RoomType,PostTypeEnum,AiAgentMessageRole}from'common';import {useAddChannelMutation,useSendMessagesMutation,GetChannelsByUserWithLastMessageDocument,useGetChannelsByUserWithLastMessageQuery,useMessagesQuery}from'common/graphql';import {useCallback,useMemo}from'react';import {v4}from'uuid';var __defProp = Object.defineProperty;
|
|
2
2
|
var __defProps = Object.defineProperties;
|
|
3
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -17,49 +17,105 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
23
31
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
const MESSAGES_PAGE_LIMIT = 100;
|
|
33
|
+
const AI_ASSISTANT_CHANNELS_QUERY_VARS = {
|
|
34
|
+
criteria: {
|
|
35
|
+
type: RoomType.Aiassistant
|
|
36
|
+
},
|
|
37
|
+
limit: 100,
|
|
38
|
+
skip: 0,
|
|
39
|
+
sort: {
|
|
40
|
+
key: "updatedAt",
|
|
41
|
+
value: SortEnum.Desc
|
|
32
42
|
}
|
|
43
|
+
};
|
|
44
|
+
function stripModelCostHeader(content) {
|
|
45
|
+
const normalized = content.replace(/\r\n/g, "\n");
|
|
46
|
+
return normalized.replace(/^\s*(?:[^\w\n]+\s*)?[a-z0-9][a-z0-9._-]*\s*\(\s*\$[\d.]+\s*\/\s*MTok\s+in\s*\)\s*\n+/i, "");
|
|
33
47
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
} catch (e) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
48
|
+
function sanitizeAssistantContentByRole(role, content) {
|
|
49
|
+
return role === "assistant" ? stripModelCostHeader(content) : content;
|
|
50
|
+
}
|
|
51
|
+
function omitContent(value) {
|
|
52
|
+
const clone = __spreadValues({}, value != null ? value : {});
|
|
53
|
+
delete clone.content;
|
|
54
|
+
return clone;
|
|
46
55
|
}
|
|
47
|
-
function
|
|
56
|
+
function useChatSessions(options) {
|
|
57
|
+
const {
|
|
58
|
+
data,
|
|
59
|
+
loading,
|
|
60
|
+
error,
|
|
61
|
+
refetch
|
|
62
|
+
} = useGetChannelsByUserWithLastMessageQuery({
|
|
63
|
+
variables: AI_ASSISTANT_CHANNELS_QUERY_VARS,
|
|
64
|
+
skip: void 0 ,
|
|
65
|
+
fetchPolicy: "cache-and-network"
|
|
66
|
+
});
|
|
67
|
+
const sessions = useMemo(() => {
|
|
68
|
+
var _a;
|
|
69
|
+
const channels = (_a = data == null ? void 0 : data.channelsByUser) != null ? _a : [];
|
|
70
|
+
return channels.filter((c) => Boolean(c == null ? void 0 : c.id)).map((channel) => {
|
|
71
|
+
var _a2, _b;
|
|
72
|
+
return {
|
|
73
|
+
id: channel.id,
|
|
74
|
+
title: channel.title || channel.displayName || "New Chat",
|
|
75
|
+
createdAt: new Date((_a2 = channel.createdAt) != null ? _a2 : Date.now()),
|
|
76
|
+
updatedAt: new Date((_b = channel.updatedAt) != null ? _b : Date.now()),
|
|
77
|
+
messageCount: void 0
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}, [data]);
|
|
48
81
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, node)
|
|
82
|
+
sessions,
|
|
83
|
+
loading,
|
|
84
|
+
error,
|
|
85
|
+
refetch
|
|
54
86
|
};
|
|
55
87
|
}
|
|
56
|
-
function
|
|
88
|
+
function mapPostToChatMessageUI(post, fallbackChannelId) {
|
|
89
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
90
|
+
const props = (_a = post.props) != null ? _a : {};
|
|
91
|
+
const contents = (_c = (_b = post.propsConfiguration) == null ? void 0 : _b.contents) != null ? _c : {};
|
|
92
|
+
const roleRaw = (_g = (_d = props.role) != null ? _d : contents.role) != null ? _g : (_f = (_e = post.propsConfiguration) == null ? void 0 : _e.content) == null ? void 0 : _f.role;
|
|
93
|
+
let role = "assistant";
|
|
94
|
+
if (roleRaw === "user" || roleRaw === AiAgentMessageRole.User) role = "user";
|
|
95
|
+
else if (roleRaw === "assistant" || roleRaw === AiAgentMessageRole.Assistant) role = "assistant";
|
|
96
|
+
else if (roleRaw === "system") role = "system";
|
|
97
|
+
const rawContent = (_h = post == null ? void 0 : post.message) != null ? _h : "";
|
|
98
|
+
const content = sanitizeAssistantContentByRole(role, rawContent);
|
|
57
99
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
100
|
+
id: (_i = post == null ? void 0 : post.id) != null ? _i : v4(),
|
|
101
|
+
sessionId: (_k = (_j = post == null ? void 0 : post.channel) == null ? void 0 : _j.id) != null ? _k : fallbackChannelId,
|
|
102
|
+
role,
|
|
103
|
+
content,
|
|
104
|
+
attachments: ((_m = (_l = post == null ? void 0 : post.files) == null ? void 0 : _l.data) != null ? _m : []).map((file) => {
|
|
105
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
106
|
+
return {
|
|
107
|
+
id: (_a2 = file.id) != null ? _a2 : v4(),
|
|
108
|
+
name: (_b2 = file.name) != null ? _b2 : "file",
|
|
109
|
+
type: typeof file.mimeType === "string" && file.mimeType.startsWith("image/") ? "screenshot" : "file",
|
|
110
|
+
mimeType: (_c2 = file.mimeType) != null ? _c2 : void 0,
|
|
111
|
+
size: (_d2 = file.size) != null ? _d2 : void 0,
|
|
112
|
+
url: (_e2 = file.url) != null ? _e2 : void 0
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
tokenCount: (_n = props.tokenCount) != null ? _n : void 0,
|
|
116
|
+
model: (_o = props.model) != null ? _o : void 0,
|
|
117
|
+
createdAt: (post == null ? void 0 : post.createdAt) ? new Date(post.createdAt) : /* @__PURE__ */ new Date(),
|
|
118
|
+
updatedAt: (post == null ? void 0 : post.updatedAt) ? new Date(post.updatedAt) : /* @__PURE__ */ new Date()
|
|
63
119
|
};
|
|
64
120
|
}
|
|
65
121
|
function useChatMessages(sessionId, options) {
|
|
@@ -68,33 +124,25 @@ function useChatMessages(sessionId, options) {
|
|
|
68
124
|
loading,
|
|
69
125
|
error,
|
|
70
126
|
refetch
|
|
71
|
-
} =
|
|
127
|
+
} = useMessagesQuery({
|
|
72
128
|
variables: {
|
|
73
|
-
sessionId,
|
|
74
|
-
|
|
129
|
+
channelId: sessionId != null ? sessionId : void 0,
|
|
130
|
+
parentId: null,
|
|
131
|
+
limit: MESSAGES_PAGE_LIMIT,
|
|
132
|
+
skip: 0
|
|
75
133
|
},
|
|
76
134
|
skip: !sessionId || (void 0 ),
|
|
77
|
-
fetchPolicy: "cache-
|
|
135
|
+
fetchPolicy: "cache-and-network",
|
|
136
|
+
context: {
|
|
137
|
+
cacheKey: "messages-list"
|
|
138
|
+
}
|
|
78
139
|
});
|
|
79
140
|
const messages = useMemo(() => {
|
|
80
|
-
var _a;
|
|
81
|
-
if (!
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
id: n.id,
|
|
87
|
-
sessionId: n.sessionId,
|
|
88
|
-
role: n.role,
|
|
89
|
-
content: (_a2 = n.content) != null ? _a2 : "",
|
|
90
|
-
attachments: (_b = n.attachments) != null ? _b : void 0,
|
|
91
|
-
tokenCount: n.tokenCount,
|
|
92
|
-
model: n.model,
|
|
93
|
-
createdAt: new Date(n.createdAt),
|
|
94
|
-
updatedAt: new Date(n.updatedAt)
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
}, [data]);
|
|
141
|
+
var _a, _b;
|
|
142
|
+
if (!sessionId) return [];
|
|
143
|
+
const rows = (_b = (_a = data == null ? void 0 : data.messages) == null ? void 0 : _a.data) != null ? _b : [];
|
|
144
|
+
return rows.map((post) => mapPostToChatMessageUI(post, sessionId)).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
145
|
+
}, [data, sessionId]);
|
|
98
146
|
return {
|
|
99
147
|
messages,
|
|
100
148
|
loading,
|
|
@@ -103,131 +151,133 @@ function useChatMessages(sessionId, options) {
|
|
|
103
151
|
};
|
|
104
152
|
}
|
|
105
153
|
function useChatMutations() {
|
|
106
|
-
const [
|
|
107
|
-
loading:
|
|
108
|
-
}] =
|
|
109
|
-
const [
|
|
110
|
-
loading:
|
|
111
|
-
}] =
|
|
112
|
-
const
|
|
113
|
-
var
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
154
|
+
const [addChannelMutation, {
|
|
155
|
+
loading: createChannelLoading
|
|
156
|
+
}] = useAddChannelMutation();
|
|
157
|
+
const [sendMessagesMutation, {
|
|
158
|
+
loading: sendMessagesLoading
|
|
159
|
+
}] = useSendMessagesMutation();
|
|
160
|
+
const createChannel = useCallback(async (input) => {
|
|
161
|
+
var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
162
|
+
const _a = input != null ? input : {}, {
|
|
163
|
+
orgName: orgNameArg,
|
|
164
|
+
projectId: projectIdArg
|
|
165
|
+
} = _a, inputForSettings = __objRest(_a, [
|
|
166
|
+
"orgName",
|
|
167
|
+
"projectId"
|
|
168
|
+
]);
|
|
169
|
+
const orgName = typeof orgNameArg === "string" && orgNameArg.trim().length > 0 ? orgNameArg.trim() : void 0;
|
|
170
|
+
const projectId = typeof projectIdArg === "string" && projectIdArg.trim().length > 0 ? projectIdArg.trim() : void 0;
|
|
171
|
+
const settings = __spreadValues({
|
|
172
|
+
title: (_b = input == null ? void 0 : input.title) != null ? _b : "New Chat",
|
|
173
|
+
description: (_c = input == null ? void 0 : input.systemPrompt) != null ? _c : null,
|
|
174
|
+
isShared: false,
|
|
175
|
+
sharedSlug: null,
|
|
176
|
+
isArchived: false,
|
|
177
|
+
isPinned: false,
|
|
178
|
+
model: (_d = input == null ? void 0 : input.model) != null ? _d : null,
|
|
179
|
+
systemPrompt: (_e = input == null ? void 0 : input.systemPrompt) != null ? _e : null
|
|
180
|
+
}, inputForSettings);
|
|
122
181
|
const {
|
|
123
182
|
data
|
|
124
|
-
} = await
|
|
125
|
-
variables: {
|
|
126
|
-
input:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
getAccountChatSessions: __spreadProps(__spreadValues({}, existing.getAccountChatSessions), {
|
|
142
|
-
edges: [newEdge, ...existing.getAccountChatSessions.edges],
|
|
143
|
-
totalCount: ((_a2 = existing.getAccountChatSessions.totalCount) != null ? _a2 : 0) + 1
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
} catch (err) {
|
|
149
|
-
console.warn("[useChatApi] createSession cache update failed:", err);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
183
|
+
} = await addChannelMutation({
|
|
184
|
+
variables: __spreadValues(__spreadValues({
|
|
185
|
+
channelId: (_f = input == null ? void 0 : input.id) != null ? _f : null,
|
|
186
|
+
name: (_g = input == null ? void 0 : input.title) != null ? _g : "New Chat",
|
|
187
|
+
description: (_h = input == null ? void 0 : input.systemPrompt) != null ? _h : null,
|
|
188
|
+
type: RoomType.Aiassistant,
|
|
189
|
+
settings
|
|
190
|
+
}, orgName ? {
|
|
191
|
+
orgName
|
|
192
|
+
} : {}), projectId ? {
|
|
193
|
+
projectId
|
|
194
|
+
} : {}),
|
|
195
|
+
refetchQueries: [{
|
|
196
|
+
query: GetChannelsByUserWithLastMessageDocument,
|
|
197
|
+
variables: AI_ASSISTANT_CHANNELS_QUERY_VARS
|
|
198
|
+
}],
|
|
199
|
+
awaitRefetchQueries: true
|
|
152
200
|
});
|
|
153
|
-
if (!(data == null ? void 0 : data.
|
|
154
|
-
throw new Error("Failed to create
|
|
201
|
+
if (!((_i = data == null ? void 0 : data.createChannel) == null ? void 0 : _i.id)) {
|
|
202
|
+
throw new Error("Failed to create channel");
|
|
155
203
|
}
|
|
156
|
-
const
|
|
204
|
+
const channel = data.createChannel;
|
|
205
|
+
const title = (_k = (_j = channel.title) != null ? _j : input == null ? void 0 : input.title) != null ? _k : "New Chat";
|
|
206
|
+
const now = /* @__PURE__ */ new Date();
|
|
157
207
|
return {
|
|
158
|
-
id:
|
|
159
|
-
title
|
|
160
|
-
createdAt:
|
|
161
|
-
updatedAt:
|
|
208
|
+
id: channel.id,
|
|
209
|
+
title,
|
|
210
|
+
createdAt: now,
|
|
211
|
+
updatedAt: now
|
|
162
212
|
};
|
|
163
|
-
}, [
|
|
213
|
+
}, [addChannelMutation]);
|
|
164
214
|
const saveMessages = useCallback(async (input) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
215
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
216
|
+
const sanitizedAssistantContent = stripModelCostHeader((_a = input.assistantMessage.content) != null ? _a : "");
|
|
217
|
+
const assistantMessageWithoutContent = omitContent((_b = input.assistantMessage) != null ? _b : {});
|
|
218
|
+
const userResult = await sendMessagesMutation({
|
|
219
|
+
variables: __spreadProps(__spreadValues({
|
|
220
|
+
channelId: input.sessionId,
|
|
221
|
+
type: RoomType.Aiassistant,
|
|
222
|
+
content: (_c = input.userMessage.content) != null ? _c : ""
|
|
223
|
+
}, input.createdBy ? {
|
|
224
|
+
createdBy: input.createdBy
|
|
225
|
+
} : {}), {
|
|
226
|
+
extraProps: __spreadValues(__spreadValues({
|
|
227
|
+
type: PostTypeEnum.Aiassistant,
|
|
228
|
+
role: "user",
|
|
229
|
+
attachments: (_d = input.userMessage.attachments) != null ? _d : [],
|
|
230
|
+
isActive: true,
|
|
231
|
+
status: "complete"
|
|
232
|
+
}, input.userMessage), input.mode ? {
|
|
233
|
+
mode: input.mode
|
|
234
|
+
} : {})
|
|
235
|
+
})
|
|
236
|
+
});
|
|
237
|
+
const assistantResult = await sendMessagesMutation({
|
|
168
238
|
variables: {
|
|
169
|
-
input
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
sessionId: input.sessionId,
|
|
186
|
-
first: 100
|
|
187
|
-
},
|
|
188
|
-
data: {
|
|
189
|
-
getAccountChatMessages: __spreadProps(__spreadValues({}, existingMessages.getAccountChatMessages), {
|
|
190
|
-
edges: [...existingMessages.getAccountChatMessages.edges, userEdge, assistantEdge],
|
|
191
|
-
totalCount: ((_a = existingMessages.getAccountChatMessages.totalCount) != null ? _a : 0) + 2
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
} catch (err) {
|
|
197
|
-
console.warn("[useChatApi] saveMessages cache update failed:", err);
|
|
198
|
-
}
|
|
199
|
-
try {
|
|
200
|
-
const existingSessions = readSessionsCache(cache);
|
|
201
|
-
if (existingSessions == null ? void 0 : existingSessions.getAccountChatSessions) {
|
|
202
|
-
const sessionData = res.session;
|
|
203
|
-
const updatedEdges = existingSessions.getAccountChatSessions.edges.map((edge) => edge.node.id === sessionData.id ? __spreadProps(__spreadValues({}, edge), {
|
|
204
|
-
node: __spreadValues(__spreadValues({}, edge.node), sessionData)
|
|
205
|
-
}) : edge);
|
|
206
|
-
cache.writeQuery({
|
|
207
|
-
query: GetAccountChatSessionsDocument,
|
|
208
|
-
variables: SESSIONS_QUERY_VARS,
|
|
209
|
-
data: {
|
|
210
|
-
getAccountChatSessions: __spreadProps(__spreadValues({}, existingSessions.getAccountChatSessions), {
|
|
211
|
-
edges: updatedEdges
|
|
212
|
-
})
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
} catch (err) {
|
|
217
|
-
console.warn("[useChatApi] saveMessages session cache update failed:", err);
|
|
218
|
-
}
|
|
239
|
+
channelId: input.sessionId,
|
|
240
|
+
type: RoomType.Aiassistant,
|
|
241
|
+
content: sanitizedAssistantContent,
|
|
242
|
+
extraProps: __spreadValues(__spreadValues({
|
|
243
|
+
type: PostTypeEnum.Aiassistant,
|
|
244
|
+
role: "assistant",
|
|
245
|
+
attachments: (_e = input.assistantMessage.attachments) != null ? _e : [],
|
|
246
|
+
tokenCount: input.assistantMessage.tokenCount,
|
|
247
|
+
latencyMs: input.assistantMessage.latencyMs,
|
|
248
|
+
model: input.assistantMessage.model,
|
|
249
|
+
finishReason: (_f = input.assistantMessage.finishReason) != null ? _f : null,
|
|
250
|
+
isActive: true,
|
|
251
|
+
status: "complete"
|
|
252
|
+
}, assistantMessageWithoutContent), input.mode ? {
|
|
253
|
+
mode: input.mode
|
|
254
|
+
} : {})
|
|
219
255
|
}
|
|
220
256
|
});
|
|
221
|
-
|
|
222
|
-
|
|
257
|
+
const userPost = (_g = userResult.data) == null ? void 0 : _g.sendMessage;
|
|
258
|
+
const assistantPost = (_h = assistantResult.data) == null ? void 0 : _h.sendMessage;
|
|
259
|
+
if (!userPost || !assistantPost) {
|
|
260
|
+
throw new Error("Failed to send messages");
|
|
223
261
|
}
|
|
224
|
-
|
|
262
|
+
const now = /* @__PURE__ */ new Date();
|
|
263
|
+
return {
|
|
264
|
+
userMessage: mapPostToChatMessageUI(userPost, input.sessionId),
|
|
265
|
+
assistantMessage: mapPostToChatMessageUI(assistantPost, input.sessionId),
|
|
266
|
+
session: {
|
|
267
|
+
id: input.sessionId,
|
|
268
|
+
title: "Chat",
|
|
269
|
+
createdAt: now,
|
|
270
|
+
updatedAt: now
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}, [sendMessagesMutation]);
|
|
225
274
|
return {
|
|
226
|
-
|
|
275
|
+
createChannel,
|
|
276
|
+
createSession: createChannel,
|
|
227
277
|
saveMessages,
|
|
228
278
|
loading: {
|
|
229
|
-
create:
|
|
230
|
-
saveMessages:
|
|
279
|
+
create: createChannelLoading,
|
|
280
|
+
saveMessages: sendMessagesLoading
|
|
231
281
|
}
|
|
232
282
|
};
|
|
233
|
-
}export{useChatMessages,useChatMutations};//# sourceMappingURL=useChatApi.js.map
|
|
283
|
+
}export{AI_ASSISTANT_CHANNELS_QUERY_VARS,useChatMessages,useChatMutations,useChatSessions};//# sourceMappingURL=useChatApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChatApi.js","sources":["../../src/hooks/useChatApi.ts"],"sourcesContent":["import type { ApolloCache } from '@apollo/client';\nimport {\n GetAccountChatMessagesDocument,\n GetAccountChatSessionsDocument,\n useCreateAccountChatSessionMutation,\n useGetAccountChatMessagesQuery,\n useGetAccountChatSessionsQuery,\n useSaveAccountChatMessagesMutation,\n} from 'common/graphql';\nimport type { IAccountCreateChatSessionInput, IAccountSaveChatMessagesInput } from 'common/server';\nimport { useCallback, useMemo } from 'react';\n\nconst SESSIONS_QUERY_VARS = { first: 25, includeArchived: false };\n\nfunction readSessionsCache(cache: ApolloCache<unknown>) {\n try {\n return cache.readQuery({\n query: GetAccountChatSessionsDocument,\n variables: SESSIONS_QUERY_VARS,\n }) as { getAccountChatSessions?: { edges: unknown[]; totalCount?: number } } | null;\n } catch {\n return null;\n }\n}\n\nfunction readMessagesCache(cache: ApolloCache<unknown>, sessionId: string) {\n try {\n return cache.readQuery({\n query: GetAccountChatMessagesDocument,\n variables: { sessionId, first: 100 },\n }) as { getAccountChatMessages?: { edges: unknown[]; totalCount?: number } } | null;\n } catch {\n return null;\n }\n}\n\nfunction buildSessionEdge(node: Record<string, unknown>) {\n return {\n __typename: 'AccountChatSessionEdge',\n cursor: '',\n node: {\n __typename: 'AccountChatSession',\n ...node,\n },\n };\n}\n\nfunction buildMessageEdge(node: Record<string, unknown>) {\n return {\n __typename: 'AccountChatMessageEdge',\n cursor: '',\n node: {\n __typename: 'AccountChatMessage',\n ...node,\n },\n };\n}\n\nexport interface ChatSessionUI {\n id: string;\n title: string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport function useChatSessions(options?: { includeArchived?: boolean; skip?: boolean }) {\n const { data, loading, error, refetch } = useGetAccountChatSessionsQuery({\n variables: {\n first: 25,\n includeArchived: options?.includeArchived ?? false,\n },\n skip: options?.skip,\n fetchPolicy: 'cache-first',\n });\n\n const sessions: ChatSessionUI[] = useMemo(() => {\n if (!data?.getAccountChatSessions?.edges) return [];\n return data.getAccountChatSessions.edges.map((edge: { node: Record<string, unknown> }) => ({\n id: edge.node.id as string,\n title: (edge.node.title as string) ?? 'New Chat',\n createdAt: new Date(edge.node.createdAt as string),\n updatedAt: new Date(edge.node.updatedAt as string),\n }));\n }, [data]);\n\n return { sessions, loading, error, refetch };\n}\n\nexport interface ChatMessageUI {\n id: string;\n sessionId: string;\n role: 'user' | 'assistant' | 'system';\n content: string;\n attachments?: Array<{ id: string; name: string; type: string; mimeType?: string; size?: number; url?: string }>;\n tokenCount?: number;\n model?: string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport function useChatMessages(sessionId: string | null, options?: { skip?: boolean }) {\n const { data, loading, error, refetch } = useGetAccountChatMessagesQuery({\n variables: { sessionId: sessionId!, first: 100 },\n skip: !sessionId || options?.skip,\n fetchPolicy: 'cache-first',\n });\n\n const messages: ChatMessageUI[] = useMemo(() => {\n if (!data?.getAccountChatMessages?.edges) return [];\n return data.getAccountChatMessages.edges.map((edge: { node: Record<string, unknown> }) => {\n const n = edge.node;\n return {\n id: n.id as string,\n sessionId: n.sessionId as string,\n role: n.role as 'user' | 'assistant' | 'system',\n content: (n.content as string) ?? '',\n attachments: (n.attachments as ChatMessageUI['attachments']) ?? undefined,\n tokenCount: n.tokenCount as number | undefined,\n model: n.model as string | undefined,\n createdAt: new Date(n.createdAt as string),\n updatedAt: new Date(n.updatedAt as string),\n };\n });\n }, [data]);\n\n return { messages, loading, error, refetch };\n}\n\nexport function useChatMutations() {\n const [createSessionMutation, { loading: createLoading }] = useCreateAccountChatSessionMutation();\n const [saveMessagesMutation, { loading: saveMessagesLoading }] = useSaveAccountChatMessagesMutation();\n\n const createSession = useCallback(\n async (input?: IAccountCreateChatSessionInput): Promise<ChatSessionUI> => {\n const inputWithId = {\n id: input?.id,\n title: input?.title ?? 'New Chat',\n ...(input?.model && { model: input.model }),\n ...(input?.systemPrompt && { systemPrompt: input.systemPrompt }),\n };\n\n const { data } = await createSessionMutation({\n variables: { input: inputWithId },\n update: (cache, { data: result }) => {\n if (!result?.createAccountChatSession) return;\n try {\n const existing = readSessionsCache(cache);\n if (existing?.getAccountChatSessions) {\n const newEdge = buildSessionEdge(result.createAccountChatSession);\n cache.writeQuery({\n query: GetAccountChatSessionsDocument,\n variables: SESSIONS_QUERY_VARS,\n data: {\n getAccountChatSessions: {\n ...existing.getAccountChatSessions,\n edges: [newEdge, ...existing.getAccountChatSessions.edges],\n totalCount: (existing.getAccountChatSessions.totalCount ?? 0) + 1,\n },\n },\n });\n }\n } catch (err) {\n console.warn('[useChatApi] createSession cache update failed:', err);\n }\n },\n });\n\n if (!data?.createAccountChatSession) {\n throw new Error('Failed to create session');\n }\n\n const s = data.createAccountChatSession;\n return {\n id: s.id,\n title: s.title ?? 'New Chat',\n createdAt: new Date(s.createdAt),\n updatedAt: new Date(s.updatedAt),\n };\n },\n [createSessionMutation],\n );\n\n const saveMessages = useCallback(\n async (input: IAccountSaveChatMessagesInput): Promise<void> => {\n const { data } = await saveMessagesMutation({\n variables: { input },\n update: (cache, { data: result }) => {\n if (!result?.saveAccountChatMessages) return;\n const res = result.saveAccountChatMessages;\n try {\n const existingMessages = readMessagesCache(cache, input.sessionId);\n if (existingMessages?.getAccountChatMessages) {\n const userEdge = buildMessageEdge(res.userMessage);\n const assistantEdge = buildMessageEdge(res.assistantMessage);\n cache.writeQuery({\n query: GetAccountChatMessagesDocument,\n variables: { sessionId: input.sessionId, first: 100 },\n data: {\n getAccountChatMessages: {\n ...existingMessages.getAccountChatMessages,\n edges: [\n ...existingMessages.getAccountChatMessages.edges,\n userEdge,\n assistantEdge,\n ],\n totalCount: (existingMessages.getAccountChatMessages.totalCount ?? 0) + 2,\n },\n },\n });\n }\n } catch (err) {\n console.warn('[useChatApi] saveMessages cache update failed:', err);\n }\n try {\n const existingSessions = readSessionsCache(cache);\n if (existingSessions?.getAccountChatSessions) {\n const sessionData = res.session;\n const updatedEdges = existingSessions.getAccountChatSessions.edges.map((edge: any) =>\n edge.node.id === sessionData.id\n ? { ...edge, node: { ...edge.node, ...sessionData } }\n : edge,\n );\n cache.writeQuery({\n query: GetAccountChatSessionsDocument,\n variables: SESSIONS_QUERY_VARS,\n data: {\n getAccountChatSessions: {\n ...existingSessions.getAccountChatSessions,\n edges: updatedEdges,\n },\n },\n });\n }\n } catch (err) {\n console.warn('[useChatApi] saveMessages session cache update failed:', err);\n }\n },\n });\n if (!data?.saveAccountChatMessages) {\n throw new Error('Failed to save messages');\n }\n },\n [saveMessagesMutation],\n );\n\n return {\n createSession,\n saveMessages,\n loading: { create: createLoading, saveMessages: saveMessagesLoading },\n };\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA,MAAM,mBAAsB,GAAA;AAAA,EAC1B,KAAO,EAAA,EAAA;AAAA,EACP,eAAiB,EAAA;AACnB,CAAA;AACA,SAAS,kBAAkB,KAA6B,EAAA;AACtD,EAAI,IAAA;AACF,IAAA,OAAO,MAAM,SAAU,CAAA;AAAA,MACrB,KAAO,EAAA,8BAAA;AAAA,MACP,SAAW,EAAA;AAAA,KACZ,CAAA;AAAA,GAMK,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,IAAA;AAAA;AAEX;AACA,SAAS,iBAAA,CAAkB,OAA6B,SAAmB,EAAA;AACzE,EAAI,IAAA;AACF,IAAA,OAAO,MAAM,SAAU,CAAA;AAAA,MACrB,KAAO,EAAA,8BAAA;AAAA,MACP,SAAW,EAAA;AAAA,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iBACT;AAAA;AACF,aACD,CAAA;AAAA;AACH,iBACO,GAAK,EAAA;AACZ,UAAQ,OAAA,CAAA,IAAA,CAAK,0DAA0D,GAAG,CAAA;AAAA;AAC5E;AACF,KACD,CAAA;AACD,IAAI,IAAA,EAAC,6BAAM,uBAAyB,CAAA,EAAA;AAClC,MAAM,MAAA,IAAI,MAAM,yBAAyB,CAAA;AAAA;AAC3C,GACF,EAAG,CAAC,oBAAoB,CAAC,CAAA;AACzB,EAAO,OAAA;AAAA,IACL,aAAA;AAAA,IACA,YAAA;AAAA,IACA,OAAS,EAAA;AAAA,MACP,MAAQ,EAAA,aAAA;AAAA,MACR,YAAc,EAAA;AAAA;AAChB,GACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useChatApi.js","sources":["../../src/hooks/useChatApi.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { AiAgentMessageRole, PostTypeEnum, RoomType, SortEnum } from 'common';\nimport {\n GetChannelsByUserWithLastMessageDocument,\n useAddChannelMutation,\n useGetChannelsByUserWithLastMessageQuery,\n useMessagesQuery,\n useSendMessagesMutation,\n} from 'common/graphql';\nimport type {\n IAccountCreateChatSessionInput,\n IAccountSaveChatMessagesInput as IAccountSaveChatMessagesInputBase,\n} from 'common/server';\nimport { useCallback, useMemo } from 'react';\nimport { v4 as uuidv4 } from 'uuid';\n\nconst MESSAGES_PAGE_LIMIT = 100;\n\n/** Same variables as web Inbox / AIAgent: list AI assistant channels for the current user. */\nexport const AI_ASSISTANT_CHANNELS_QUERY_VARS = {\n criteria: { type: RoomType.Aiassistant },\n limit: 100,\n skip: 0,\n sort: { key: 'updatedAt', value: SortEnum.Desc },\n};\n\nfunction stripModelCostHeader(content: string): string {\n const normalized = content.replace(/\\r\\n/g, '\\n');\n return normalized.replace(\n /^\\s*(?:[^\\w\\n]+\\s*)?[a-z0-9][a-z0-9._-]*\\s*\\(\\s*\\$[\\d.]+\\s*\\/\\s*MTok\\s+in\\s*\\)\\s*\\n+/i,\n '',\n );\n}\n\nfunction sanitizeAssistantContentByRole(role: unknown, content: string): string {\n return role === 'assistant' ? stripModelCostHeader(content) : content;\n}\n\nfunction omitContent<T extends Record<string, any>>(value: T | null | undefined): Omit<T, 'content'> {\n const clone = { ...(value ?? {}) } as Record<string, any>;\n delete clone.content;\n return clone as Omit<T, 'content'>;\n}\n\nexport interface ChatSessionUI {\n id: string;\n title: string;\n createdAt: Date;\n updatedAt: Date;\n messageCount?: number;\n}\n\nexport function useChatSessions(options?: { includeArchived?: boolean; skip?: boolean }) {\n const { data, loading, error, refetch } = useGetChannelsByUserWithLastMessageQuery({\n variables: AI_ASSISTANT_CHANNELS_QUERY_VARS,\n skip: options?.skip,\n fetchPolicy: 'cache-and-network',\n });\n\n const sessions: ChatSessionUI[] = useMemo(() => {\n const channels = data?.channelsByUser ?? [];\n return channels\n .filter((c): c is NonNullable<typeof c> => Boolean(c?.id))\n .map((channel) => ({\n id: channel.id,\n title: channel.title || channel.displayName || 'New Chat',\n createdAt: new Date(channel.createdAt ?? Date.now()),\n updatedAt: new Date(channel.updatedAt ?? Date.now()),\n messageCount: undefined,\n }));\n }, [data]);\n\n return { sessions, loading, error, refetch };\n}\n\nexport interface ChatMessageUI {\n id: string;\n sessionId: string;\n role: 'user' | 'assistant' | 'system';\n content: string;\n attachments?: Array<{ id: string; name: string; type: string; mimeType?: string; size?: number; url?: string }>;\n tokenCount?: number;\n model?: string;\n createdAt: Date;\n updatedAt: Date;\n}\n\ninterface MinimalFile {\n id?: string | null;\n name?: string | null;\n mimeType?: string | null;\n size?: number | null;\n url?: string | null;\n}\n\ninterface MinimalPost {\n id?: string | null;\n message?: string | null;\n createdAt?: string | null;\n updatedAt?: string | null;\n channel?: { id?: string | null } | null;\n files?: { data?: MinimalFile[] | null } | null;\n props?: { role?: string | null; tokenCount?: number | null; model?: string | null } | null;\n propsConfiguration?: {\n contents?: { role?: string | null } | null;\n content?: { role?: string | null } | null;\n } | null;\n}\n\nfunction mapPostToChatMessageUI(post: MinimalPost, fallbackChannelId: string): ChatMessageUI {\n const props = (post.props ?? {}) as Record<string, any>;\n const contents = post.propsConfiguration?.contents ?? {};\n const roleRaw = props.role ?? contents.role ?? post.propsConfiguration?.content?.role;\n let role: ChatMessageUI['role'] = 'assistant';\n if (roleRaw === 'user' || roleRaw === AiAgentMessageRole.User) role = 'user';\n else if (roleRaw === 'assistant' || roleRaw === AiAgentMessageRole.Assistant) role = 'assistant';\n else if (roleRaw === 'system') role = 'system';\n\n const rawContent = post?.message ?? '';\n const content = sanitizeAssistantContentByRole(role, rawContent);\n\n return {\n id: post?.id ?? uuidv4(),\n sessionId: post?.channel?.id ?? fallbackChannelId,\n role,\n content,\n attachments: (post?.files?.data ?? []).map((file) => ({\n id: file.id ?? uuidv4(),\n name: file.name ?? 'file',\n type: typeof file.mimeType === 'string' && file.mimeType.startsWith('image/') ? 'screenshot' : 'file',\n mimeType: file.mimeType ?? undefined,\n size: file.size ?? undefined,\n url: file.url ?? undefined,\n })),\n tokenCount: props.tokenCount ?? undefined,\n model: props.model ?? undefined,\n createdAt: post?.createdAt ? new Date(post.createdAt) : new Date(),\n updatedAt: post?.updatedAt ? new Date(post.updatedAt) : new Date(),\n };\n}\n\nexport function useChatMessages(sessionId: string | null, options?: { skip?: boolean }) {\n const { data, loading, error, refetch } = useMessagesQuery({\n variables: {\n channelId: sessionId ?? undefined,\n parentId: null,\n limit: MESSAGES_PAGE_LIMIT,\n skip: 0,\n },\n skip: !sessionId || options?.skip,\n fetchPolicy: 'cache-and-network',\n context: { cacheKey: 'messages-list' },\n });\n\n const messages: ChatMessageUI[] = useMemo(() => {\n if (!sessionId) return [];\n const rows = data?.messages?.data ?? [];\n return rows\n .map((post) => mapPostToChatMessageUI(post as MinimalPost, sessionId))\n .sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());\n }, [data, sessionId]);\n\n return { messages, loading, error, refetch };\n}\n\nexport type IAccountSaveChatMessagesInput = IAccountSaveChatMessagesInputBase & {\n mode?: 'plan' | 'build';\n createdBy?: string;\n};\n\nexport function useChatMutations() {\n const [addChannelMutation, { loading: createChannelLoading }] = useAddChannelMutation();\n const [sendMessagesMutation, { loading: sendMessagesLoading }] = useSendMessagesMutation();\n\n const createChannel = useCallback(\n async (input?: IAccountCreateChatSessionInput): Promise<ChatSessionUI> => {\n const {\n orgName: orgNameArg,\n projectId: projectIdArg,\n ...inputForSettings\n } = (input ?? {}) as IAccountCreateChatSessionInput & {\n orgName?: string | null;\n projectId?: string | null;\n };\n const orgName =\n typeof orgNameArg === 'string' && orgNameArg.trim().length > 0 ? orgNameArg.trim() : undefined;\n const projectId =\n typeof projectIdArg === 'string' && projectIdArg.trim().length > 0 ? projectIdArg.trim() : undefined;\n\n const settings = {\n title: input?.title ?? 'New Chat',\n description: input?.systemPrompt ?? null,\n isShared: false,\n sharedSlug: null,\n isArchived: false,\n isPinned: false,\n model: input?.model ?? null,\n systemPrompt: input?.systemPrompt ?? null,\n ...inputForSettings,\n };\n\n const { data } = await addChannelMutation({\n variables: {\n channelId: input?.id ?? null,\n name: input?.title ?? 'New Chat',\n description: input?.systemPrompt ?? null,\n type: RoomType.Aiassistant,\n settings,\n ...(orgName ? { orgName } : {}),\n ...(projectId ? { projectId } : {}),\n },\n refetchQueries: [\n { query: GetChannelsByUserWithLastMessageDocument, variables: AI_ASSISTANT_CHANNELS_QUERY_VARS },\n ],\n awaitRefetchQueries: true,\n });\n\n if (!data?.createChannel?.id) {\n throw new Error('Failed to create channel');\n }\n\n const channel = data.createChannel;\n const title = channel.title ?? input?.title ?? 'New Chat';\n const now = new Date();\n\n return {\n id: channel.id,\n title,\n createdAt: now,\n updatedAt: now,\n };\n },\n [addChannelMutation],\n );\n\n const saveMessages = useCallback(\n async (\n input: IAccountSaveChatMessagesInput,\n ): Promise<{\n userMessage: ChatMessageUI;\n assistantMessage: ChatMessageUI;\n session: ChatSessionUI;\n }> => {\n const sanitizedAssistantContent = stripModelCostHeader(input.assistantMessage.content ?? '');\n const assistantMessageWithoutContent = omitContent((input.assistantMessage as any) ?? {});\n const userResult = await sendMessagesMutation({\n variables: {\n channelId: input.sessionId,\n type: RoomType.Aiassistant,\n content: input.userMessage.content ?? '',\n ...(input.createdBy ? { createdBy: input.createdBy } : {}),\n extraProps: {\n type: PostTypeEnum.Aiassistant,\n role: 'user',\n attachments: input.userMessage.attachments ?? [],\n isActive: true,\n status: 'complete',\n ...(input.userMessage as any),\n ...(input.mode ? { mode: input.mode } : {}),\n },\n } as any,\n });\n const assistantResult = await sendMessagesMutation({\n variables: {\n channelId: input.sessionId,\n type: RoomType.Aiassistant,\n content: sanitizedAssistantContent,\n extraProps: {\n type: PostTypeEnum.Aiassistant,\n role: 'assistant',\n attachments: input.assistantMessage.attachments ?? [],\n tokenCount: input.assistantMessage.tokenCount,\n latencyMs: input.assistantMessage.latencyMs,\n model: input.assistantMessage.model,\n finishReason: (input.assistantMessage as any).finishReason ?? null,\n isActive: true,\n status: 'complete',\n ...assistantMessageWithoutContent,\n ...(input.mode ? { mode: input.mode } : {}),\n },\n } as any,\n });\n\n const userPost = userResult.data?.sendMessage;\n const assistantPost = assistantResult.data?.sendMessage;\n if (!userPost || !assistantPost) {\n throw new Error('Failed to send messages');\n }\n\n const now = new Date();\n return {\n userMessage: mapPostToChatMessageUI(userPost as MinimalPost, input.sessionId),\n assistantMessage: mapPostToChatMessageUI(assistantPost as MinimalPost, input.sessionId),\n session: {\n id: input.sessionId,\n title: 'Chat',\n createdAt: now,\n updatedAt: now,\n },\n };\n },\n [sendMessagesMutation],\n );\n\n return {\n createChannel,\n createSession: createChannel,\n saveMessages,\n loading: { create: createChannelLoading, saveMessages: sendMessagesLoading },\n };\n}\n"],"names":["_a","uuidv4","_b","_c","_d","_e"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,mBAAsB,GAAA,GAAA;AAGrB,MAAM,gCAAmC,GAAA;AAAA,EAC9C,QAAU,EAAA;AAAA,IACR,MAAM,QAAS,CAA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