@bikdotai/bik-component-library 0.0.862 → 0.0.863-beta.1

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 (92) hide show
  1. package/dist/cjs/components/bik-copilot/BIKCopilot.js +2 -0
  2. package/dist/cjs/components/bik-copilot/BIKCopilot.js.map +1 -0
  3. package/dist/cjs/components/bik-copilot/ControlledCopilot.js +2 -0
  4. package/dist/cjs/components/bik-copilot/ControlledCopilot.js.map +1 -0
  5. package/dist/cjs/components/bik-copilot/ControlledCopilot.styled.js +27 -0
  6. package/dist/cjs/components/bik-copilot/ControlledCopilot.styled.js.map +1 -0
  7. package/dist/cjs/components/bik-copilot/CopilotBall.js +2 -0
  8. package/dist/cjs/components/bik-copilot/CopilotBall.js.map +1 -0
  9. package/dist/cjs/components/bik-copilot/CopilotBall.styled.js +42 -0
  10. package/dist/cjs/components/bik-copilot/CopilotBall.styled.js.map +1 -0
  11. package/dist/cjs/components/bik-copilot/CopilotPanel.js +2 -0
  12. package/dist/cjs/components/bik-copilot/CopilotPanel.js.map +1 -0
  13. package/dist/cjs/components/bik-copilot/CopilotPanel.styled.js +460 -0
  14. package/dist/cjs/components/bik-copilot/CopilotPanel.styled.js.map +1 -0
  15. package/dist/cjs/components/bik-copilot/copilotPlacement.js +2 -0
  16. package/dist/cjs/components/bik-copilot/copilotPlacement.js.map +1 -0
  17. package/dist/cjs/components/bik-copilot/services/copilotDb.js +2 -0
  18. package/dist/cjs/components/bik-copilot/services/copilotDb.js.map +1 -0
  19. package/dist/cjs/components/bik-copilot/services/copilotIcebreakersClient.js +2 -0
  20. package/dist/cjs/components/bik-copilot/services/copilotIcebreakersClient.js.map +1 -0
  21. package/dist/cjs/components/bik-copilot/services/copilotMessagesClient.js +2 -0
  22. package/dist/cjs/components/bik-copilot/services/copilotMessagesClient.js.map +1 -0
  23. package/dist/cjs/components/bik-copilot/services/copilotPageSession.js +2 -0
  24. package/dist/cjs/components/bik-copilot/services/copilotPageSession.js.map +1 -0
  25. package/dist/cjs/components/bik-copilot/services/copilotSseParser.js +7 -0
  26. package/dist/cjs/components/bik-copilot/services/copilotSseParser.js.map +1 -0
  27. package/dist/cjs/components/bik-copilot/services/copilotStreamClient.js +2 -0
  28. package/dist/cjs/components/bik-copilot/services/copilotStreamClient.js.map +1 -0
  29. package/dist/cjs/components/bik-copilot/useCopilotIcebreakers.js +2 -0
  30. package/dist/cjs/components/bik-copilot/useCopilotIcebreakers.js.map +1 -0
  31. package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js +2 -0
  32. package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js.map +1 -0
  33. package/dist/cjs/components/bik-copilot/useDraggableFloater.js +2 -0
  34. package/dist/cjs/components/bik-copilot/useDraggableFloater.js.map +1 -0
  35. package/dist/cjs/index.js +1 -1
  36. package/dist/esm/components/bik-copilot/BIKCopilot.d.ts +32 -0
  37. package/dist/esm/components/bik-copilot/BIKCopilot.js +114 -0
  38. package/dist/esm/components/bik-copilot/BIKCopilot.js.map +1 -0
  39. package/dist/esm/components/bik-copilot/ControlledCopilot.d.ts +14 -0
  40. package/dist/esm/components/bik-copilot/ControlledCopilot.js +170 -0
  41. package/dist/esm/components/bik-copilot/ControlledCopilot.js.map +1 -0
  42. package/dist/esm/components/bik-copilot/ControlledCopilot.styled.d.ts +7 -0
  43. package/dist/esm/components/bik-copilot/ControlledCopilot.styled.js +31 -0
  44. package/dist/esm/components/bik-copilot/ControlledCopilot.styled.js.map +1 -0
  45. package/dist/esm/components/bik-copilot/CopilotBall.d.ts +13 -0
  46. package/dist/esm/components/bik-copilot/CopilotBall.js +50 -0
  47. package/dist/esm/components/bik-copilot/CopilotBall.js.map +1 -0
  48. package/dist/esm/components/bik-copilot/CopilotBall.styled.d.ts +9 -0
  49. package/dist/esm/components/bik-copilot/CopilotBall.styled.js +46 -0
  50. package/dist/esm/components/bik-copilot/CopilotBall.styled.js.map +1 -0
  51. package/dist/esm/components/bik-copilot/CopilotPanel.d.ts +9 -0
  52. package/dist/esm/components/bik-copilot/CopilotPanel.js +379 -0
  53. package/dist/esm/components/bik-copilot/CopilotPanel.js.map +1 -0
  54. package/dist/esm/components/bik-copilot/CopilotPanel.styled.d.ts +64 -0
  55. package/dist/esm/components/bik-copilot/CopilotPanel.styled.js +496 -0
  56. package/dist/esm/components/bik-copilot/CopilotPanel.styled.js.map +1 -0
  57. package/dist/esm/components/bik-copilot/copilotPlacement.d.ts +24 -0
  58. package/dist/esm/components/bik-copilot/copilotPlacement.js +38 -0
  59. package/dist/esm/components/bik-copilot/copilotPlacement.js.map +1 -0
  60. package/dist/esm/components/bik-copilot/index.d.ts +16 -0
  61. package/dist/esm/components/bik-copilot/model.d.ts +674 -0
  62. package/dist/esm/components/bik-copilot/services/copilotDb.d.ts +90 -0
  63. package/dist/esm/components/bik-copilot/services/copilotDb.js +96 -0
  64. package/dist/esm/components/bik-copilot/services/copilotDb.js.map +1 -0
  65. package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.d.ts +11 -0
  66. package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.js +54 -0
  67. package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.js.map +1 -0
  68. package/dist/esm/components/bik-copilot/services/copilotMessagesClient.d.ts +23 -0
  69. package/dist/esm/components/bik-copilot/services/copilotMessagesClient.js +78 -0
  70. package/dist/esm/components/bik-copilot/services/copilotMessagesClient.js.map +1 -0
  71. package/dist/esm/components/bik-copilot/services/copilotPageSession.d.ts +37 -0
  72. package/dist/esm/components/bik-copilot/services/copilotPageSession.js +35 -0
  73. package/dist/esm/components/bik-copilot/services/copilotPageSession.js.map +1 -0
  74. package/dist/esm/components/bik-copilot/services/copilotSseParser.d.ts +22 -0
  75. package/dist/esm/components/bik-copilot/services/copilotSseParser.js +52 -0
  76. package/dist/esm/components/bik-copilot/services/copilotSseParser.js.map +1 -0
  77. package/dist/esm/components/bik-copilot/services/copilotStreamClient.d.ts +31 -0
  78. package/dist/esm/components/bik-copilot/services/copilotStreamClient.js +103 -0
  79. package/dist/esm/components/bik-copilot/services/copilotStreamClient.js.map +1 -0
  80. package/dist/esm/components/bik-copilot/useCopilotIcebreakers.d.ts +17 -0
  81. package/dist/esm/components/bik-copilot/useCopilotIcebreakers.js +60 -0
  82. package/dist/esm/components/bik-copilot/useCopilotIcebreakers.js.map +1 -0
  83. package/dist/esm/components/bik-copilot/useCopilotStreamChat.d.ts +20 -0
  84. package/dist/esm/components/bik-copilot/useCopilotStreamChat.js +333 -0
  85. package/dist/esm/components/bik-copilot/useCopilotStreamChat.js.map +1 -0
  86. package/dist/esm/components/bik-copilot/useDraggableFloater.d.ts +9 -0
  87. package/dist/esm/components/bik-copilot/useDraggableFloater.js +118 -0
  88. package/dist/esm/components/bik-copilot/useDraggableFloater.js.map +1 -0
  89. package/dist/esm/index.d.ts +1 -0
  90. package/dist/esm/index.js +832 -782
  91. package/dist/esm/index.js.map +1 -1
  92. package/package.json +1 -1
@@ -0,0 +1,103 @@
1
+ import { CopilotSseParser as g } from "./copilotSseParser.js";
2
+ const v = "/bik-ai/copilot-chatbot", C = (t) => ({
3
+ store_id: t.storeId,
4
+ agent: t.agent,
5
+ route: t.route,
6
+ user_prompt: t.userPrompt,
7
+ session_id: t.sessionId,
8
+ // Trimmed, then left out rather than sent empty: the backend reads a missing
9
+ // key as "no signed-in user", which a blank string would not.
10
+ ...t.email?.trim() ? { email: t.email.trim() } : {},
11
+ // Omitted on the first turn; from the second turn on it is the `responseId`
12
+ // of the previous TEXT event, which is how OpenAI keeps the thread's context.
13
+ ...t.previousResponseId ? { previous_response_id: t.previousResponseId } : {},
14
+ ...t.systemPrompt ? { system_prompt: t.systemPrompt } : {},
15
+ ...t.model ? { model: t.model } : {},
16
+ ...t.maxOutputTokens ? { max_output_tokens: t.maxOutputTokens } : {}
17
+ }), P = (t) => {
18
+ const { content: o } = t;
19
+ if (typeof o == "string")
20
+ return { text: o };
21
+ if (!o || typeof o != "object")
22
+ return { text: "" };
23
+ const e = Array.isArray(o.followUps) ? o.followUps.filter(
24
+ (c) => typeof c == "string" && c.trim().length > 0
25
+ ) : void 0;
26
+ return {
27
+ text: typeof o.message == "string" ? o.message : "",
28
+ ...e && e.length > 0 ? { followUps: e } : {}
29
+ };
30
+ }, x = (t) => {
31
+ try {
32
+ const o = JSON.parse(t);
33
+ if (typeof o != "object" || o === null)
34
+ return null;
35
+ const e = o;
36
+ return e.type ? e : null;
37
+ } catch {
38
+ return null;
39
+ }
40
+ }, k = ({
41
+ baseUrl: t,
42
+ endpointPath: o = v,
43
+ headers: e,
44
+ authToken: c,
45
+ getAuthToken: m,
46
+ fetchImpl: h,
47
+ ...w
48
+ }, p) => {
49
+ const l = new AbortController();
50
+ return (async () => {
51
+ const i = `${t.replace(/\/$/, "")}${o}`, f = m ? await m() : c, a = await (h ?? fetch)(i, {
52
+ method: "POST",
53
+ headers: {
54
+ "Content-Type": "application/json",
55
+ Accept: "text/event-stream",
56
+ ...f ? { authorization: f } : {},
57
+ ...e
58
+ },
59
+ body: JSON.stringify(C(w)),
60
+ signal: l.signal
61
+ });
62
+ if (!a.ok) {
63
+ const n = await a.text().catch(() => "");
64
+ throw new Error(
65
+ `Copilot request failed with ${a.status}${n ? `: ${n}` : ""}`
66
+ );
67
+ }
68
+ if (!a.body)
69
+ throw new Error("Copilot response carried no stream body");
70
+ const b = a.body.getReader(), u = new g();
71
+ let d;
72
+ const y = (n) => {
73
+ n.forEach((r) => {
74
+ const s = x(r);
75
+ s && p.onEvent(s);
76
+ });
77
+ };
78
+ for (; ; ) {
79
+ const { done: n, value: r } = await b.read();
80
+ if (n)
81
+ break;
82
+ if (r === void 0)
83
+ continue;
84
+ let s;
85
+ typeof r == "string" ? s = r : (d = d ?? new TextDecoder(), s = d.decode(r, { stream: !0 })), y(u.push(s));
86
+ }
87
+ y(u.flush());
88
+ })().then(() => p.onComplete?.()).catch((i) => {
89
+ if (l.signal.aborted) {
90
+ p.onAbort?.();
91
+ return;
92
+ }
93
+ p.onError?.(
94
+ i instanceof Error ? i : new Error(String(i))
95
+ );
96
+ }), () => l.abort();
97
+ };
98
+ export {
99
+ v as COPILOT_ENDPOINT_PATH,
100
+ P as readCopilotEventContent,
101
+ k as streamCopilotChat
102
+ };
103
+ //# sourceMappingURL=copilotStreamClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilotStreamClient.js","sources":["../../../../../src/components/bik-copilot/services/copilotStreamClient.ts"],"sourcesContent":["import {\n\tCopilotStreamEvent,\n\tCopilotStreamHandlers,\n\tCopilotStreamRequest,\n\tStreamCopilotChatOptions,\n} from '../model';\nimport { CopilotSseParser } from './copilotSseParser';\n\n/** Default path of the streaming copilot endpoint. */\nexport const COPILOT_ENDPOINT_PATH = '/bik-ai/copilot-chatbot';\n\nconst buildRequestBody = (request: CopilotStreamRequest) => ({\n\tstore_id: request.storeId,\n\tagent: request.agent,\n\troute: request.route,\n\tuser_prompt: request.userPrompt,\n\tsession_id: request.sessionId,\n\t// Trimmed, then left out rather than sent empty: the backend reads a missing\n\t// key as \"no signed-in user\", which a blank string would not.\n\t...(request.email?.trim() ? { email: request.email.trim() } : {}),\n\t// Omitted on the first turn; from the second turn on it is the `responseId`\n\t// of the previous TEXT event, which is how OpenAI keeps the thread's context.\n\t...(request.previousResponseId\n\t\t? { previous_response_id: request.previousResponseId }\n\t\t: {}),\n\t...(request.systemPrompt ? { system_prompt: request.systemPrompt } : {}),\n\t...(request.model ? { model: request.model } : {}),\n\t...(request.maxOutputTokens\n\t\t? { max_output_tokens: request.maxOutputTokens }\n\t\t: {}),\n});\n\n/**\n * Reads an event's `content`, which the backend sends two ways: a bare string on\n * `STREAM` and `ERROR`, and an `{ type, message, followUps }` payload on `TEXT`.\n *\n * Anything unrecognised reads as empty text rather than throwing, so a shape the\n * backend adds later cannot break a turn that is otherwise fine.\n */\nexport const readCopilotEventContent = (\n\tevent: CopilotStreamEvent,\n): { text: string; followUps?: string[] } => {\n\tconst { content } = event;\n\n\tif (typeof content === 'string') {\n\t\treturn { text: content };\n\t}\n\tif (!content || typeof content !== 'object') {\n\t\treturn { text: '' };\n\t}\n\n\tconst followUps = Array.isArray(content.followUps)\n\t\t? content.followUps.filter(\n\t\t\t\t(followUp): followUp is string =>\n\t\t\t\t\ttypeof followUp === 'string' && followUp.trim().length > 0,\n\t\t )\n\t\t: undefined;\n\n\treturn {\n\t\ttext: typeof content.message === 'string' ? content.message : '',\n\t\t...(followUps && followUps.length > 0 ? { followUps } : {}),\n\t};\n};\n\nconst parseEvent = (payload: string): CopilotStreamEvent | null => {\n\ttry {\n\t\tconst parsed = JSON.parse(payload) as unknown;\n\t\tif (typeof parsed !== 'object' || parsed === null) {\n\t\t\treturn null;\n\t\t}\n\t\tconst event = parsed as CopilotStreamEvent;\n\t\treturn event.type ? event : null;\n\t} catch {\n\t\t// A frame that is not JSON is not something this endpoint emits; dropping\n\t\t// it is better than tearing down a stream that is otherwise fine.\n\t\treturn null;\n\t}\n};\n\n/**\n * Opens one streaming copilot turn and drives the handlers until the server\n * closes the stream.\n *\n * The endpoint's `STOP` never reaches the client as a frame — the server breaks\n * out of its generator, which ends the HTTP stream. So \"the reader is done\" is\n * what completion means here, and `onComplete` fires from there.\n *\n * `TEXT` carries the **whole** message, so it is authoritative: a caller should\n * replace the text accumulated from `STREAM` chunks with it rather than append.\n * When a turn fails halfway the server still sends `TEXT` with the partial\n * answer but **without** `responseId` — that intentionally drops the thread, so\n * the next turn must start fresh.\n *\n * @returns a function that aborts the in-flight stream.\n */\nexport const streamCopilotChat = (\n\t{\n\t\tbaseUrl,\n\t\tendpointPath = COPILOT_ENDPOINT_PATH,\n\t\theaders,\n\t\tauthToken,\n\t\tgetAuthToken,\n\t\tfetchImpl,\n\t\t...request\n\t}: StreamCopilotChatOptions,\n\thandlers: CopilotStreamHandlers,\n): (() => void) => {\n\tconst abortController = new AbortController();\n\n\tconst run = async () => {\n\t\tconst url = `${baseUrl.replace(/\\/$/, '')}${endpointPath}`;\n\t\tconst token = getAuthToken ? await getAuthToken() : authToken;\n\t\tconst doFetch = fetchImpl ?? fetch;\n\n\t\tconst response = await doFetch(url, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\tAccept: 'text/event-stream',\n\t\t\t\t...(token ? { authorization: token } : {}),\n\t\t\t\t...headers,\n\t\t\t},\n\t\t\tbody: JSON.stringify(buildRequestBody(request)),\n\t\t\tsignal: abortController.signal,\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst detail = await response.text().catch(() => '');\n\t\t\tthrow new Error(\n\t\t\t\t`Copilot request failed with ${response.status}${\n\t\t\t\t\tdetail ? `: ${detail}` : ''\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t\tif (!response.body) {\n\t\t\tthrow new Error('Copilot response carried no stream body');\n\t\t}\n\n\t\tconst reader = response.body.getReader();\n\t\tconst parser = new CopilotSseParser();\n\t\tlet decoder: TextDecoder | undefined;\n\n\t\tconst dispatch = (payloads: string[]) => {\n\t\t\tpayloads.forEach((payload) => {\n\t\t\t\tconst event = parseEvent(payload);\n\t\t\t\tif (event) {\n\t\t\t\t\thandlers.onEvent(event);\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (value === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Tests feed strings; the network feeds bytes.\n\t\t\tlet chunk: string;\n\t\t\tif (typeof value === 'string') {\n\t\t\t\tchunk = value;\n\t\t\t} else {\n\t\t\t\tdecoder = decoder ?? new TextDecoder();\n\t\t\t\tchunk = decoder.decode(value, { stream: true });\n\t\t\t}\n\t\t\tdispatch(parser.push(chunk));\n\t\t}\n\n\t\tdispatch(parser.flush());\n\t};\n\n\trun()\n\t\t.then(() => handlers.onComplete?.())\n\t\t.catch((error: unknown) => {\n\t\t\tif (abortController.signal.aborted) {\n\t\t\t\thandlers.onAbort?.();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\thandlers.onError?.(\n\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t);\n\t\t});\n\n\treturn () => abortController.abort();\n};\n"],"names":["COPILOT_ENDPOINT_PATH","buildRequestBody","request","readCopilotEventContent","event","content","followUps","followUp","parseEvent","payload","parsed","streamCopilotChat","baseUrl","endpointPath","headers","authToken","getAuthToken","fetchImpl","handlers","abortController","url","token","response","detail","reader","parser","CopilotSseParser","decoder","dispatch","payloads","done","value","chunk","error"],"mappings":";AASO,MAAMA,IAAwB,2BAE/BC,IAAmB,CAACC,OAAmC;AAAA,EAC5D,UAAUA,EAAQ;AAAA,EAClB,OAAOA,EAAQ;AAAA,EACf,OAAOA,EAAQ;AAAA,EACf,aAAaA,EAAQ;AAAA,EACrB,YAAYA,EAAQ;AAAA;AAAA;AAAA,EAGpB,GAAIA,EAAQ,OAAO,SAAS,EAAE,OAAOA,EAAQ,MAAM,KAAA,EAAK,IAAM,CAAA;AAAA;AAAA;AAAA,EAG9D,GAAIA,EAAQ,qBACT,EAAE,sBAAsBA,EAAQ,mBAAA,IAChC,CAAA;AAAA,EACH,GAAIA,EAAQ,eAAe,EAAE,eAAeA,EAAQ,aAAA,IAAiB,CAAA;AAAA,EACrE,GAAIA,EAAQ,QAAQ,EAAE,OAAOA,EAAQ,MAAA,IAAU,CAAA;AAAA,EAC/C,GAAIA,EAAQ,kBACT,EAAE,mBAAmBA,EAAQ,gBAAA,IAC7B,CAAA;AACJ,IASaC,IAA0B,CACtCC,MAC4C;AAC5C,QAAM,EAAE,SAAAC,MAAYD;AAEpB,MAAI,OAAOC,KAAY;AACtB,WAAO,EAAE,MAAMA,EAAA;AAEhB,MAAI,CAACA,KAAW,OAAOA,KAAY;AAClC,WAAO,EAAE,MAAM,GAAA;AAGhB,QAAMC,IAAY,MAAM,QAAQD,EAAQ,SAAS,IAC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nD,YAAM,IAAI;AAAA,QACT,+BAA+BA,EAAS,MAAM,GAC7CC,IAAS,KAAKA,CAAM,KAAK,EAC1B;AAAA,MAAA;AAAA,IAEF;AACA,QAAI,CAACD,EAAS;AACb,YAAM,IAAI,MAAM,yCAAyC;AAG1D,UAAME,IAASF,EAAS,KAAK,UAAA,GACvBG,IAAS,IAAIC,EAAA;AACnB,QAAIC;AAEJ,UAAMC,IAAW,CAACC,MAAuB;AACxC,MAAAA,EAAS,QAAQ,CAACpB,MAAY;AAC7B,cAAML,IAAQI,EAAWC,CAAO;AAChC,QAAIL,KACHc,EAAS,QAAQd,CAAK;AAAA,MAExB,CAAC;AAAA,IACF;AAGA,eAAa;AACZ,YAAM,EAAE,MAAA0B,GAAM,OAAAC,EAAA,IAAU,MAAMP,EAAO,KAAA;AACrC,UAAIM;AACH;AAED,UAAIC,MAAU;AACb;AAGD,UAAIC;AACJ,MAAI,OAAOD,KAAU,WACpBC,IAAQD,KAERJ,IAAUA,KAAW,IAAI,YAAA,GACzBK,IAAQL,EAAQ,OAAOI,GAAO,EAAE,QAAQ,IAAM,IAE/CH,EAASH,EAAO,KAAKO,CAAK,CAAC;AAAA,IAC5B;AAEA,IAAAJ,EAASH,EAAO,OAAO;AAAA,EACxB,GAEA,EACE,KAAK,MAAMP,EAAS,cAAc,EAClC,MAAM,CAACe,MAAmB;AAC1B,QAAId,EAAgB,OAAO,SAAS;AACnC,MAAAD,EAAS,UAAA;AACT;AAAA,IACD;AACA,IAAAA,EAAS;AAAA,MACRe,aAAiB,QAAQA,IAAQ,IAAI,MAAM,OAAOA,CAAK,CAAC;AAAA,IAAA;AAAA,EAE1D,CAAC,GAEK,MAAMd,EAAgB,MAAA;AAC9B;"}
@@ -0,0 +1,17 @@
1
+ import { UseCopilotIcebreakersOptions, UseCopilotIcebreakersResult } from './model';
2
+ /** Agent hardcoded until more than one exists server side. */
3
+ export declare const DEFAULT_COPILOT_AGENT = "BIK_ASSISTANT_AGENT";
4
+ /**
5
+ * Placeholder route. Replace it with the route the merchant is actually on —
6
+ * the backend resolves both the ice breakers and the turn's page knowledge from
7
+ * it, so a stale value means the copilot answers about the wrong page.
8
+ */
9
+ export declare const DEFAULT_COPILOT_ROUTE = "campaigns/overview";
10
+ /**
11
+ * Loads the suggested opening prompts for a route and maps them into the shape
12
+ * the panel's suggestion chips take.
13
+ *
14
+ * Refetches whenever `agent` or `route` changes, so the chips follow the
15
+ * merchant as they navigate, and aborts the in-flight request when they do.
16
+ */
17
+ export declare const useCopilotIcebreakers: ({ baseUrl, icebreakersPath, headers, authToken, getAuthToken, fetchImpl, agent, route, storeId, enabled, }: UseCopilotIcebreakersOptions) => UseCopilotIcebreakersResult;
@@ -0,0 +1,60 @@
1
+ import { useState as o, useRef as L, useEffect as R, useCallback as _, useMemo as N } from "react";
2
+ import { fetchCopilotIcebreakers as O } from "./services/copilotIcebreakersClient.js";
3
+ const S = "BIK_ASSISTANT_AGENT", v = "campaigns/overview", F = ({
4
+ baseUrl: n,
5
+ icebreakersPath: a,
6
+ headers: m,
7
+ authToken: p,
8
+ getAuthToken: T,
9
+ fetchImpl: g,
10
+ agent: i = S,
11
+ route: c = v,
12
+ storeId: l,
13
+ enabled: u = !0
14
+ }) => {
15
+ const [t, d] = o(null), [k, s] = o(!1), [A, f] = o(), [C, E] = o(0), b = L(null);
16
+ R(() => {
17
+ if (!u)
18
+ return;
19
+ const e = new AbortController();
20
+ return b.current?.abort(), b.current = e, s(!0), f(void 0), O({
21
+ baseUrl: n,
22
+ endpointPath: a,
23
+ headers: m,
24
+ authToken: p,
25
+ getAuthToken: T,
26
+ fetchImpl: g,
27
+ agent: i,
28
+ route: c,
29
+ storeId: l,
30
+ signal: e.signal
31
+ }).then((r) => {
32
+ e.signal.aborted || (d(r), s(!1));
33
+ }).catch((r) => {
34
+ e.signal.aborted || (f(
35
+ r instanceof Error ? r.message : String(r)
36
+ ), s(!1));
37
+ }), () => e.abort();
38
+ }, [i, c, l, u, n, a, C]);
39
+ const I = _(() => E((e) => e + 1), []);
40
+ return {
41
+ icebreakers: N(
42
+ () => (t?.icebreakers ?? []).map((e, r) => ({
43
+ id: `copilot-icebreaker-${r}`,
44
+ text: e
45
+ })),
46
+ [t]
47
+ ),
48
+ pageName: t?.pageName,
49
+ matchedRoute: t?.route,
50
+ isLoading: k,
51
+ error: A,
52
+ refresh: I
53
+ };
54
+ };
55
+ export {
56
+ S as DEFAULT_COPILOT_AGENT,
57
+ v as DEFAULT_COPILOT_ROUTE,
58
+ F as useCopilotIcebreakers
59
+ };
60
+ //# sourceMappingURL=useCopilotIcebreakers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCopilotIcebreakers.js","sources":["../../../../src/components/bik-copilot/useCopilotIcebreakers.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n\tCopilotIcebreakersResult,\n\tUseCopilotIcebreakersOptions,\n\tUseCopilotIcebreakersResult,\n} from './model';\nimport { fetchCopilotIcebreakers } from './services/copilotIcebreakersClient';\n\n/** Agent hardcoded until more than one exists server side. */\nexport const DEFAULT_COPILOT_AGENT = 'BIK_ASSISTANT_AGENT';\n\n/**\n * Placeholder route. Replace it with the route the merchant is actually on —\n * the backend resolves both the ice breakers and the turn's page knowledge from\n * it, so a stale value means the copilot answers about the wrong page.\n */\nexport const DEFAULT_COPILOT_ROUTE = 'campaigns/overview';\n\n/**\n * Loads the suggested opening prompts for a route and maps them into the shape\n * the panel's suggestion chips take.\n *\n * Refetches whenever `agent` or `route` changes, so the chips follow the\n * merchant as they navigate, and aborts the in-flight request when they do.\n */\nexport const useCopilotIcebreakers = ({\n\tbaseUrl,\n\ticebreakersPath,\n\theaders,\n\tauthToken,\n\tgetAuthToken,\n\tfetchImpl,\n\tagent = DEFAULT_COPILOT_AGENT,\n\troute = DEFAULT_COPILOT_ROUTE,\n\tstoreId,\n\tenabled = true,\n}: UseCopilotIcebreakersOptions): UseCopilotIcebreakersResult => {\n\tconst [result, setResult] = useState<CopilotIcebreakersResult | null>(null);\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<string | undefined>();\n\tconst [reloadToken, setReloadToken] = useState(0);\n\n\tconst abortRef = useRef<AbortController | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!enabled) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst abortController = new AbortController();\n\t\tabortRef.current?.abort();\n\t\tabortRef.current = abortController;\n\n\t\tsetIsLoading(true);\n\t\tsetError(undefined);\n\n\t\tfetchCopilotIcebreakers({\n\t\t\tbaseUrl,\n\t\t\tendpointPath: icebreakersPath,\n\t\t\theaders,\n\t\t\tauthToken,\n\t\t\tgetAuthToken,\n\t\t\tfetchImpl,\n\t\t\tagent,\n\t\t\troute,\n\t\t\tstoreId,\n\t\t\tsignal: abortController.signal,\n\t\t})\n\t\t\t.then((fetched) => {\n\t\t\t\tif (abortController.signal.aborted) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsetResult(fetched);\n\t\t\t\tsetIsLoading(false);\n\t\t\t})\n\t\t\t.catch((fetchError: unknown) => {\n\t\t\t\tif (abortController.signal.aborted) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsetError(\n\t\t\t\t\tfetchError instanceof Error ? fetchError.message : String(fetchError),\n\t\t\t\t);\n\t\t\t\tsetIsLoading(false);\n\t\t\t});\n\n\t\treturn () => abortController.abort();\n\t\t// The transport options are stable config in practice; re-running on a new\n\t\t// inline `headers` object would refetch on every render.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [agent, route, storeId, enabled, baseUrl, icebreakersPath, reloadToken]);\n\n\tconst refresh = useCallback(() => setReloadToken((token) => token + 1), []);\n\n\tconst icebreakers = useMemo(\n\t\t() =>\n\t\t\t(result?.icebreakers ?? []).map((text, index) => ({\n\t\t\t\tid: `copilot-icebreaker-${index}`,\n\t\t\t\ttext,\n\t\t\t})),\n\t\t[result],\n\t);\n\n\treturn {\n\t\ticebreakers,\n\t\tpageName: result?.pageName,\n\t\tmatchedRoute: result?.route,\n\t\tisLoading,\n\t\terror,\n\t\trefresh,\n\t};\n};\n"],"names":["DEFAULT_COPILOT_AGENT","DEFAULT_COPILOT_ROUTE","useCopilotIcebreakers","baseUrl","icebreakersPath","headers","authToken","getAuthToken","fetchImpl","agent","route","storeId","enabled","result","setResult","useState","isLoading","setIsLoading","error","setError","reloadToken","setReloadToken","abortRef","useRef","useEffect","abortController","fetchCopilotIcebreakers","fetched","fetchError","refresh","useCallback","token","useMemo","text","index"],"mappings":";;AASO,MAAMA,IAAwB,uBAOxBC,IAAwB,sBASxBC,IAAwB,CAAC;AAAA,EACrC,SAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,WAAAC;AAAA,EACA,cAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC,IAAQT;AAAA,EACR,OAAAU,IAAQT;AAAA,EACR,SAAAU;AAAA,EACA,SAAAC,IAAU;AACX,MAAiE;AAChE,QAAM,CAACC,GAAQC,CAAS,IAAIC,EAA0C,IAAI,GACpE,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK,GAC1C,CAACG,GAAOC,CAAQ,IAAIJ,EAAA,GACpB,CAACK,GAAaC,CAAc,IAAIN,EAAS,CAAC,GAE1CO,IAAWC,EAA+B,IAAI;AAEpD,EAAAC,EAAU,MAAM;AACf,QAAI,CAACZ;AACJ;AAGD,UAAMa,IAAkB,IAAI,gBAAA;AAC5B,WAAAH,EAAS,SAAS,MAAA,GAClBA,EAAS,UAAUG,GAEnBR,EAAa,EAAI,GACjBE,EAAS,MAAS,GAElBO,EAAwB;AAAA,MACvB,SAAAvB;AAAA,MACA,cAAcC;AAAA,MACd,SAAAC;AAAA,MACA,WAAAC;AAAA,MACA,cAAAC;AAAA,MACA,WAAAC;AAAA,MACA,OAAAC;AAAA,MACA,OAAAC;AAAA,MACA,SAAAC;AAAA,MACA,QAAQc,EAAgB;AAAA,IAAA,CACxB,EACC,KAAK,CAACE,MAAY;AAClB,MAAIF,EAAgB,OAAO,YAG3BX,EAAUa,CAAO,GACjBV,EAAa,EAAK;AAAA,IACnB,CAAC,EACA,MAAM,CAACW,MAAwB;AAC/B,MAAIH,EAAgB,OAAO,YAG3BN;AAAA,QACCS,aAAsB,QAAQA,EAAW,UAAU,OAAOA,CAAU;AAAA,MAAA,GAErEX,EAAa,EAAK;AAAA,IACnB,CAAC,GAEK,MAAMQ,EAAgB,MAAA;AAAA,EAI9B,GAAG,CAAChB,GAAOC,GAAOC,GAASC,GAAST,GAASC,GAAiBgB,CAAW,CAAC;AAE1E,QAAMS,IAAUC,EAAY,MAAMT,EAAe,CAACU,MAAUA,IAAQ,CAAC,GAAG,EAAE;AAW1E,SAAO;AAAA,IACN,aAVmBC;AAAA,MACnB,OACEnB,GAAQ,eAAe,CAAA,GAAI,IAAI,CAACoB,GAAMC,OAAW;AAAA,QACjD,IAAI,sBAAsBA,CAAK;AAAA,QAC/B,MAAAD;AAAA,MAAA,EACC;AAAA,MACH,CAACpB,CAAM;AAAA,IAAA;AAAA,IAKP,UAAUA,GAAQ;AAAA,IAClB,cAAcA,GAAQ;AAAA,IACtB,WAAAG;AAAA,IACA,OAAAE;AAAA,IACA,SAAAW;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,20 @@
1
+ import { UseCopilotStreamChatOptions, UseCopilotStreamChatResult } from './model';
2
+ /**
3
+ * Runs a merchant copilot conversation against the streaming
4
+ * `/bik-ai/copilot-chatbot` endpoint.
5
+ *
6
+ * Owns three things the endpoint's contract requires:
7
+ *
8
+ * 1. **The session id.** One per route. Navigating away and back to the same
9
+ * route continues that conversation, and so does a refresh: the ids live in
10
+ * memory but are recovered from the stored records, which is what keeps them
11
+ * lined up with the history the backend keys by them (see
12
+ * `copilotPageSession`).
13
+ * 2. **`previousResponseId`.** Absent on the first turn; from then on it is the
14
+ * `responseId` of the last `TEXT` event, which is what makes OpenAI replay the
15
+ * earlier turns server side. A turn that breaks halfway returns no
16
+ * `responseId`, and the backend means that — the next turn starts fresh.
17
+ * 3. **The transcript**, stored in IndexedDB under `{sessionId}:{route}` and
18
+ * written every turn, so leaving the page mid-conversation loses nothing.
19
+ */
20
+ export declare const useCopilotStreamChat: ({ storeId, agent, route, email, messagesPath, loadHistory, systemPrompt, model, maxOutputTokens, sessionId: pinnedSessionId, persist, onError, onResponseComplete, onSessionIdChange, baseUrl, endpointPath, headers, authToken, getAuthToken, fetchImpl, }: UseCopilotStreamChatOptions) => UseCopilotStreamChatResult;
@@ -0,0 +1,333 @@
1
+ import { useState as g, useRef as f, useCallback as a, useEffect as z, useMemo as Rt } from "react";
2
+ import { persistCopilotTurn as gt, pruneCopilotSessions as mt, deleteCopilotSession as It, loadCopilotSession as yt } from "./services/copilotDb.js";
3
+ import { fetchCopilotMessages as Ct, COPILOT_HISTORY_PAGE_SIZE as Et } from "./services/copilotMessagesClient.js";
4
+ import { resetCopilotSessionForRoute as wt, resolveCopilotSessionIdForRoute as St, getCopilotSessionIdForRoute as ht } from "./services/copilotPageSession.js";
5
+ import { readCopilotEventContent as X, streamCopilotChat as vt } from "./services/copilotStreamClient.js";
6
+ import { DEFAULT_COPILOT_ROUTE as Mt, DEFAULT_COPILOT_AGENT as Tt } from "./useCopilotIcebreakers.js";
7
+ const et = "Something went wrong. Please try again.", bt = ({
8
+ storeId: u,
9
+ agent: H = Tt,
10
+ route: d = Mt,
11
+ email: Y,
12
+ messagesPath: Z,
13
+ loadHistory: j = !0,
14
+ systemPrompt: q,
15
+ model: J,
16
+ maxOutputTokens: K,
17
+ sessionId: m,
18
+ persist: l = !0,
19
+ onError: O,
20
+ onResponseComplete: Q,
21
+ onSessionIdChange: D,
22
+ baseUrl: P,
23
+ endpointPath: V,
24
+ headers: x,
25
+ authToken: L,
26
+ getAuthToken: _,
27
+ fetchImpl: b
28
+ }) => {
29
+ const [G, N] = g([]), [nt, W] = g(
30
+ m ?? null
31
+ ), [v, w] = g(!1), [st, tt] = g(!0), [ot, M] = g(), [ct, ut] = g(), [it, A] = g(!1), [U, p] = g(!1), I = f([]), B = f(void 0), y = f(null), o = f(null), S = f(m ?? null), $ = f(d);
32
+ $.current = d;
33
+ const C = f(1), T = f(!1), c = a(
34
+ (t) => {
35
+ const r = t(I.current);
36
+ I.current = r, N(r);
37
+ },
38
+ []
39
+ ), h = a((t) => {
40
+ B.current = t, ut(t);
41
+ }, []), R = a(() => {
42
+ const t = S.current;
43
+ !l || !t || gt({
44
+ route: $.current,
45
+ sessionId: t,
46
+ messages: I.current,
47
+ previousResponseId: B.current,
48
+ storeId: u,
49
+ agent: H
50
+ });
51
+ }, [H, l, u]), k = f({
52
+ baseUrl: P,
53
+ messagesPath: Z,
54
+ headers: x,
55
+ authToken: L,
56
+ getAuthToken: _,
57
+ fetchImpl: b,
58
+ storeId: u,
59
+ loadHistory: j
60
+ });
61
+ k.current = {
62
+ baseUrl: P,
63
+ messagesPath: Z,
64
+ headers: x,
65
+ authToken: L,
66
+ getAuthToken: _,
67
+ fetchImpl: b,
68
+ storeId: u,
69
+ loadHistory: j
70
+ };
71
+ const F = a(async (t) => {
72
+ const r = k.current, e = S.current;
73
+ return !r.loadHistory || !e ? null : Ct({
74
+ baseUrl: r.baseUrl,
75
+ endpointPath: r.messagesPath,
76
+ headers: r.headers,
77
+ authToken: r.authToken,
78
+ getAuthToken: r.getAuthToken,
79
+ fetchImpl: r.fetchImpl,
80
+ storeId: r.storeId,
81
+ sessionId: e,
82
+ page: t,
83
+ pageSize: Et
84
+ });
85
+ }, []);
86
+ z(() => {
87
+ let t = !1;
88
+ return (async () => {
89
+ o.current?.(), o.current = null, y.current = null, w(!1), M(void 0), tt(!0), p(!1), T.current = !1, A(!1);
90
+ const e = m ?? (l ? await St({ route: d, storeId: u }) : ht({ route: d, storeId: u })), n = l ? await yt(d, e) : null;
91
+ if (!t) {
92
+ if (S.current = e, W(e), I.current = n?.messages ?? [], N(I.current), h(n?.previousResponseId), tt(!1), D?.(e), I.current.length > 0) {
93
+ C.current = 2, p(k.current.loadHistory);
94
+ return;
95
+ }
96
+ if (!m) {
97
+ C.current = 1, p(!1);
98
+ return;
99
+ }
100
+ C.current = 1;
101
+ try {
102
+ const s = await F(1);
103
+ if (t || !s)
104
+ return;
105
+ C.current = 2, c(() => s.messages), p(s.hasMore);
106
+ } catch {
107
+ p(!1);
108
+ }
109
+ }
110
+ })(), () => {
111
+ t = !0;
112
+ };
113
+ }, [
114
+ d,
115
+ u,
116
+ m,
117
+ l,
118
+ h,
119
+ c,
120
+ F
121
+ ]);
122
+ const at = a(() => {
123
+ if (T.current || !U)
124
+ return;
125
+ T.current = !0, A(!0);
126
+ const t = C.current;
127
+ (async () => {
128
+ try {
129
+ const r = await F(t);
130
+ if (!r) {
131
+ p(!1);
132
+ return;
133
+ }
134
+ C.current = t + 1, p(r.hasMore), c((e) => {
135
+ const n = new Set(
136
+ e.flatMap(
137
+ (i) => i.messageId ? [i.id, i.messageId] : [i.id]
138
+ )
139
+ ), s = r.messages.filter(
140
+ (i) => !n.has(i.id)
141
+ );
142
+ return s.length > 0 ? [...s, ...e] : e;
143
+ });
144
+ } catch (r) {
145
+ O?.(
146
+ r instanceof Error ? r : new Error(String(r))
147
+ );
148
+ } finally {
149
+ T.current = !1, A(!1);
150
+ }
151
+ })();
152
+ }, [c, U, O, F]);
153
+ z(() => {
154
+ l && mt();
155
+ }, [l]), z(() => () => o.current?.(), []);
156
+ const E = a(
157
+ (t) => {
158
+ const r = y.current;
159
+ y.current = null, r && c(
160
+ (e) => e.map((n) => {
161
+ if (n.id !== r)
162
+ return n;
163
+ const s = {
164
+ ...n,
165
+ isStreaming: !1
166
+ };
167
+ return t ? t(s) : s;
168
+ }).filter(
169
+ (n) => n.id !== r || n.content.length > 0 || n.wasInterrupted === !0
170
+ )
171
+ );
172
+ },
173
+ [c]
174
+ ), rt = a(
175
+ (t) => {
176
+ const r = y.current;
177
+ if (t.type === "STREAM") {
178
+ const e = X(t).text;
179
+ if (!r || !e)
180
+ return;
181
+ c(
182
+ (n) => n.map(
183
+ (s) => s.id === r ? {
184
+ ...s,
185
+ content: s.content + e,
186
+ messageId: t.messageId ?? s.messageId
187
+ } : s
188
+ )
189
+ );
190
+ return;
191
+ }
192
+ if (t.type === "TEXT") {
193
+ const { text: e, followUps: n } = X(t);
194
+ E((s) => ({
195
+ ...s,
196
+ content: e,
197
+ messageId: t.messageId ?? s.messageId,
198
+ ...n ? { followUps: n } : {}
199
+ })), h(t.responseId), R(), Q?.({
200
+ text: e,
201
+ responseId: t.responseId,
202
+ followUps: n
203
+ });
204
+ return;
205
+ }
206
+ t.type === "ERROR" && (M(X(t).text || et), E(), R());
207
+ },
208
+ [
209
+ c,
210
+ E,
211
+ Q,
212
+ R,
213
+ h
214
+ ]
215
+ ), lt = a(
216
+ (t) => {
217
+ const r = t.trim(), e = S.current;
218
+ if (!r || !e || v)
219
+ return;
220
+ M(void 0);
221
+ const n = Date.now(), s = `copilot-a-${n}`;
222
+ y.current = s, c((i) => [
223
+ ...i,
224
+ {
225
+ id: `copilot-u-${n}`,
226
+ role: "user",
227
+ content: r,
228
+ timestamp: n
229
+ },
230
+ {
231
+ id: s,
232
+ role: "assistant",
233
+ content: "",
234
+ timestamp: n + 1,
235
+ isStreaming: !0
236
+ }
237
+ ]), w(!0), R(), o.current = vt(
238
+ {
239
+ baseUrl: P,
240
+ endpointPath: V,
241
+ headers: x,
242
+ authToken: L,
243
+ getAuthToken: _,
244
+ fetchImpl: b,
245
+ storeId: u,
246
+ agent: H,
247
+ route: d,
248
+ email: Y,
249
+ userPrompt: r,
250
+ sessionId: e,
251
+ previousResponseId: B.current,
252
+ systemPrompt: q,
253
+ model: J,
254
+ maxOutputTokens: K
255
+ },
256
+ {
257
+ onEvent: rt,
258
+ onComplete: () => {
259
+ E(), w(!1), o.current = null, R();
260
+ },
261
+ onError: (i) => {
262
+ M(i.message || et), E(), w(!1), o.current = null, R(), O?.(i);
263
+ },
264
+ onAbort: () => {
265
+ E(), w(!1), o.current = null, R();
266
+ }
267
+ }
268
+ );
269
+ },
270
+ [
271
+ H,
272
+ c,
273
+ L,
274
+ P,
275
+ Y,
276
+ V,
277
+ b,
278
+ E,
279
+ _,
280
+ rt,
281
+ x,
282
+ v,
283
+ K,
284
+ J,
285
+ O,
286
+ d,
287
+ R,
288
+ u,
289
+ q
290
+ ]
291
+ ), ft = a(() => {
292
+ if (!o.current)
293
+ return;
294
+ const t = y.current;
295
+ t && c(
296
+ (r) => r.map(
297
+ (e) => e.id === t ? { ...e, wasInterrupted: !0 } : e
298
+ )
299
+ ), o.current(), o.current = null;
300
+ }, [c]), dt = a(() => {
301
+ o.current?.(), o.current = null, y.current = null, w(!1), M(void 0), C.current = 1, T.current = !1, A(!1), p(!1);
302
+ const t = $.current, r = S.current, e = m ?? wt({ route: t, storeId: u });
303
+ S.current = e, W(e), I.current = [], N([]), h(void 0), l && r && It(t, r), D?.(e);
304
+ }, [
305
+ D,
306
+ l,
307
+ m,
308
+ h,
309
+ u
310
+ ]), pt = Rt(
311
+ () => v && !G.some((t) => t.isStreaming && t.content),
312
+ [v, G]
313
+ );
314
+ return {
315
+ messages: G,
316
+ sessionId: nt,
317
+ previousResponseId: ct,
318
+ isStreaming: v,
319
+ isThinking: pt,
320
+ isRestoring: st,
321
+ isLoadingHistory: it,
322
+ hasMoreHistory: U,
323
+ error: ot,
324
+ sendMessage: lt,
325
+ loadOlderMessages: at,
326
+ stopStreaming: ft,
327
+ startNewConversation: dt
328
+ };
329
+ };
330
+ export {
331
+ bt as useCopilotStreamChat
332
+ };
333
+ //# sourceMappingURL=useCopilotStreamChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCopilotStreamChat.js","sources":["../../../../src/components/bik-copilot/useCopilotStreamChat.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n\tCopilotMessage,\n\tCopilotStreamEvent,\n\tUseCopilotStreamChatOptions,\n\tUseCopilotStreamChatResult,\n} from './model';\nimport {\n\tdeleteCopilotSession,\n\tloadCopilotSession,\n\tpersistCopilotTurn,\n\tpruneCopilotSessions,\n} from './services/copilotDb';\nimport {\n\tCOPILOT_HISTORY_PAGE_SIZE,\n\tfetchCopilotMessages,\n} from './services/copilotMessagesClient';\nimport {\n\tgetCopilotSessionIdForRoute,\n\tresetCopilotSessionForRoute,\n\tresolveCopilotSessionIdForRoute,\n} from './services/copilotPageSession';\nimport {\n\treadCopilotEventContent,\n\tstreamCopilotChat,\n} from './services/copilotStreamClient';\nimport {\n\tDEFAULT_COPILOT_AGENT,\n\tDEFAULT_COPILOT_ROUTE,\n} from './useCopilotIcebreakers';\n\nconst GENERIC_ERROR = 'Something went wrong. Please try again.';\n\n/**\n * Runs a merchant copilot conversation against the streaming\n * `/bik-ai/copilot-chatbot` endpoint.\n *\n * Owns three things the endpoint's contract requires:\n *\n * 1. **The session id.** One per route. Navigating away and back to the same\n * route continues that conversation, and so does a refresh: the ids live in\n * memory but are recovered from the stored records, which is what keeps them\n * lined up with the history the backend keys by them (see\n * `copilotPageSession`).\n * 2. **`previousResponseId`.** Absent on the first turn; from then on it is the\n * `responseId` of the last `TEXT` event, which is what makes OpenAI replay the\n * earlier turns server side. A turn that breaks halfway returns no\n * `responseId`, and the backend means that — the next turn starts fresh.\n * 3. **The transcript**, stored in IndexedDB under `{sessionId}:{route}` and\n * written every turn, so leaving the page mid-conversation loses nothing.\n */\nexport const useCopilotStreamChat = ({\n\tstoreId,\n\tagent = DEFAULT_COPILOT_AGENT,\n\troute = DEFAULT_COPILOT_ROUTE,\n\temail,\n\tmessagesPath,\n\tloadHistory = true,\n\tsystemPrompt,\n\tmodel,\n\tmaxOutputTokens,\n\tsessionId: pinnedSessionId,\n\tpersist = true,\n\tonError,\n\tonResponseComplete,\n\tonSessionIdChange,\n\tbaseUrl,\n\tendpointPath,\n\theaders,\n\tauthToken,\n\tgetAuthToken,\n\tfetchImpl,\n}: UseCopilotStreamChatOptions): UseCopilotStreamChatResult => {\n\tconst [messages, setMessages] = useState<CopilotMessage[]>([]);\n\tconst [sessionId, setSessionId] = useState<string | null>(\n\t\tpinnedSessionId ?? null,\n\t);\n\tconst [isStreaming, setIsStreaming] = useState(false);\n\tconst [isRestoring, setIsRestoring] = useState(true);\n\tconst [error, setError] = useState<string | undefined>();\n\tconst [previousResponseId, setPreviousResponseId] = useState<\n\t\tstring | undefined\n\t>();\n\tconst [isLoadingHistory, setIsLoadingHistory] = useState(false);\n\tconst [hasMoreHistory, setHasMoreHistory] = useState(false);\n\n\t// Async stream handlers run long after the render that created them, so the\n\t// live values live in refs and state is only the render mirror.\n\tconst messagesRef = useRef<CopilotMessage[]>([]);\n\tconst previousResponseIdRef = useRef<string | undefined>(undefined);\n\tconst streamingIdRef = useRef<string | null>(null);\n\tconst abortRef = useRef<(() => void) | null>(null);\n\tconst sessionIdRef = useRef<string | null>(pinnedSessionId ?? null);\n\t// The active route, for the async handlers that write the transcript.\n\tconst routeRef = useRef<string>(route);\n\trouteRef.current = route;\n\t// Next page of stored history to ask for. Starts at 2 when the local cache\n\t// already holds page 1's worth, which is the steady state.\n\tconst nextHistoryPageRef = useRef(1);\n\tconst isLoadingHistoryRef = useRef(false);\n\n\tconst applyMessages = useCallback(\n\t\t(updater: (previous: CopilotMessage[]) => CopilotMessage[]) => {\n\t\t\tconst next = updater(messagesRef.current);\n\t\t\tmessagesRef.current = next;\n\t\t\tsetMessages(next);\n\t\t},\n\t\t[],\n\t);\n\n\tconst setThreadResponseId = useCallback((responseId: string | undefined) => {\n\t\tpreviousResponseIdRef.current = responseId;\n\t\tsetPreviousResponseId(responseId);\n\t}, []);\n\n\tconst save = useCallback(() => {\n\t\tconst id = sessionIdRef.current;\n\t\tif (!persist || !id) {\n\t\t\treturn;\n\t\t}\n\t\tvoid persistCopilotTurn({\n\t\t\troute: routeRef.current,\n\t\t\tsessionId: id,\n\t\t\tmessages: messagesRef.current,\n\t\t\tpreviousResponseId: previousResponseIdRef.current,\n\t\t\tstoreId,\n\t\t\tagent,\n\t\t});\n\t}, [agent, persist, storeId]);\n\n\t// Transport config for the async readers below. Held in a ref rather than in\n\t// the effect's deps: a host that passes an inline `headers` object would\n\t// otherwise re-run restore on every render and wipe the transcript.\n\tconst transportRef = useRef({\n\t\tbaseUrl,\n\t\tmessagesPath,\n\t\theaders,\n\t\tauthToken,\n\t\tgetAuthToken,\n\t\tfetchImpl,\n\t\tstoreId,\n\t\tloadHistory,\n\t});\n\ttransportRef.current = {\n\t\tbaseUrl,\n\t\tmessagesPath,\n\t\theaders,\n\t\tauthToken,\n\t\tgetAuthToken,\n\t\tfetchImpl,\n\t\tstoreId,\n\t\tloadHistory,\n\t};\n\n\tconst readHistoryPage = useCallback(async (page: number) => {\n\t\tconst transport = transportRef.current;\n\t\tconst id = sessionIdRef.current;\n\t\tif (!transport.loadHistory || !id) {\n\t\t\treturn null;\n\t\t}\n\t\treturn fetchCopilotMessages({\n\t\t\tbaseUrl: transport.baseUrl,\n\t\t\tendpointPath: transport.messagesPath,\n\t\t\theaders: transport.headers,\n\t\t\tauthToken: transport.authToken,\n\t\t\tgetAuthToken: transport.getAuthToken,\n\t\t\tfetchImpl: transport.fetchImpl,\n\t\t\tstoreId: transport.storeId,\n\t\t\tsessionId: id,\n\t\t\tpage,\n\t\t\tpageSize: COPILOT_HISTORY_PAGE_SIZE,\n\t\t});\n\t}, []);\n\n\t// Resolve the conversation for this route and read it back from IndexedDB.\n\t// Runs again when `route` changes, because the route is half of a\n\t// conversation's identity — a different page is a different chat.\n\tuseEffect(() => {\n\t\tlet cancelled = false;\n\n\t\tconst restore = async () => {\n\t\t\t// Chunks from the previous route's turn must not land in this one.\n\t\t\tabortRef.current?.();\n\t\t\tabortRef.current = null;\n\t\t\tstreamingIdRef.current = null;\n\t\t\tsetIsStreaming(false);\n\t\t\tsetError(undefined);\n\t\t\tsetIsRestoring(true);\n\t\t\tsetHasMoreHistory(false);\n\t\t\tisLoadingHistoryRef.current = false;\n\t\t\tsetIsLoadingHistory(false);\n\n\t\t\tconst id =\n\t\t\t\tpinnedSessionId ??\n\t\t\t\t(persist\n\t\t\t\t\t? await resolveCopilotSessionIdForRoute({ route, storeId })\n\t\t\t\t\t: getCopilotSessionIdForRoute({ route, storeId }));\n\t\t\tconst record = persist ? await loadCopilotSession(route, id) : null;\n\t\t\tif (cancelled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsessionIdRef.current = id;\n\t\t\tsetSessionId(id);\n\t\t\tmessagesRef.current = record?.messages ?? [];\n\t\t\tsetMessages(messagesRef.current);\n\t\t\tsetThreadResponseId(record?.previousResponseId);\n\t\t\tsetIsRestoring(false);\n\t\t\tonSessionIdChange?.(id);\n\n\t\t\t// The cache holds at most one page, so what is on screen already *is*\n\t\t\t// page 1 and the reader's first scroll-up wants page 2.\n\t\t\tif (messagesRef.current.length > 0) {\n\t\t\t\tnextHistoryPageRef.current = 2;\n\t\t\t\tsetHasMoreHistory(transportRef.current.loadHistory);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Nothing cached and nothing to scroll, so page 1 has to be fetched for\n\t\t\t// the history to be reachable at all — but only for an id the host\n\t\t\t// pinned. An id this library resolved came out of the local records, so\n\t\t\t// an empty cache for it means an empty conversation, and a freshly\n\t\t\t// minted one has nothing behind it by definition. Asking anyway would\n\t\t\t// put a pointless request on the start of every new conversation.\n\t\t\tif (!pinnedSessionId) {\n\t\t\t\tnextHistoryPageRef.current = 1;\n\t\t\t\tsetHasMoreHistory(false);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tnextHistoryPageRef.current = 1;\n\t\t\ttry {\n\t\t\t\tconst firstPage = await readHistoryPage(1);\n\t\t\t\tif (cancelled || !firstPage) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tnextHistoryPageRef.current = 2;\n\t\t\t\tapplyMessages(() => firstPage.messages);\n\t\t\t\tsetHasMoreHistory(firstPage.hasMore);\n\t\t\t} catch {\n\t\t\t\t// A session the backend has never heard of is the normal case for a\n\t\t\t\t// host-pinned id on its first use; the empty state covers it.\n\t\t\t\tsetHasMoreHistory(false);\n\t\t\t}\n\t\t};\n\n\t\tvoid restore();\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t};\n\t\t// onSessionIdChange is event-like: re-running restore because the host\n\t\t// passed a new inline callback would wipe the transcript.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [\n\t\troute,\n\t\tstoreId,\n\t\tpinnedSessionId,\n\t\tpersist,\n\t\tsetThreadResponseId,\n\t\tapplyMessages,\n\t\treadHistoryPage,\n\t]);\n\n\t/**\n\t * Prepends the page before the oldest message on screen.\n\t *\n\t * Guarded by a ref rather than the state flag because a scroll handler can\n\t * fire many times before React re-renders, and each of those would otherwise\n\t * start its own request for the same page.\n\t */\n\tconst loadOlderMessages = useCallback(() => {\n\t\tif (isLoadingHistoryRef.current || !hasMoreHistory) {\n\t\t\treturn;\n\t\t}\n\t\tisLoadingHistoryRef.current = true;\n\t\tsetIsLoadingHistory(true);\n\n\t\tconst page = nextHistoryPageRef.current;\n\t\tvoid (async () => {\n\t\t\ttry {\n\t\t\t\tconst older = await readHistoryPage(page);\n\t\t\t\tif (!older) {\n\t\t\t\t\tsetHasMoreHistory(false);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tnextHistoryPageRef.current = page + 1;\n\t\t\t\tsetHasMoreHistory(older.hasMore);\n\t\t\t\tapplyMessages((previous) => {\n\t\t\t\t\tconst known = new Set(\n\t\t\t\t\t\tprevious.flatMap((message) =>\n\t\t\t\t\t\t\tmessage.messageId\n\t\t\t\t\t\t\t\t? [message.id, message.messageId]\n\t\t\t\t\t\t\t\t: [message.id],\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tconst fresh = older.messages.filter(\n\t\t\t\t\t\t(message) => !known.has(message.id),\n\t\t\t\t\t);\n\t\t\t\t\treturn fresh.length > 0 ? [...fresh, ...previous] : previous;\n\t\t\t\t});\n\t\t\t} catch (historyError) {\n\t\t\t\t// Left silent in the transcript on purpose: failing to reach further\n\t\t\t\t// back is not a failure of the conversation on screen. Another\n\t\t\t\t// scroll-up retries the same page.\n\t\t\t\tonError?.(\n\t\t\t\t\thistoryError instanceof Error\n\t\t\t\t\t\t? historyError\n\t\t\t\t\t\t: new Error(String(historyError)),\n\t\t\t\t);\n\t\t\t} finally {\n\t\t\t\tisLoadingHistoryRef.current = false;\n\t\t\t\tsetIsLoadingHistory(false);\n\t\t\t}\n\t\t})();\n\t}, [applyMessages, hasMoreHistory, onError, readHistoryPage]);\n\n\t// Records pile up one per route per page load otherwise, since every refresh\n\t// writes under a new key.\n\tuseEffect(() => {\n\t\tif (persist) {\n\t\t\tvoid pruneCopilotSessions();\n\t\t}\n\t}, [persist]);\n\n\t// Abort an in-flight turn if the copilot unmounts.\n\tuseEffect(() => () => abortRef.current?.(), []);\n\n\tconst finishStreamingBubble = useCallback(\n\t\t(mutate?: (message: CopilotMessage) => CopilotMessage) => {\n\t\t\tconst streamingId = streamingIdRef.current;\n\t\t\tstreamingIdRef.current = null;\n\t\t\tif (!streamingId) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tapplyMessages((previous) =>\n\t\t\t\tprevious\n\t\t\t\t\t.map((message) => {\n\t\t\t\t\t\tif (message.id !== streamingId) {\n\t\t\t\t\t\t\treturn message;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst settled: CopilotMessage = {\n\t\t\t\t\t\t\t...message,\n\t\t\t\t\t\t\tisStreaming: false,\n\t\t\t\t\t\t};\n\t\t\t\t\t\treturn mutate ? mutate(settled) : settled;\n\t\t\t\t\t})\n\t\t\t\t\t// An assistant bubble that never received text would render as an\n\t\t\t\t\t// empty balloon; the error banner carries the information instead.\n\t\t\t\t\t// A stopped turn keeps its bubble either way — the interrupted note\n\t\t\t\t\t// is the only trace a turn the reader cut short ever happened.\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(message) =>\n\t\t\t\t\t\t\tmessage.id !== streamingId ||\n\t\t\t\t\t\t\tmessage.content.length > 0 ||\n\t\t\t\t\t\t\tmessage.wasInterrupted === true,\n\t\t\t\t\t),\n\t\t\t);\n\t\t},\n\t\t[applyMessages],\n\t);\n\n\tconst handleEvent = useCallback(\n\t\t(event: CopilotStreamEvent) => {\n\t\t\tconst streamingId = streamingIdRef.current;\n\n\t\t\tif (event.type === 'STREAM') {\n\t\t\t\tconst chunk = readCopilotEventContent(event).text;\n\t\t\t\tif (!streamingId || !chunk) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tapplyMessages((previous) =>\n\t\t\t\t\tprevious.map((message) =>\n\t\t\t\t\t\tmessage.id === streamingId\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t...message,\n\t\t\t\t\t\t\t\t\tcontent: message.content + chunk,\n\t\t\t\t\t\t\t\t\tmessageId: event.messageId ?? message.messageId,\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: message,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (event.type === 'TEXT') {\n\t\t\t\t// TEXT carries the whole message, so it replaces the accumulated\n\t\t\t\t// chunks rather than appending — that keeps the bubble correct even if\n\t\t\t\t// a STREAM frame was dropped or duplicated.\n\t\t\t\tconst { text: fullText, followUps } = readCopilotEventContent(event);\n\t\t\t\tfinishStreamingBubble((message) => ({\n\t\t\t\t\t...message,\n\t\t\t\t\tcontent: fullText,\n\t\t\t\t\tmessageId: event.messageId ?? message.messageId,\n\t\t\t\t\t...(followUps ? { followUps } : {}),\n\t\t\t\t}));\n\t\t\t\tsetThreadResponseId(event.responseId);\n\t\t\t\tsave();\n\t\t\t\tonResponseComplete?.({\n\t\t\t\t\ttext: fullText,\n\t\t\t\t\tresponseId: event.responseId,\n\t\t\t\t\tfollowUps,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (event.type === 'ERROR') {\n\t\t\t\tsetError(readCopilotEventContent(event).text || GENERIC_ERROR);\n\t\t\t\tfinishStreamingBubble();\n\t\t\t\tsave();\n\t\t\t}\n\n\t\t\t// Unknown types (TOOL_STATUS is declared server side but not emitted)\n\t\t\t// are ignored so a new event type cannot break an existing client.\n\t\t},\n\t\t[\n\t\t\tapplyMessages,\n\t\t\tfinishStreamingBubble,\n\t\t\tonResponseComplete,\n\t\t\tsave,\n\t\t\tsetThreadResponseId,\n\t\t],\n\t);\n\n\tconst sendMessage = useCallback(\n\t\t(message: string) => {\n\t\t\tconst userPrompt = message.trim();\n\t\t\tconst id = sessionIdRef.current;\n\t\t\tif (!userPrompt || !id || isStreaming) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetError(undefined);\n\t\t\tconst now = Date.now();\n\t\t\tconst assistantBubbleId = `copilot-a-${now}`;\n\t\t\tstreamingIdRef.current = assistantBubbleId;\n\n\t\t\tapplyMessages((previous) => [\n\t\t\t\t...previous,\n\t\t\t\t{\n\t\t\t\t\tid: `copilot-u-${now}`,\n\t\t\t\t\trole: 'user',\n\t\t\t\t\tcontent: userPrompt,\n\t\t\t\t\ttimestamp: now,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: assistantBubbleId,\n\t\t\t\t\trole: 'assistant',\n\t\t\t\t\tcontent: '',\n\t\t\t\t\ttimestamp: now + 1,\n\t\t\t\t\tisStreaming: true,\n\t\t\t\t},\n\t\t\t]);\n\t\t\tsetIsStreaming(true);\n\t\t\tsave();\n\n\t\t\tabortRef.current = streamCopilotChat(\n\t\t\t\t{\n\t\t\t\t\tbaseUrl,\n\t\t\t\t\tendpointPath,\n\t\t\t\t\theaders,\n\t\t\t\t\tauthToken,\n\t\t\t\t\tgetAuthToken,\n\t\t\t\t\tfetchImpl,\n\t\t\t\t\tstoreId,\n\t\t\t\t\tagent,\n\t\t\t\t\troute,\n\t\t\t\t\temail,\n\t\t\t\t\tuserPrompt,\n\t\t\t\t\tsessionId: id,\n\t\t\t\t\tpreviousResponseId: previousResponseIdRef.current,\n\t\t\t\t\tsystemPrompt,\n\t\t\t\t\tmodel,\n\t\t\t\t\tmaxOutputTokens,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tonEvent: handleEvent,\n\t\t\t\t\tonComplete: () => {\n\t\t\t\t\t\t// STOP closes the stream without a frame, so this is where a turn\n\t\t\t\t\t\t// ends. TEXT has usually already settled the bubble.\n\t\t\t\t\t\tfinishStreamingBubble();\n\t\t\t\t\t\tsetIsStreaming(false);\n\t\t\t\t\t\tabortRef.current = null;\n\t\t\t\t\t\tsave();\n\t\t\t\t\t},\n\t\t\t\t\tonError: (streamError) => {\n\t\t\t\t\t\tsetError(streamError.message || GENERIC_ERROR);\n\t\t\t\t\t\tfinishStreamingBubble();\n\t\t\t\t\t\tsetIsStreaming(false);\n\t\t\t\t\t\tabortRef.current = null;\n\t\t\t\t\t\tsave();\n\t\t\t\t\t\tonError?.(streamError);\n\t\t\t\t\t},\n\t\t\t\t\tonAbort: () => {\n\t\t\t\t\t\tfinishStreamingBubble();\n\t\t\t\t\t\tsetIsStreaming(false);\n\t\t\t\t\t\tabortRef.current = null;\n\t\t\t\t\t\tsave();\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\t[\n\t\t\tagent,\n\t\t\tapplyMessages,\n\t\t\tauthToken,\n\t\t\tbaseUrl,\n\t\t\temail,\n\t\t\tendpointPath,\n\t\t\tfetchImpl,\n\t\t\tfinishStreamingBubble,\n\t\t\tgetAuthToken,\n\t\t\thandleEvent,\n\t\t\theaders,\n\t\t\tisStreaming,\n\t\t\tmaxOutputTokens,\n\t\t\tmodel,\n\t\t\tonError,\n\t\t\troute,\n\t\t\tsave,\n\t\t\tstoreId,\n\t\t\tsystemPrompt,\n\t\t],\n\t);\n\n\tconst stopStreaming = useCallback(() => {\n\t\tif (!abortRef.current) {\n\t\t\treturn;\n\t\t}\n\t\t// Flagged here rather than in `onAbort`, because an abort that lands between\n\t\t// frames ends the stream through `onComplete` instead. Whichever fires, the\n\t\t// reader stopped this turn, and whatever text had arrived stays.\n\t\tconst streamingId = streamingIdRef.current;\n\t\tif (streamingId) {\n\t\t\tapplyMessages((previous) =>\n\t\t\t\tprevious.map((message) =>\n\t\t\t\t\tmessage.id === streamingId\n\t\t\t\t\t\t? { ...message, wasInterrupted: true }\n\t\t\t\t\t\t: message,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tabortRef.current();\n\t\tabortRef.current = null;\n\t}, [applyMessages]);\n\n\tconst startNewConversation = useCallback(() => {\n\t\tabortRef.current?.();\n\t\tabortRef.current = null;\n\t\tstreamingIdRef.current = null;\n\t\tsetIsStreaming(false);\n\t\tsetError(undefined);\n\t\t// A new conversation has no history behind it; the old session's pages\n\t\t// belong to the old session id.\n\t\tnextHistoryPageRef.current = 1;\n\t\tisLoadingHistoryRef.current = false;\n\t\tsetIsLoadingHistory(false);\n\t\tsetHasMoreHistory(false);\n\n\t\tconst activeRoute = routeRef.current;\n\t\t// The conversation being cleared, so its stored transcript can go with it.\n\t\tconst clearedId = sessionIdRef.current;\n\t\t// A host-pinned id is the host's to change, so only clear its transcript.\n\t\tconst nextId =\n\t\t\tpinnedSessionId ??\n\t\t\tresetCopilotSessionForRoute({ route: activeRoute, storeId });\n\t\tsessionIdRef.current = nextId;\n\t\tsetSessionId(nextId);\n\t\tmessagesRef.current = [];\n\t\tsetMessages([]);\n\t\tsetThreadResponseId(undefined);\n\n\t\t// \"Refresh chat\" wipes the record, not just the screen: the cleared\n\t\t// conversation is deleted from IndexedDB so reopening the tab starts fresh\n\t\t// instead of resuming it. Nothing is written for the new session here — its\n\t\t// first record is stamped when the first turn is sent, which is also what\n\t\t// keeps an untouched refresh from leaving an empty record behind.\n\t\tif (persist && clearedId) {\n\t\t\tvoid deleteCopilotSession(activeRoute, clearedId);\n\t\t}\n\t\tonSessionIdChange?.(nextId);\n\t}, [\n\t\tonSessionIdChange,\n\t\tpersist,\n\t\tpinnedSessionId,\n\t\tsetThreadResponseId,\n\t\tstoreId,\n\t]);\n\n\t// The thinking bubble is only for the wait before the first token; once text\n\t// starts arriving the bubble itself shows progress.\n\tconst isThinking = useMemo(\n\t\t() =>\n\t\t\tisStreaming &&\n\t\t\t!messages.some((message) => message.isStreaming && message.content),\n\t\t[isStreaming, messages],\n\t);\n\n\treturn {\n\t\tmessages,\n\t\tsessionId,\n\t\tpreviousResponseId,\n\t\tisStreaming,\n\t\tisThinking,\n\t\tisRestoring,\n\t\tisLoadingHistory,\n\t\thasMoreHistory,\n\t\terror,\n\t\tsendMessage,\n\t\tloadOlderMessages,\n\t\tstopStreaming,\n\t\tstartNewConversation,\n\t};\n};\n"],"names":["GENERIC_ERROR","useCopilotStreamChat","storeId","agent","DEFAULT_COPILOT_AGENT","route","DEFAULT_COPILOT_ROUTE","email","messagesPath","loadHistory","systemPrompt","model","maxOutputTokens","pinnedSessionId","persist","onError","onResponseComplete","onSessionIdChange","baseUrl","endpointPath","headers","authToken","getAuthToken","fetchImpl","messages","setMessages","useState","sessionId","setSessionId","isStreaming","setIsStreaming","isRestoring","setIsRestoring","error","setError","previousResponseId","setPreviousResponseId","isLoadingHistory","setIsLoadingHistory","hasMoreHistory","setHasMoreHistory","messagesRef","useRef","previousResponseIdRef","streamingIdRef","abortRef","sessionIdRef","routeRef","nextHistoryPageRef","isLoadingHistoryRef","applyMessages","useCallback","updater","next","setThreadResponseId","responseId","save","id","persistCopilotTurn","transportRef","readHistoryPage","page","transport","fetchCopilotMessages","COPILOT_HISTORY_PAGE_SIZE","useEffect","cancelled","resolveCopilotSessionIdForRoute","getCopilotSessionIdForRoute","record","loadCopilotSession","firstPage","loadOlderMessages","older","previous","known","message","fresh","historyError","pruneCopilotSessions","finishStreamingBubble","mutate","streamingId","settled","handleEvent","event","chunk","readCopilotEventContent","fullText","followUps","sendMessage","userPrompt","now","assistantBubbleId","streamCopilotChat","streamError","stopStreaming","startNewConversation","activeRoute","clearedId","nextId","resetCopilotSessionForRoute","deleteCopilotSession","isThinking","useMemo"],"mappings":";;;;;;AA+BA,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,EAAS,UAAU,MACnBD,EAAe,UAAU,MACzBd,EAAe,EAAK,GACpBI,EAAS,MAAS,GAGlBc,EAAmB,UAAU,GAC7BC,EAAoB,UAAU,IAC9BX,EAAoB,EAAK,GACzBE,EAAkB,EAAK;AAEvB,UAAM0D,IAAcnD,EAAS,SAEvBoD,IAAYrD,EAAa,SAEzBsD,IACLvF,KACAwF,GAA4B,EAAE,OAAOH,GAAa,SAAAhG,GAAS;AAC5D,IAAA4C,EAAa,UAAUsD,GACvBxE,EAAawE,CAAM,GACnB3D,EAAY,UAAU,CAAA,GACtBhB,EAAY,CAAA,CAAE,GACd6B,EAAoB,MAAS,GAOzBxC,KAAWqF,KACTG,GAAqBJ,GAAaC,CAAS,GAEjDlF,IAAoBmF,CAAM;AAAA,EAC3B,GAAG;AAAA,IACFnF;AAAA,IACAH;AAAA,IACAD;AAAA,IACAyC;AAAA,IACApD;AAAA,EAAA,CACA,GAIKqG,KAAaC;AAAA,IAClB,MACC3E,KACA,CAACL,EAAS,KAAK,CAACoD,MAAYA,EAAQ,eAAeA,EAAQ,OAAO;AAAA,IACnE,CAAC/C,GAAaL,CAAQ;AAAA,EAAA;AAGvB,SAAO;AAAA,IACN,UAAAA;AAAA,IACA,WAAAG;AAAA,IACA,oBAAAQ;AAAA,IACA,aAAAN;AAAA,IACA,YAAA0E;AAAA,IACA,aAAAxE;AAAA,IACA,kBAAAM;AAAA,IACA,gBAAAE;AAAA,IACA,OAAAN;AAAA,IACA,aAAAyD;AAAA,IACA,mBAAAlB;AAAA,IACA,eAAAwB;AAAA,IACA,sBAAAC;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,9 @@
1
+ import { UseDraggableFloaterOptions, UseDraggableFloaterResult } from './model';
2
+ /**
3
+ * Drives a fixed-position element the user can drag anywhere in the viewport.
4
+ *
5
+ * The hook owns the element's coordinates, keeps them inside the viewport as the
6
+ * window resizes, and separates a tap from a drag so the same element can both
7
+ * be dragged and clicked.
8
+ */
9
+ export declare const useDraggableFloater: ({ size, corner, offset, enabled, snapToEdge, initialPosition, onPositionChange, }: UseDraggableFloaterOptions) => UseDraggableFloaterResult;