@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.
Files changed (28) hide show
  1. package/dist/cjs/components/bik-copilot/services/copilotDb.js +1 -1
  2. package/dist/cjs/components/bik-copilot/services/copilotDb.js.map +1 -1
  3. package/dist/cjs/components/bik-copilot/services/copilotPageSession.js +1 -1
  4. package/dist/cjs/components/bik-copilot/services/copilotPageSession.js.map +1 -1
  5. package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js +1 -1
  6. package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js.map +1 -1
  7. package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.js +1 -1
  8. package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.js.map +1 -1
  9. package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.styled.js +19 -28
  10. package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.styled.js.map +1 -1
  11. package/dist/cjs/index.js +1 -1
  12. package/dist/esm/components/bik-copilot/index.d.ts +1 -1
  13. package/dist/esm/components/bik-copilot/services/copilotDb.d.ts +15 -17
  14. package/dist/esm/components/bik-copilot/services/copilotDb.js +49 -57
  15. package/dist/esm/components/bik-copilot/services/copilotDb.js.map +1 -1
  16. package/dist/esm/components/bik-copilot/services/copilotPageSession.d.ts +10 -13
  17. package/dist/esm/components/bik-copilot/services/copilotPageSession.js +22 -25
  18. package/dist/esm/components/bik-copilot/services/copilotPageSession.js.map +1 -1
  19. package/dist/esm/components/bik-copilot/useCopilotStreamChat.js +95 -96
  20. package/dist/esm/components/bik-copilot/useCopilotStreamChat.js.map +1 -1
  21. package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.js +44 -46
  22. package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.js.map +1 -1
  23. package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.d.ts +0 -3
  24. package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.js +15 -25
  25. package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.js.map +1 -1
  26. package/dist/esm/components/multi-level-dropdown/type.d.ts +0 -5
  27. package/dist/esm/index.js +49 -49
  28. package/package.json +1 -1
@@ -1,33 +1,30 @@
1
1
  /**
2
- * The session id for a route in this page load, created on first use and stable
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 getCopilotSessionIdForRoute: ({ route, storeId, }: {
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 route, resuming the stored conversation when this page
11
- * load has not seen the route yet.
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 route already in play keeps
14
- * its id without a database read; then the most recent stored conversation, which
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 `getCopilotSessionIdForRoute` anywhere persistence is on — the
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 resolveCopilotSessionIdForRoute: ({ route, storeId, }: {
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 route, leaving other routes untouched. The
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 resetCopilotSessionForRoute: ({ route, storeId, }: {
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 r, findLatestCopilotSessionId as d } from "./copilotDb.js";
2
- const e = /* @__PURE__ */ new Map(), c = (s, o) => `${s ?? ""}:${o}`, p = ({
3
- route: s,
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 t = c(o, s), n = e.get(t);
7
- if (n)
8
- return n;
9
- const i = r();
10
- return e.set(t, i), i;
11
- }, u = async ({
12
- route: s,
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 t = c(o, s), n = e.get(t);
16
- if (n)
17
- return n;
18
- const a = await d({ route: s, storeId: o }) ?? r();
19
- return e.set(t, a), a;
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
- route: s,
22
- storeId: o
19
+ storeId: s
23
20
  }) => {
24
- const t = r();
25
- return e.set(c(o, s), t), t;
21
+ const o = i();
22
+ return t.set(r(s), o), o;
26
23
  }, S = () => {
27
- e.clear();
24
+ t.clear();
28
25
  };
29
26
  export {
30
27
  S as clearCopilotPageSessions,
31
- p as getCopilotSessionIdForRoute,
32
- I as resetCopilotSessionForRoute,
33
- u as resolveCopilotSessionIdForRoute
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 **navigating away and back to the same route**\n * keeps the id and the copilot picks the conversation up where it was left.\n * Component state could not do this — the 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 `resolveCopilotSessionIdForRoute`, which reads the\n * route's most recent conversation out of IndexedDB before minting a new one.\n * That is 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 under `{sessionId}:{route}`; this\n * registry only decides which of those keys the copilot reads.\n */\nconst routeSessionIds = new Map<string, string>();\n\n/**\n * Registry key.\n *\n * The store is part of it, and each entry gets its own session id rather than a\n * shared per-page one — otherwise two stores on the same route would resolve to\n * the same `{sessionId}:{route}` record and show each other's conversation.\n */\nconst registryKey = (storeId: string | undefined, route: string) =>\n\t`${storeId ?? ''}:${route}`;\n\n/**\n * The session id for a route in this page load, created on first use and stable\n * for the rest of the page load.\n */\nexport const getCopilotSessionIdForRoute = ({\n\troute,\n\tstoreId,\n}: {\n\troute: string;\n\tstoreId?: string;\n}): string => {\n\tconst key = registryKey(storeId, route);\n\tconst existing = routeSessionIds.get(key);\n\tif (existing) {\n\t\treturn existing;\n\t}\n\tconst sessionId = createCopilotSessionId();\n\trouteSessionIds.set(key, sessionId);\n\treturn sessionId;\n};\n\n/**\n * The session id for a route, resuming the stored conversation when this page\n * load has not seen the route yet.\n *\n * Order matters: the in-memory registry first, so a route already in play keeps\n * its id without a database read; then the most recent stored conversation, which\n * is how a refresh resumes; and only then a new id.\n *\n * Prefer this over `getCopilotSessionIdForRoute` anywhere persistence is on — the\n * synchronous version cannot see the stored records, so it always starts fresh.\n */\nexport const resolveCopilotSessionIdForRoute = async ({\n\troute,\n\tstoreId,\n}: {\n\troute: string;\n\tstoreId?: string;\n}): Promise<string> => {\n\tconst key = registryKey(storeId, route);\n\tconst inPlay = routeSessionIds.get(key);\n\tif (inPlay) {\n\t\treturn inPlay;\n\t}\n\n\tconst stored = await findLatestCopilotSessionId({ route, storeId });\n\tconst sessionId = stored ?? createCopilotSessionId();\n\t// Registered either way, so a second mount in this page load skips the read.\n\trouteSessionIds.set(key, sessionId);\n\treturn sessionId;\n};\n\n/**\n * Starts a new conversation for one route, leaving other routes 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 resetCopilotSessionForRoute = ({\n\troute,\n\tstoreId,\n}: {\n\troute: string;\n\tstoreId?: string;\n}): string => {\n\tconst sessionId = createCopilotSessionId();\n\trouteSessionIds.set(registryKey(storeId, route), 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\trouteSessionIds.clear();\n};\n"],"names":["routeSessionIds","registryKey","storeId","route","getCopilotSessionIdForRoute","key","existing","sessionId","createCopilotSessionId","resolveCopilotSessionIdForRoute","inPlay","findLatestCopilotSessionId","resetCopilotSessionForRoute","clearCopilotPageSessions"],"mappings":";AAqBA,MAAMA,wBAAsB,IAAA,GAStBC,IAAc,CAACC,GAA6BC,MACjD,GAAGD,KAAW,EAAE,IAAIC,CAAK,IAMbC,IAA8B,CAAC;AAAA,EAC3C,OAAAD;AAAA,EACA,SAAAD;AACD,MAGc;AACb,QAAMG,IAAMJ,EAAYC,GAASC,CAAK,GAChCG,IAAWN,EAAgB,IAAIK,CAAG;AACxC,MAAIC;AACH,WAAOA;AAER,QAAMC,IAAYC,EAAA;AAClB,SAAAR,EAAgB,IAAIK,GAAKE,CAAS,GAC3BA;AACR,GAaaE,IAAkC,OAAO;AAAA,EACrD,OAAAN;AAAA,EACA,SAAAD;AACD,MAGuB;AACtB,QAAMG,IAAMJ,EAAYC,GAASC,CAAK,GAChCO,IAASV,EAAgB,IAAIK,CAAG;AACtC,MAAIK;AACH,WAAOA;AAIR,QAAMH,IADS,MAAMI,EAA2B,EAAE,OAAAR,GAAO,SAAAD,GAAS,KACtCM,EAAA;AAE5B,SAAAR,EAAgB,IAAIK,GAAKE,CAAS,GAC3BA;AACR,GAOaK,IAA8B,CAAC;AAAA,EAC3C,OAAAT;AAAA,EACA,SAAAD;AACD,MAGc;AACb,QAAMK,IAAYC,EAAA;AAClB,SAAAR,EAAgB,IAAIC,EAAYC,GAASC,CAAK,GAAGI,CAAS,GACnDA;AACR,GAMaM,IAA2B,MAAY;AACnD,EAAAb,EAAgB,MAAA;AACjB;"}
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 h, useRef as p, useCallback as a, useEffect as Y, useMemo as It } from "react";
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 { resetCopilotSessionForRoute as Ot, resolveCopilotSessionIdForRoute as Pt, getCopilotSessionIdForRoute as Mt } from "./services/copilotPageSession.js";
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: R = _t,
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: y,
20
+ sessionId: h,
21
21
  persist: l = !0,
22
- onError: S,
22
+ onError: w,
23
23
  onResponseComplete: V,
24
- onSessionIdChange: N,
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 [D, B] = h([]), [ot, tt] = h(
33
- y ?? null
34
- ), [P, v] = h(!1), [ct, et] = h(!0), [ut, M] = h(), [it, at] = h(), [lt, F] = h(!1), [$, g] = h(!1), f = p([]), z = p(void 0), C = p(null), u = p(null), T = p(y ?? null), k = p(R);
35
- k.current = R;
36
- const E = p(1), H = p(!1), i = a(
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, B(e);
39
+ f.current = e, D(e);
40
40
  },
41
41
  []
42
- ), O = a((t) => {
43
- z.current = t, at(t);
44
- }, []), I = a(() => {
45
- const t = T.current;
42
+ ), v = a((t) => {
43
+ $.current = t, at(t);
44
+ }, []), g = a(() => {
45
+ const t = C.current;
46
46
  !l || !t || yt({
47
- route: k.current,
47
+ route: z.current,
48
48
  sessionId: t,
49
49
  messages: f.current,
50
- previousResponseId: z.current,
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 G = a(async (t) => {
79
- const e = U.current, n = T.current;
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
- u.current?.(), u.current = null, C.current = null, v(!1), M(void 0), et(!0), g(!1), H.current = !1, F(!1);
100
- const n = y ?? (l ? await Pt({ route: R, storeId: c }) : Mt({ route: R, storeId: c })), r = l ? await Et(R, n) : null;
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 (T.current = n, tt(n), f.current = st(r?.messages ?? []), B(f.current), O(r?.previousResponseId), et(!1), N?.(n), f.current.length > 0) {
103
- E.current = 2, g(U.current.loadHistory);
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 (!y) {
107
- E.current = 1, g(!1);
106
+ if (!h) {
107
+ T.current = 1, R(!1);
108
108
  return;
109
109
  }
110
- E.current = 1;
110
+ T.current = 1;
111
111
  try {
112
- const s = await G(1);
112
+ const s = await F(1);
113
113
  if (t || !s)
114
114
  return;
115
- E.current = 2, i(() => s.messages), g(s.hasMore);
115
+ T.current = 2, u(() => s.messages), R(s.hasMore);
116
116
  } catch {
117
- g(!1);
117
+ R(!1);
118
118
  }
119
119
  }
120
120
  })(), () => {
121
121
  t = !0;
122
122
  };
123
123
  }, [
124
- R,
125
124
  c,
126
- y,
125
+ h,
127
126
  l,
128
- O,
129
- i,
130
- G
127
+ v,
128
+ u,
129
+ F
131
130
  ]);
132
131
  const ft = a(() => {
133
- if (H.current || !$)
132
+ if (M.current || !B)
134
133
  return;
135
- H.current = !0, F(!0);
136
- const t = E.current;
134
+ M.current = !0, k(!0);
135
+ const t = T.current;
137
136
  (async () => {
138
137
  try {
139
- const e = await G(t);
138
+ const e = await F(t);
140
139
  if (!e) {
141
- g(!1);
140
+ R(!1);
142
141
  return;
143
142
  }
144
- E.current = t + 1, g(e.hasMore), i((n) => {
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
- S?.(
154
+ w?.(
156
155
  e instanceof Error ? e : new Error(String(e))
157
156
  );
158
157
  } finally {
159
- H.current = !1, F(!1);
158
+ M.current = !1, k(!1);
160
159
  }
161
160
  })();
162
- }, [i, $, S, G]);
161
+ }, [u, B, w, F]);
163
162
  Y(() => {
164
163
  l && Ct();
165
- }, [l]), Y(() => () => u.current?.(), []);
166
- const w = a(
164
+ }, [l]), Y(() => () => i.current?.(), []);
165
+ const E = a(
167
166
  (t) => {
168
- const e = C.current;
169
- C.current = null, e && i(
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
- [i]
182
+ [u]
184
183
  ), rt = a(
185
184
  (t) => {
186
- const e = C.current;
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
- i(
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
- w((d) => ({
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
- })), O(o), I(), V?.({
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" && (M(Z(t).text || nt), w(), I());
223
+ t.type === "ERROR" && (P(Z(t).text || nt), E(), g());
225
224
  },
226
225
  [
227
- i,
228
- w,
226
+ u,
227
+ E,
229
228
  V,
230
- I,
231
- O
229
+ g,
230
+ v
232
231
  ]
233
232
  ), X = a(
234
233
  (t) => {
235
- const e = t.trim(), n = T.current;
236
- if (!e || !n || P)
234
+ const e = t.trim(), n = C.current;
235
+ if (!e || !n || O)
237
236
  return;
238
- M(void 0);
237
+ P(void 0);
239
238
  const r = Date.now(), s = `copilot-a-${r}`;
240
- C.current = s, i((o) => [
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
- ]), v(!0), I(), u.current = Ht(
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: R,
264
+ route: H,
266
265
  userPrompt: e,
267
266
  sessionId: n,
268
- previousResponseId: z.current,
267
+ previousResponseId: $.current,
269
268
  systemPrompt: Q
270
269
  },
271
270
  {
272
271
  onEvent: rt,
273
272
  onComplete: () => {
274
- w(), v(!1), u.current = null, I();
273
+ E(), S(!1), i.current = null, g();
275
274
  },
276
275
  onError: (o) => {
277
- M(o.message || nt), w(), v(!1), u.current = null, I(), S?.(o);
276
+ P(o.message || nt), E(), S(!1), i.current = null, g(), w?.(o);
278
277
  },
279
278
  onAbort: () => {
280
- w(), v(!1), u.current = null, I();
279
+ E(), S(!1), i.current = null, g();
281
280
  }
282
281
  }
283
282
  );
284
283
  },
285
284
  [
286
- i,
285
+ u,
287
286
  x,
288
287
  _,
289
288
  W,
290
289
  A,
291
290
  m,
292
- w,
291
+ E,
293
292
  L,
294
293
  rt,
295
294
  b,
296
- P,
297
- S,
298
- R,
299
- I,
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 = T.current;
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: k.current,
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
- S?.(
331
+ w?.(
333
332
  d instanceof Error ? d : new Error(String(d))
334
333
  );
335
334
  });
336
335
  },
337
- [S]
336
+ [w]
338
337
  ), mt = a(() => {
339
- if (!u.current)
338
+ if (!i.current)
340
339
  return;
341
- const t = C.current;
342
- t && i(
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
- ), u.current(), u.current = null;
347
- }, [i]), Rt = a(() => {
348
- u.current?.(), u.current = null, C.current = null, v(!1), M(void 0), E.current = 1, H.current = !1, F(!1), g(!1);
349
- const t = k.current, e = T.current, n = y ?? Ot({ route: t, storeId: c });
350
- T.current = n, tt(n), f.current = [], B([]), O(void 0), l && e && Tt(t, e), N?.(n);
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
- N,
351
+ G,
353
352
  l,
354
- y,
355
- O,
353
+ h,
354
+ v,
356
355
  c
357
356
  ]), gt = It(
358
- () => P && !D.some((t) => t.isStreaming && t.content),
359
- [P, D]
357
+ () => O && !N.some((t) => t.isStreaming && t.content),
358
+ [O, N]
360
359
  );
361
360
  return {
362
- messages: D,
361
+ messages: N,
363
362
  sessionId: ot,
364
- previousResponseId: it,
365
- isStreaming: P,
363
+ previousResponseId: ut,
364
+ isStreaming: O,
366
365
  isThinking: gt,
367
366
  isRestoring: ct,
368
367
  isLoadingHistory: lt,
369
- hasMoreHistory: $,
370
- error: ut,
368
+ hasMoreHistory: B,
369
+ error: it,
371
370
  sendMessage: X,
372
371
  regenerate: dt,
373
372
  submitFeedback: pt,