@bikdotai/bik-component-library 0.0.876-beta.3 → 0.0.877-beta.0
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/dist/cjs/components/bik-copilot/services/copilotDb.js +1 -1
- package/dist/cjs/components/bik-copilot/services/copilotDb.js.map +1 -1
- package/dist/cjs/components/bik-copilot/services/copilotPageSession.js +1 -1
- package/dist/cjs/components/bik-copilot/services/copilotPageSession.js.map +1 -1
- package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js +1 -1
- package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js.map +1 -1
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.js +1 -1
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.js.map +1 -1
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.styled.js +19 -28
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.styled.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/components/bik-copilot/index.d.ts +1 -1
- package/dist/esm/components/bik-copilot/services/copilotDb.d.ts +15 -17
- package/dist/esm/components/bik-copilot/services/copilotDb.js +49 -57
- package/dist/esm/components/bik-copilot/services/copilotDb.js.map +1 -1
- package/dist/esm/components/bik-copilot/services/copilotPageSession.d.ts +10 -13
- package/dist/esm/components/bik-copilot/services/copilotPageSession.js +22 -25
- package/dist/esm/components/bik-copilot/services/copilotPageSession.js.map +1 -1
- package/dist/esm/components/bik-copilot/useCopilotStreamChat.js +95 -96
- package/dist/esm/components/bik-copilot/useCopilotStreamChat.js.map +1 -1
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.js +44 -46
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.js.map +1 -1
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.d.ts +0 -3
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.js +15 -25
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.js.map +1 -1
- package/dist/esm/components/multi-level-dropdown/type.d.ts +0 -5
- package/dist/esm/index.js +49 -49
- package/package.json +1 -1
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The session id for a
|
|
2
|
+
* The session id for a store in this page load, created on first use and stable
|
|
3
3
|
* for the rest of the page load.
|
|
4
4
|
*/
|
|
5
|
-
export declare const
|
|
6
|
-
route: string;
|
|
5
|
+
export declare const getCopilotSessionId: ({ storeId, }: {
|
|
7
6
|
storeId?: string | undefined;
|
|
8
7
|
}) => string;
|
|
9
8
|
/**
|
|
10
|
-
* The session id for a
|
|
11
|
-
* load has not seen the
|
|
9
|
+
* The session id for a store, resuming the stored conversation when this page
|
|
10
|
+
* load has not seen the store yet.
|
|
12
11
|
*
|
|
13
|
-
* Order matters: the in-memory registry first, so a
|
|
14
|
-
* its id without a database read; then
|
|
12
|
+
* Order matters: the in-memory registry first, so a store already in play keeps
|
|
13
|
+
* its id without a database read; then its most recent stored conversation, which
|
|
15
14
|
* is how a refresh resumes; and only then a new id.
|
|
16
15
|
*
|
|
17
|
-
* Prefer this over `
|
|
16
|
+
* Prefer this over `getCopilotSessionId` anywhere persistence is on — the
|
|
18
17
|
* synchronous version cannot see the stored records, so it always starts fresh.
|
|
19
18
|
*/
|
|
20
|
-
export declare const
|
|
21
|
-
route: string;
|
|
19
|
+
export declare const resolveCopilotSessionId: ({ storeId, }: {
|
|
22
20
|
storeId?: string | undefined;
|
|
23
21
|
}) => Promise<string>;
|
|
24
22
|
/**
|
|
25
|
-
* Starts a new conversation for one
|
|
23
|
+
* Starts a new conversation for one store, leaving other stores untouched. The
|
|
26
24
|
* new id sticks for the rest of the page load, so navigating away and back does
|
|
27
25
|
* not resurrect the conversation the user just cleared.
|
|
28
26
|
*/
|
|
29
|
-
export declare const
|
|
30
|
-
route: string;
|
|
27
|
+
export declare const resetCopilotSession: ({ storeId, }: {
|
|
31
28
|
storeId?: string | undefined;
|
|
32
29
|
}) => string;
|
|
33
30
|
/**
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
import { createCopilotSessionId as
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
storeId: o
|
|
1
|
+
import { createCopilotSessionId as i, findLatestCopilotSessionId as a } from "./copilotDb.js";
|
|
2
|
+
const t = /* @__PURE__ */ new Map(), r = (s) => s ?? "", l = ({
|
|
3
|
+
storeId: s
|
|
5
4
|
}) => {
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
9
|
-
const
|
|
10
|
-
return
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
storeId: o
|
|
5
|
+
const o = r(s), e = t.get(o);
|
|
6
|
+
if (e)
|
|
7
|
+
return e;
|
|
8
|
+
const n = i();
|
|
9
|
+
return t.set(o, n), n;
|
|
10
|
+
}, p = async ({
|
|
11
|
+
storeId: s
|
|
14
12
|
}) => {
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
18
|
-
const
|
|
19
|
-
return
|
|
13
|
+
const o = r(s), e = t.get(o);
|
|
14
|
+
if (e)
|
|
15
|
+
return e;
|
|
16
|
+
const c = await a({ storeId: s }) ?? i();
|
|
17
|
+
return t.set(o, c), c;
|
|
20
18
|
}, I = ({
|
|
21
|
-
|
|
22
|
-
storeId: o
|
|
19
|
+
storeId: s
|
|
23
20
|
}) => {
|
|
24
|
-
const
|
|
25
|
-
return
|
|
21
|
+
const o = i();
|
|
22
|
+
return t.set(r(s), o), o;
|
|
26
23
|
}, S = () => {
|
|
27
|
-
|
|
24
|
+
t.clear();
|
|
28
25
|
};
|
|
29
26
|
export {
|
|
30
27
|
S as clearCopilotPageSessions,
|
|
31
|
-
|
|
32
|
-
I as
|
|
33
|
-
|
|
28
|
+
l as getCopilotSessionId,
|
|
29
|
+
I as resetCopilotSession,
|
|
30
|
+
p as resolveCopilotSessionId
|
|
34
31
|
};
|
|
35
32
|
//# sourceMappingURL=copilotPageSession.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilotPageSession.js","sources":["../../../../../src/components/bik-copilot/services/copilotPageSession.ts"],"sourcesContent":["import {\n\tcreateCopilotSessionId,\n\tfindLatestCopilotSessionId,\n} from './copilotDb';\n\n/**\n * Registry of the session ids in play for the current page load.\n *\n * Module-level and in-memory, so
|
|
1
|
+
{"version":3,"file":"copilotPageSession.js","sources":["../../../../../src/components/bik-copilot/services/copilotPageSession.ts"],"sourcesContent":["import {\n\tcreateCopilotSessionId,\n\tfindLatestCopilotSessionId,\n} from './copilotDb';\n\n/**\n * Registry of the session ids in play for the current page load.\n *\n * Module-level and in-memory, so the id survives the copilot unmounting —\n * **navigating between dashboard routes keeps one conversation**, and so does\n * closing the panel and opening it again. Component state could not do this: the\n * copilot unmounts on the way out.\n *\n * A **refresh** empties the registry, so the id has to be recovered from the\n * stored records instead: see `resolveCopilotSessionId`, which reads the store's\n * most recent conversation out of IndexedDB before minting a new one. That is\n * what makes history survive a reload, and it is why the id must not be\n * regenerated per page load any more.\n *\n * The transcripts themselves live in IndexedDB keyed by session id, each record\n * carrying the route it was last used on; this registry only decides which\n * session id the copilot reads.\n */\nconst storeSessionIds = new Map<string, string>();\n\n/**\n * Registry key: the store.\n *\n * One conversation per store rather than per route — the merchant moving from\n * Campaigns to Segments is still the same conversation, and the route only\n * decides which POD, Area and page knowledge the backend loads into the *next*\n * turn. Two stores stay separate, or they would resolve to one record and show\n * each other's conversation.\n */\nconst registryKey = (storeId: string | undefined) => storeId ?? '';\n\n/**\n * The session id for a store in this page load, created on first use and stable\n * for the rest of the page load.\n */\nexport const getCopilotSessionId = ({\n\tstoreId,\n}: {\n\tstoreId?: string;\n}): string => {\n\tconst key = registryKey(storeId);\n\tconst existing = storeSessionIds.get(key);\n\tif (existing) {\n\t\treturn existing;\n\t}\n\tconst sessionId = createCopilotSessionId();\n\tstoreSessionIds.set(key, sessionId);\n\treturn sessionId;\n};\n\n/**\n * The session id for a store, resuming the stored conversation when this page\n * load has not seen the store yet.\n *\n * Order matters: the in-memory registry first, so a store already in play keeps\n * its id without a database read; then its most recent stored conversation, which\n * is how a refresh resumes; and only then a new id.\n *\n * Prefer this over `getCopilotSessionId` anywhere persistence is on — the\n * synchronous version cannot see the stored records, so it always starts fresh.\n */\nexport const resolveCopilotSessionId = async ({\n\tstoreId,\n}: {\n\tstoreId?: string;\n}): Promise<string> => {\n\tconst key = registryKey(storeId);\n\tconst inPlay = storeSessionIds.get(key);\n\tif (inPlay) {\n\t\treturn inPlay;\n\t}\n\n\tconst stored = await findLatestCopilotSessionId({ storeId });\n\tconst sessionId = stored ?? createCopilotSessionId();\n\t// Registered either way, so a second mount in this page load skips the read.\n\tstoreSessionIds.set(key, sessionId);\n\treturn sessionId;\n};\n\n/**\n * Starts a new conversation for one store, leaving other stores untouched. The\n * new id sticks for the rest of the page load, so navigating away and back does\n * not resurrect the conversation the user just cleared.\n */\nexport const resetCopilotSession = ({\n\tstoreId,\n}: {\n\tstoreId?: string;\n}): string => {\n\tconst sessionId = createCopilotSessionId();\n\tstoreSessionIds.set(registryKey(storeId), sessionId);\n\treturn sessionId;\n};\n\n/**\n * Forgets every session id, as a reload would. Call it on logout or when the\n * signed-in user changes; tests use it to simulate a refresh.\n */\nexport const clearCopilotPageSessions = (): void => {\n\tstoreSessionIds.clear();\n};\n"],"names":["storeSessionIds","registryKey","storeId","getCopilotSessionId","key","existing","sessionId","createCopilotSessionId","resolveCopilotSessionId","inPlay","findLatestCopilotSessionId","resetCopilotSession","clearCopilotPageSessions"],"mappings":";AAuBA,MAAMA,wBAAsB,IAAA,GAWtBC,IAAc,CAACC,MAAgCA,KAAW,IAMnDC,IAAsB,CAAC;AAAA,EACnC,SAAAD;AACD,MAEc;AACb,QAAME,IAAMH,EAAYC,CAAO,GACzBG,IAAWL,EAAgB,IAAII,CAAG;AACxC,MAAIC;AACH,WAAOA;AAER,QAAMC,IAAYC,EAAA;AAClB,SAAAP,EAAgB,IAAII,GAAKE,CAAS,GAC3BA;AACR,GAaaE,IAA0B,OAAO;AAAA,EAC7C,SAAAN;AACD,MAEuB;AACtB,QAAME,IAAMH,EAAYC,CAAO,GACzBO,IAAST,EAAgB,IAAII,CAAG;AACtC,MAAIK;AACH,WAAOA;AAIR,QAAMH,IADS,MAAMI,EAA2B,EAAE,SAAAR,GAAS,KAC/BK,EAAA;AAE5B,SAAAP,EAAgB,IAAII,GAAKE,CAAS,GAC3BA;AACR,GAOaK,IAAsB,CAAC;AAAA,EACnC,SAAAT;AACD,MAEc;AACb,QAAMI,IAAYC,EAAA;AAClB,SAAAP,EAAgB,IAAIC,EAAYC,CAAO,GAAGI,CAAS,GAC5CA;AACR,GAMaM,IAA2B,MAAY;AACnD,EAAAZ,EAAgB,MAAA;AACjB;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as I, useRef as p, useCallback as a, useEffect as Y, useMemo as It } from "react";
|
|
2
2
|
import { COPILOT_REGENERATE_PROMPT as ht } from "./copilotRegenerate.js";
|
|
3
3
|
import { persistCopilotTurn as yt, pruneCopilotSessions as Ct, deleteCopilotSession as Tt, loadCopilotSession as Et } from "./services/copilotDb.js";
|
|
4
4
|
import { sendCopilotFeedback as wt } from "./services/copilotFeedbackClient.js";
|
|
5
5
|
import { fetchCopilotMessages as St, COPILOT_HISTORY_PAGE_SIZE as vt } from "./services/copilotMessagesClient.js";
|
|
6
|
-
import {
|
|
6
|
+
import { resetCopilotSession as Ot, resolveCopilotSessionId as Pt, getCopilotSessionId as Mt } from "./services/copilotPageSession.js";
|
|
7
7
|
import { readCopilotEventContent as Z, streamCopilotChat as Ht } from "./services/copilotStreamClient.js";
|
|
8
8
|
import { DEFAULT_COPILOT_ROUTE as _t, DEFAULT_COPILOT_AGENT as bt } from "./useCopilotIcebreakers.js";
|
|
9
9
|
const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
@@ -11,17 +11,17 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
11
11
|
), Dt = ({
|
|
12
12
|
storeId: c,
|
|
13
13
|
agent: m = bt,
|
|
14
|
-
route:
|
|
14
|
+
route: H = _t,
|
|
15
15
|
messagesPath: j,
|
|
16
16
|
feedbackPath: q,
|
|
17
17
|
user: J,
|
|
18
18
|
loadHistory: K = !0,
|
|
19
19
|
systemPrompt: Q,
|
|
20
|
-
sessionId:
|
|
20
|
+
sessionId: h,
|
|
21
21
|
persist: l = !0,
|
|
22
|
-
onError:
|
|
22
|
+
onError: w,
|
|
23
23
|
onResponseComplete: V,
|
|
24
|
-
onSessionIdChange:
|
|
24
|
+
onSessionIdChange: G,
|
|
25
25
|
baseUrl: _,
|
|
26
26
|
endpointPath: W,
|
|
27
27
|
headers: b,
|
|
@@ -29,25 +29,25 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
29
29
|
getAuthToken: L,
|
|
30
30
|
fetchImpl: A
|
|
31
31
|
}) => {
|
|
32
|
-
const [
|
|
33
|
-
|
|
34
|
-
), [
|
|
35
|
-
|
|
36
|
-
const
|
|
32
|
+
const [N, D] = I([]), [ot, tt] = I(
|
|
33
|
+
h ?? null
|
|
34
|
+
), [O, S] = I(!1), [ct, et] = I(!0), [it, P] = I(), [ut, at] = I(), [lt, k] = I(!1), [B, R] = I(!1), f = p([]), $ = p(void 0), y = p(null), i = p(null), C = p(h ?? null), z = p(H);
|
|
35
|
+
z.current = H;
|
|
36
|
+
const T = p(1), M = p(!1), u = a(
|
|
37
37
|
(t) => {
|
|
38
38
|
const e = t(f.current);
|
|
39
|
-
f.current = e,
|
|
39
|
+
f.current = e, D(e);
|
|
40
40
|
},
|
|
41
41
|
[]
|
|
42
|
-
),
|
|
43
|
-
|
|
44
|
-
}, []),
|
|
45
|
-
const t =
|
|
42
|
+
), v = a((t) => {
|
|
43
|
+
$.current = t, at(t);
|
|
44
|
+
}, []), g = a(() => {
|
|
45
|
+
const t = C.current;
|
|
46
46
|
!l || !t || yt({
|
|
47
|
-
route:
|
|
47
|
+
route: z.current,
|
|
48
48
|
sessionId: t,
|
|
49
49
|
messages: f.current,
|
|
50
|
-
previousResponseId:
|
|
50
|
+
previousResponseId: $.current,
|
|
51
51
|
storeId: c,
|
|
52
52
|
agent: m
|
|
53
53
|
});
|
|
@@ -75,8 +75,8 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
75
75
|
loadHistory: K,
|
|
76
76
|
user: J
|
|
77
77
|
};
|
|
78
|
-
const
|
|
79
|
-
const e = U.current, n =
|
|
78
|
+
const F = a(async (t) => {
|
|
79
|
+
const e = U.current, n = C.current;
|
|
80
80
|
if (!e.loadHistory || !n)
|
|
81
81
|
return null;
|
|
82
82
|
const r = await St({
|
|
@@ -96,52 +96,51 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
96
96
|
Y(() => {
|
|
97
97
|
let t = !1;
|
|
98
98
|
return (async () => {
|
|
99
|
-
|
|
100
|
-
const n =
|
|
99
|
+
i.current?.(), i.current = null, y.current = null, S(!1), P(void 0), et(!0), R(!1), M.current = !1, k(!1);
|
|
100
|
+
const n = h ?? (l ? await Pt({ storeId: c }) : Mt({ storeId: c })), r = l ? await Et(n) : null;
|
|
101
101
|
if (!t) {
|
|
102
|
-
if (
|
|
103
|
-
|
|
102
|
+
if (C.current = n, tt(n), f.current = st(r?.messages ?? []), D(f.current), v(r?.previousResponseId), et(!1), G?.(n), f.current.length > 0) {
|
|
103
|
+
T.current = 2, R(U.current.loadHistory);
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
if (!
|
|
107
|
-
|
|
106
|
+
if (!h) {
|
|
107
|
+
T.current = 1, R(!1);
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
T.current = 1;
|
|
111
111
|
try {
|
|
112
|
-
const s = await
|
|
112
|
+
const s = await F(1);
|
|
113
113
|
if (t || !s)
|
|
114
114
|
return;
|
|
115
|
-
|
|
115
|
+
T.current = 2, u(() => s.messages), R(s.hasMore);
|
|
116
116
|
} catch {
|
|
117
|
-
|
|
117
|
+
R(!1);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
})(), () => {
|
|
121
121
|
t = !0;
|
|
122
122
|
};
|
|
123
123
|
}, [
|
|
124
|
-
R,
|
|
125
124
|
c,
|
|
126
|
-
|
|
125
|
+
h,
|
|
127
126
|
l,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
v,
|
|
128
|
+
u,
|
|
129
|
+
F
|
|
131
130
|
]);
|
|
132
131
|
const ft = a(() => {
|
|
133
|
-
if (
|
|
132
|
+
if (M.current || !B)
|
|
134
133
|
return;
|
|
135
|
-
|
|
136
|
-
const t =
|
|
134
|
+
M.current = !0, k(!0);
|
|
135
|
+
const t = T.current;
|
|
137
136
|
(async () => {
|
|
138
137
|
try {
|
|
139
|
-
const e = await
|
|
138
|
+
const e = await F(t);
|
|
140
139
|
if (!e) {
|
|
141
|
-
|
|
140
|
+
R(!1);
|
|
142
141
|
return;
|
|
143
142
|
}
|
|
144
|
-
|
|
143
|
+
T.current = t + 1, R(e.hasMore), u((n) => {
|
|
145
144
|
const r = new Set(
|
|
146
145
|
n.flatMap(
|
|
147
146
|
(o) => o.messageId ? [o.id, o.messageId] : [o.id]
|
|
@@ -152,21 +151,21 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
152
151
|
return s.length > 0 ? [...s, ...n] : n;
|
|
153
152
|
});
|
|
154
153
|
} catch (e) {
|
|
155
|
-
|
|
154
|
+
w?.(
|
|
156
155
|
e instanceof Error ? e : new Error(String(e))
|
|
157
156
|
);
|
|
158
157
|
} finally {
|
|
159
|
-
|
|
158
|
+
M.current = !1, k(!1);
|
|
160
159
|
}
|
|
161
160
|
})();
|
|
162
|
-
}, [
|
|
161
|
+
}, [u, B, w, F]);
|
|
163
162
|
Y(() => {
|
|
164
163
|
l && Ct();
|
|
165
|
-
}, [l]), Y(() => () =>
|
|
166
|
-
const
|
|
164
|
+
}, [l]), Y(() => () => i.current?.(), []);
|
|
165
|
+
const E = a(
|
|
167
166
|
(t) => {
|
|
168
|
-
const e =
|
|
169
|
-
|
|
167
|
+
const e = y.current;
|
|
168
|
+
y.current = null, e && u(
|
|
170
169
|
(n) => n.map((r) => {
|
|
171
170
|
if (r.id !== e)
|
|
172
171
|
return r;
|
|
@@ -180,15 +179,15 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
180
179
|
)
|
|
181
180
|
);
|
|
182
181
|
},
|
|
183
|
-
[
|
|
182
|
+
[u]
|
|
184
183
|
), rt = a(
|
|
185
184
|
(t) => {
|
|
186
|
-
const e =
|
|
185
|
+
const e = y.current;
|
|
187
186
|
if (t.type === "STREAM") {
|
|
188
187
|
const n = Z(t).text;
|
|
189
188
|
if (!e || !n)
|
|
190
189
|
return;
|
|
191
|
-
|
|
190
|
+
u(
|
|
192
191
|
(r) => r.map(
|
|
193
192
|
(s) => s.id === e ? {
|
|
194
193
|
...s,
|
|
@@ -206,7 +205,7 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
206
205
|
toolResults: s,
|
|
207
206
|
responseId: o
|
|
208
207
|
} = Z(t);
|
|
209
|
-
|
|
208
|
+
E((d) => ({
|
|
210
209
|
...d,
|
|
211
210
|
content: n,
|
|
212
211
|
messageId: t.messageId ?? d.messageId,
|
|
@@ -214,30 +213,30 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
214
213
|
// Kept on the message, not just handled in passing, so the
|
|
215
214
|
// action button is still there after a reload.
|
|
216
215
|
...s ? { toolResults: s } : {}
|
|
217
|
-
})),
|
|
216
|
+
})), v(o), g(), V?.({
|
|
218
217
|
text: n,
|
|
219
218
|
responseId: o,
|
|
220
219
|
followUps: r
|
|
221
220
|
});
|
|
222
221
|
return;
|
|
223
222
|
}
|
|
224
|
-
t.type === "ERROR" && (
|
|
223
|
+
t.type === "ERROR" && (P(Z(t).text || nt), E(), g());
|
|
225
224
|
},
|
|
226
225
|
[
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
u,
|
|
227
|
+
E,
|
|
229
228
|
V,
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
g,
|
|
230
|
+
v
|
|
232
231
|
]
|
|
233
232
|
), X = a(
|
|
234
233
|
(t) => {
|
|
235
|
-
const e = t.trim(), n =
|
|
236
|
-
if (!e || !n ||
|
|
234
|
+
const e = t.trim(), n = C.current;
|
|
235
|
+
if (!e || !n || O)
|
|
237
236
|
return;
|
|
238
|
-
|
|
237
|
+
P(void 0);
|
|
239
238
|
const r = Date.now(), s = `copilot-a-${r}`;
|
|
240
|
-
|
|
239
|
+
y.current = s, u((o) => [
|
|
241
240
|
...o,
|
|
242
241
|
{
|
|
243
242
|
id: `copilot-u-${r}`,
|
|
@@ -252,7 +251,7 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
252
251
|
timestamp: r + 1,
|
|
253
252
|
isStreaming: !0
|
|
254
253
|
}
|
|
255
|
-
]),
|
|
254
|
+
]), S(!0), g(), i.current = Ht(
|
|
256
255
|
{
|
|
257
256
|
baseUrl: _,
|
|
258
257
|
endpointPath: W,
|
|
@@ -262,41 +261,41 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
262
261
|
fetchImpl: A,
|
|
263
262
|
storeId: c,
|
|
264
263
|
agent: m,
|
|
265
|
-
route:
|
|
264
|
+
route: H,
|
|
266
265
|
userPrompt: e,
|
|
267
266
|
sessionId: n,
|
|
268
|
-
previousResponseId:
|
|
267
|
+
previousResponseId: $.current,
|
|
269
268
|
systemPrompt: Q
|
|
270
269
|
},
|
|
271
270
|
{
|
|
272
271
|
onEvent: rt,
|
|
273
272
|
onComplete: () => {
|
|
274
|
-
|
|
273
|
+
E(), S(!1), i.current = null, g();
|
|
275
274
|
},
|
|
276
275
|
onError: (o) => {
|
|
277
|
-
|
|
276
|
+
P(o.message || nt), E(), S(!1), i.current = null, g(), w?.(o);
|
|
278
277
|
},
|
|
279
278
|
onAbort: () => {
|
|
280
|
-
|
|
279
|
+
E(), S(!1), i.current = null, g();
|
|
281
280
|
}
|
|
282
281
|
}
|
|
283
282
|
);
|
|
284
283
|
},
|
|
285
284
|
[
|
|
286
|
-
|
|
285
|
+
u,
|
|
287
286
|
x,
|
|
288
287
|
_,
|
|
289
288
|
W,
|
|
290
289
|
A,
|
|
291
290
|
m,
|
|
292
|
-
|
|
291
|
+
E,
|
|
293
292
|
L,
|
|
294
293
|
rt,
|
|
295
294
|
b,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
295
|
+
O,
|
|
296
|
+
w,
|
|
297
|
+
H,
|
|
298
|
+
g,
|
|
300
299
|
c,
|
|
301
300
|
Q
|
|
302
301
|
]
|
|
@@ -306,7 +305,7 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
306
305
|
) && X(ht);
|
|
307
306
|
}, [X]), pt = a(
|
|
308
307
|
(t, e, n) => {
|
|
309
|
-
const r = U.current, s =
|
|
308
|
+
const r = U.current, s = C.current;
|
|
310
309
|
if (!s)
|
|
311
310
|
return;
|
|
312
311
|
const o = f.current.find(
|
|
@@ -323,51 +322,51 @@ const nt = "Something went wrong. Please try again.", st = (c) => c.map(
|
|
|
323
322
|
sessionId: s,
|
|
324
323
|
messageId: t,
|
|
325
324
|
feedback: e,
|
|
326
|
-
route:
|
|
325
|
+
route: z.current,
|
|
327
326
|
reply: o?.content,
|
|
328
327
|
user: r.user,
|
|
329
328
|
reasons: n?.reasons,
|
|
330
329
|
comment: n?.comment
|
|
331
330
|
}).catch((d) => {
|
|
332
|
-
|
|
331
|
+
w?.(
|
|
333
332
|
d instanceof Error ? d : new Error(String(d))
|
|
334
333
|
);
|
|
335
334
|
});
|
|
336
335
|
},
|
|
337
|
-
[
|
|
336
|
+
[w]
|
|
338
337
|
), mt = a(() => {
|
|
339
|
-
if (!
|
|
338
|
+
if (!i.current)
|
|
340
339
|
return;
|
|
341
|
-
const t =
|
|
342
|
-
t &&
|
|
340
|
+
const t = y.current;
|
|
341
|
+
t && u(
|
|
343
342
|
(e) => e.map(
|
|
344
343
|
(n) => n.id === t ? { ...n, wasInterrupted: !0 } : n
|
|
345
344
|
)
|
|
346
|
-
),
|
|
347
|
-
}, [
|
|
348
|
-
|
|
349
|
-
const t =
|
|
350
|
-
|
|
345
|
+
), i.current(), i.current = null;
|
|
346
|
+
}, [u]), Rt = a(() => {
|
|
347
|
+
i.current?.(), i.current = null, y.current = null, S(!1), P(void 0), T.current = 1, M.current = !1, k(!1), R(!1);
|
|
348
|
+
const t = C.current, e = h ?? Ot({ storeId: c });
|
|
349
|
+
C.current = e, tt(e), f.current = [], D([]), v(void 0), l && t && Tt(t), G?.(e);
|
|
351
350
|
}, [
|
|
352
|
-
|
|
351
|
+
G,
|
|
353
352
|
l,
|
|
354
|
-
|
|
355
|
-
|
|
353
|
+
h,
|
|
354
|
+
v,
|
|
356
355
|
c
|
|
357
356
|
]), gt = It(
|
|
358
|
-
() =>
|
|
359
|
-
[
|
|
357
|
+
() => O && !N.some((t) => t.isStreaming && t.content),
|
|
358
|
+
[O, N]
|
|
360
359
|
);
|
|
361
360
|
return {
|
|
362
|
-
messages:
|
|
361
|
+
messages: N,
|
|
363
362
|
sessionId: ot,
|
|
364
|
-
previousResponseId:
|
|
365
|
-
isStreaming:
|
|
363
|
+
previousResponseId: ut,
|
|
364
|
+
isStreaming: O,
|
|
366
365
|
isThinking: gt,
|
|
367
366
|
isRestoring: ct,
|
|
368
367
|
isLoadingHistory: lt,
|
|
369
|
-
hasMoreHistory:
|
|
370
|
-
error:
|
|
368
|
+
hasMoreHistory: B,
|
|
369
|
+
error: it,
|
|
371
370
|
sendMessage: X,
|
|
372
371
|
regenerate: dt,
|
|
373
372
|
submitFeedback: pt,
|