@bikdotai/bik-component-library 0.0.868-beta.6 → 0.0.868-beta.9
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/README.md +3 -0
- package/dist/cjs/components/agent-builder/constants/tools.js +1 -1
- package/dist/cjs/components/agent-builder/constants/tools.js.map +1 -1
- package/dist/cjs/components/button/themes.js +2 -2
- package/dist/cjs/components/button/themes.js.map +1 -1
- package/dist/cjs/components/chip-selector/ChipSelector.js +2 -0
- package/dist/cjs/components/chip-selector/ChipSelector.js.map +1 -0
- package/dist/cjs/components/chip-selector/ChipSelector.styled.js +36 -0
- package/dist/cjs/components/chip-selector/ChipSelector.styled.js.map +1 -0
- package/dist/cjs/components/chip-selector/ChipSelectorGroup.js +2 -0
- package/dist/cjs/components/chip-selector/ChipSelectorGroup.js.map +1 -0
- package/dist/cjs/components/combo-box/ComboBox.js +2 -0
- package/dist/cjs/components/combo-box/ComboBox.js.map +1 -0
- package/dist/cjs/components/combo-box/ComboBox.styled.js +33 -0
- package/dist/cjs/components/combo-box/ComboBox.styled.js.map +1 -0
- package/dist/cjs/components/datePicker/DatePickerWrapper.js +1 -1
- package/dist/cjs/components/datePicker/DatePickerWrapper.js.map +1 -1
- package/dist/cjs/components/schedule-builder/RefreshSegmentToggle.js +2 -0
- package/dist/cjs/components/schedule-builder/RefreshSegmentToggle.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.styled.js +138 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.styled.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleEndPicker.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleEndPicker.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleFrequencyPicker.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleFrequencyPicker.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleHelper.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleHelper.js.map +1 -0
- package/dist/cjs/components/schedule-builder/SendModeSelector.js +2 -0
- package/dist/cjs/components/schedule-builder/SendModeSelector.js.map +1 -0
- package/dist/cjs/components/schedule-builder/StartDateTimePicker.js +2 -0
- package/dist/cjs/components/schedule-builder/StartDateTimePicker.js.map +1 -0
- package/dist/cjs/components/schedule-builder/UpcomingRunsPreview.js +2 -0
- package/dist/cjs/components/schedule-builder/UpcomingRunsPreview.js.map +1 -0
- package/dist/cjs/components/schedule-builder/model.js +2 -0
- package/dist/cjs/components/schedule-builder/model.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/esm/components/agent-builder/constants/tools.d.ts +0 -1
- package/dist/esm/components/agent-builder/constants/tools.js +18 -18
- package/dist/esm/components/agent-builder/constants/tools.js.map +1 -1
- package/dist/esm/components/button/themes.js +2 -1
- package/dist/esm/components/button/themes.js.map +1 -1
- package/dist/esm/components/chip-selector/ChipSelector.d.ts +9 -0
- package/dist/esm/components/chip-selector/ChipSelector.js +27 -0
- package/dist/esm/components/chip-selector/ChipSelector.js.map +1 -0
- package/dist/esm/components/chip-selector/ChipSelector.styled.d.ts +10 -0
- package/dist/esm/components/chip-selector/ChipSelector.styled.js +48 -0
- package/dist/esm/components/chip-selector/ChipSelector.styled.js.map +1 -0
- package/dist/esm/components/chip-selector/ChipSelectorGroup.d.ts +10 -0
- package/dist/esm/components/chip-selector/ChipSelectorGroup.js +48 -0
- package/dist/esm/components/chip-selector/ChipSelectorGroup.js.map +1 -0
- package/dist/esm/components/chip-selector/index.d.ts +4 -0
- package/dist/esm/components/chip-selector/model.d.ts +106 -0
- package/dist/esm/components/combo-box/ComboBox.d.ts +15 -0
- package/dist/esm/components/combo-box/ComboBox.js +118 -0
- package/dist/esm/components/combo-box/ComboBox.js.map +1 -0
- package/dist/esm/components/combo-box/ComboBox.styled.d.ts +12 -0
- package/dist/esm/components/combo-box/ComboBox.styled.js +40 -0
- package/dist/esm/components/combo-box/ComboBox.styled.js.map +1 -0
- package/dist/esm/components/combo-box/index.d.ts +3 -0
- package/dist/esm/components/combo-box/model.d.ts +55 -0
- package/dist/esm/components/datePicker/DatePickerWrapper.d.ts +7 -0
- package/dist/esm/components/datePicker/DatePickerWrapper.js +66 -64
- package/dist/esm/components/datePicker/DatePickerWrapper.js.map +1 -1
- package/dist/esm/components/datePicker/index.d.ts +1 -0
- package/dist/esm/components/schedule-builder/RefreshSegmentToggle.d.ts +22 -0
- package/dist/esm/components/schedule-builder/RefreshSegmentToggle.js +31 -0
- package/dist/esm/components/schedule-builder/RefreshSegmentToggle.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.d.ts +88 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.js +105 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.styled.d.ts +81 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.styled.js +168 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.styled.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleEndPicker.d.ts +17 -0
- package/dist/esm/components/schedule-builder/ScheduleEndPicker.js +105 -0
- package/dist/esm/components/schedule-builder/ScheduleEndPicker.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleFrequencyPicker.d.ts +21 -0
- package/dist/esm/components/schedule-builder/ScheduleFrequencyPicker.js +136 -0
- package/dist/esm/components/schedule-builder/ScheduleFrequencyPicker.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleHelper.d.ts +110 -0
- package/dist/esm/components/schedule-builder/ScheduleHelper.js +196 -0
- package/dist/esm/components/schedule-builder/ScheduleHelper.js.map +1 -0
- package/dist/esm/components/schedule-builder/SendModeSelector.d.ts +29 -0
- package/dist/esm/components/schedule-builder/SendModeSelector.js +41 -0
- package/dist/esm/components/schedule-builder/SendModeSelector.js.map +1 -0
- package/dist/esm/components/schedule-builder/StartDateTimePicker.d.ts +51 -0
- package/dist/esm/components/schedule-builder/StartDateTimePicker.js +120 -0
- package/dist/esm/components/schedule-builder/StartDateTimePicker.js.map +1 -0
- package/dist/esm/components/schedule-builder/UpcomingRunsPreview.d.ts +19 -0
- package/dist/esm/components/schedule-builder/UpcomingRunsPreview.js +44 -0
- package/dist/esm/components/schedule-builder/UpcomingRunsPreview.js.map +1 -0
- package/dist/esm/components/schedule-builder/index.d.ts +18 -0
- package/dist/esm/components/schedule-builder/model.d.ts +69 -0
- package/dist/esm/components/schedule-builder/model.js +8 -0
- package/dist/esm/components/schedule-builder/model.js.map +1 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +828 -844
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/components/bik-copilot/BIKCopilot.js +0 -2
- package/dist/cjs/components/bik-copilot/BIKCopilot.js.map +0 -1
- package/dist/cjs/components/bik-copilot/ControlledCopilot.js +0 -2
- package/dist/cjs/components/bik-copilot/ControlledCopilot.js.map +0 -1
- package/dist/cjs/components/bik-copilot/ControlledCopilot.styled.js +0 -27
- package/dist/cjs/components/bik-copilot/ControlledCopilot.styled.js.map +0 -1
- package/dist/cjs/components/bik-copilot/CopilotBall.js +0 -2
- package/dist/cjs/components/bik-copilot/CopilotBall.js.map +0 -1
- package/dist/cjs/components/bik-copilot/CopilotBall.styled.js +0 -42
- package/dist/cjs/components/bik-copilot/CopilotBall.styled.js.map +0 -1
- package/dist/cjs/components/bik-copilot/CopilotFeedbackModal.js +0 -2
- package/dist/cjs/components/bik-copilot/CopilotFeedbackModal.js.map +0 -1
- package/dist/cjs/components/bik-copilot/CopilotFeedbackModal.styled.js +0 -108
- package/dist/cjs/components/bik-copilot/CopilotFeedbackModal.styled.js.map +0 -1
- package/dist/cjs/components/bik-copilot/CopilotPanel.js +0 -2
- package/dist/cjs/components/bik-copilot/CopilotPanel.js.map +0 -1
- package/dist/cjs/components/bik-copilot/CopilotPanel.styled.js +0 -534
- package/dist/cjs/components/bik-copilot/CopilotPanel.styled.js.map +0 -1
- package/dist/cjs/components/bik-copilot/copilotPlacement.js +0 -2
- package/dist/cjs/components/bik-copilot/copilotPlacement.js.map +0 -1
- package/dist/cjs/components/bik-copilot/copilotRegenerate.js +0 -2
- package/dist/cjs/components/bik-copilot/copilotRegenerate.js.map +0 -1
- package/dist/cjs/components/bik-copilot/services/copilotDb.js +0 -2
- package/dist/cjs/components/bik-copilot/services/copilotDb.js.map +0 -1
- package/dist/cjs/components/bik-copilot/services/copilotFeedbackClient.js +0 -2
- package/dist/cjs/components/bik-copilot/services/copilotFeedbackClient.js.map +0 -1
- package/dist/cjs/components/bik-copilot/services/copilotIcebreakersClient.js +0 -2
- package/dist/cjs/components/bik-copilot/services/copilotIcebreakersClient.js.map +0 -1
- package/dist/cjs/components/bik-copilot/services/copilotMessagesClient.js +0 -2
- package/dist/cjs/components/bik-copilot/services/copilotMessagesClient.js.map +0 -1
- package/dist/cjs/components/bik-copilot/services/copilotPageSession.js +0 -2
- package/dist/cjs/components/bik-copilot/services/copilotPageSession.js.map +0 -1
- package/dist/cjs/components/bik-copilot/services/copilotSseParser.js +0 -7
- package/dist/cjs/components/bik-copilot/services/copilotSseParser.js.map +0 -1
- package/dist/cjs/components/bik-copilot/services/copilotStreamClient.js +0 -2
- package/dist/cjs/components/bik-copilot/services/copilotStreamClient.js.map +0 -1
- package/dist/cjs/components/bik-copilot/useCopilotIcebreakers.js +0 -2
- package/dist/cjs/components/bik-copilot/useCopilotIcebreakers.js.map +0 -1
- package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js +0 -2
- package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js.map +0 -1
- package/dist/cjs/components/bik-copilot/useDraggableFloater.js +0 -2
- package/dist/cjs/components/bik-copilot/useDraggableFloater.js.map +0 -1
- package/dist/cjs/components/bik-copilot/utils/markdown.js +0 -4
- package/dist/cjs/components/bik-copilot/utils/markdown.js.map +0 -1
- package/dist/cjs/components/bik-copilot/utils/toolCtas.js +0 -2
- package/dist/cjs/components/bik-copilot/utils/toolCtas.js.map +0 -1
- package/dist/esm/components/bik-copilot/BIKCopilot.d.ts +0 -31
- package/dist/esm/components/bik-copilot/BIKCopilot.js +0 -118
- package/dist/esm/components/bik-copilot/BIKCopilot.js.map +0 -1
- package/dist/esm/components/bik-copilot/ControlledCopilot.d.ts +0 -14
- package/dist/esm/components/bik-copilot/ControlledCopilot.js +0 -174
- package/dist/esm/components/bik-copilot/ControlledCopilot.js.map +0 -1
- package/dist/esm/components/bik-copilot/ControlledCopilot.styled.d.ts +0 -7
- package/dist/esm/components/bik-copilot/ControlledCopilot.styled.js +0 -31
- package/dist/esm/components/bik-copilot/ControlledCopilot.styled.js.map +0 -1
- package/dist/esm/components/bik-copilot/CopilotBall.d.ts +0 -13
- package/dist/esm/components/bik-copilot/CopilotBall.js +0 -50
- package/dist/esm/components/bik-copilot/CopilotBall.js.map +0 -1
- package/dist/esm/components/bik-copilot/CopilotBall.styled.d.ts +0 -9
- package/dist/esm/components/bik-copilot/CopilotBall.styled.js +0 -46
- package/dist/esm/components/bik-copilot/CopilotBall.styled.js.map +0 -1
- package/dist/esm/components/bik-copilot/CopilotFeedbackModal.d.ts +0 -29
- package/dist/esm/components/bik-copilot/CopilotFeedbackModal.js +0 -73
- package/dist/esm/components/bik-copilot/CopilotFeedbackModal.js.map +0 -1
- package/dist/esm/components/bik-copilot/CopilotFeedbackModal.styled.d.ts +0 -12
- package/dist/esm/components/bik-copilot/CopilotFeedbackModal.styled.js +0 -122
- package/dist/esm/components/bik-copilot/CopilotFeedbackModal.styled.js.map +0 -1
- package/dist/esm/components/bik-copilot/CopilotPanel.d.ts +0 -9
- package/dist/esm/components/bik-copilot/CopilotPanel.js +0 -536
- package/dist/esm/components/bik-copilot/CopilotPanel.js.map +0 -1
- package/dist/esm/components/bik-copilot/CopilotPanel.styled.d.ts +0 -67
- package/dist/esm/components/bik-copilot/CopilotPanel.styled.js +0 -573
- package/dist/esm/components/bik-copilot/CopilotPanel.styled.js.map +0 -1
- package/dist/esm/components/bik-copilot/copilotPlacement.d.ts +0 -24
- package/dist/esm/components/bik-copilot/copilotPlacement.js +0 -38
- package/dist/esm/components/bik-copilot/copilotPlacement.js.map +0 -1
- package/dist/esm/components/bik-copilot/copilotRegenerate.d.ts +0 -22
- package/dist/esm/components/bik-copilot/copilotRegenerate.js +0 -6
- package/dist/esm/components/bik-copilot/copilotRegenerate.js.map +0 -1
- package/dist/esm/components/bik-copilot/index.d.ts +0 -19
- package/dist/esm/components/bik-copilot/model.d.ts +0 -804
- package/dist/esm/components/bik-copilot/services/copilotDb.d.ts +0 -90
- package/dist/esm/components/bik-copilot/services/copilotDb.js +0 -96
- package/dist/esm/components/bik-copilot/services/copilotDb.js.map +0 -1
- package/dist/esm/components/bik-copilot/services/copilotFeedbackClient.d.ts +0 -15
- package/dist/esm/components/bik-copilot/services/copilotFeedbackClient.js +0 -55
- package/dist/esm/components/bik-copilot/services/copilotFeedbackClient.js.map +0 -1
- package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.d.ts +0 -11
- package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.js +0 -54
- package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.js.map +0 -1
- package/dist/esm/components/bik-copilot/services/copilotMessagesClient.d.ts +0 -23
- package/dist/esm/components/bik-copilot/services/copilotMessagesClient.js +0 -78
- package/dist/esm/components/bik-copilot/services/copilotMessagesClient.js.map +0 -1
- package/dist/esm/components/bik-copilot/services/copilotPageSession.d.ts +0 -37
- package/dist/esm/components/bik-copilot/services/copilotPageSession.js +0 -35
- package/dist/esm/components/bik-copilot/services/copilotPageSession.js.map +0 -1
- package/dist/esm/components/bik-copilot/services/copilotSseParser.d.ts +0 -22
- package/dist/esm/components/bik-copilot/services/copilotSseParser.js +0 -52
- package/dist/esm/components/bik-copilot/services/copilotSseParser.js.map +0 -1
- package/dist/esm/components/bik-copilot/services/copilotStreamClient.d.ts +0 -35
- package/dist/esm/components/bik-copilot/services/copilotStreamClient.js +0 -110
- package/dist/esm/components/bik-copilot/services/copilotStreamClient.js.map +0 -1
- package/dist/esm/components/bik-copilot/useCopilotIcebreakers.d.ts +0 -17
- package/dist/esm/components/bik-copilot/useCopilotIcebreakers.js +0 -60
- package/dist/esm/components/bik-copilot/useCopilotIcebreakers.js.map +0 -1
- package/dist/esm/components/bik-copilot/useCopilotStreamChat.d.ts +0 -20
- package/dist/esm/components/bik-copilot/useCopilotStreamChat.js +0 -377
- package/dist/esm/components/bik-copilot/useCopilotStreamChat.js.map +0 -1
- package/dist/esm/components/bik-copilot/useDraggableFloater.d.ts +0 -9
- package/dist/esm/components/bik-copilot/useDraggableFloater.js +0 -118
- package/dist/esm/components/bik-copilot/useDraggableFloater.js.map +0 -1
- package/dist/esm/components/bik-copilot/utils/markdown.d.ts +0 -1
- package/dist/esm/components/bik-copilot/utils/markdown.js +0 -48
- package/dist/esm/components/bik-copilot/utils/markdown.js.map +0 -1
- package/dist/esm/components/bik-copilot/utils/toolCtas.d.ts +0 -6
- package/dist/esm/components/bik-copilot/utils/toolCtas.js +0 -27
- package/dist/esm/components/bik-copilot/utils/toolCtas.js.map +0 -1
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
class f {
|
|
2
|
-
buffer = "";
|
|
3
|
-
/**
|
|
4
|
-
* Feeds one network chunk in and returns every complete `data:` payload it
|
|
5
|
-
* completed, as raw strings.
|
|
6
|
-
*/
|
|
7
|
-
push(t) {
|
|
8
|
-
this.buffer += t;
|
|
9
|
-
const n = [];
|
|
10
|
-
let e = this.findBoundary();
|
|
11
|
-
for (; e; ) {
|
|
12
|
-
const r = this.buffer.slice(0, e.index);
|
|
13
|
-
this.buffer = this.buffer.slice(e.index + e.length);
|
|
14
|
-
const i = l(r);
|
|
15
|
-
i !== null && n.push(i), e = this.findBoundary();
|
|
16
|
-
}
|
|
17
|
-
return n;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns any trailing frame left in the buffer when the stream ends without
|
|
21
|
-
* a final blank line, then empties the buffer.
|
|
22
|
-
*/
|
|
23
|
-
flush() {
|
|
24
|
-
const t = this.buffer;
|
|
25
|
-
this.buffer = "";
|
|
26
|
-
const n = l(t);
|
|
27
|
-
return n === null ? [] : [n];
|
|
28
|
-
}
|
|
29
|
-
findBoundary() {
|
|
30
|
-
const t = this.buffer.indexOf(`
|
|
31
|
-
|
|
32
|
-
`), n = this.buffer.indexOf(`\r
|
|
33
|
-
\r
|
|
34
|
-
`);
|
|
35
|
-
return n !== -1 && (t === -1 || n < t) ? { index: n, length: 4 } : t !== -1 ? { index: t, length: 2 } : null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const l = (s) => {
|
|
39
|
-
const t = s.split(/\r?\n/).filter((e) => e.startsWith("data:")).map((e) => {
|
|
40
|
-
const r = e.slice(5);
|
|
41
|
-
return r.startsWith(" ") ? r.slice(1) : r;
|
|
42
|
-
});
|
|
43
|
-
if (t.length === 0)
|
|
44
|
-
return null;
|
|
45
|
-
const n = t.join(`
|
|
46
|
-
`).trim();
|
|
47
|
-
return n.length === 0 ? null : n;
|
|
48
|
-
};
|
|
49
|
-
export {
|
|
50
|
-
f as CopilotSseParser
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=copilotSseParser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"copilotSseParser.js","sources":["../../../../../src/components/bik-copilot/services/copilotSseParser.ts"],"sourcesContent":["/**\n * Incremental parser for the SSE frames emitted by `/bik-ai/copilot-bikchatbot`.\n *\n * The endpoint writes `data: {json}\\n\\n` frames and never sets an `event:` name\n * — the discriminator lives in the JSON payload's `type`. A chunk off the\n * network can split a frame anywhere, so the parser keeps a buffer between\n * calls and only yields frames it has seen terminated.\n */\nexport class CopilotSseParser {\n\tprivate buffer = '';\n\n\t/**\n\t * Feeds one network chunk in and returns every complete `data:` payload it\n\t * completed, as raw strings.\n\t */\n\tpush(chunk: string): string[] {\n\t\tthis.buffer += chunk;\n\t\tconst payloads: string[] = [];\n\n\t\t// Frames are separated by a blank line. \\r\\n\\r\\n is tolerated because\n\t\t// proxies rewrite line endings.\n\t\tlet boundary = this.findBoundary();\n\t\twhile (boundary) {\n\t\t\tconst frame = this.buffer.slice(0, boundary.index);\n\t\t\tthis.buffer = this.buffer.slice(boundary.index + boundary.length);\n\t\t\tconst payload = extractDataPayload(frame);\n\t\t\tif (payload !== null) {\n\t\t\t\tpayloads.push(payload);\n\t\t\t}\n\t\t\tboundary = this.findBoundary();\n\t\t}\n\n\t\treturn payloads;\n\t}\n\n\t/**\n\t * Returns any trailing frame left in the buffer when the stream ends without\n\t * a final blank line, then empties the buffer.\n\t */\n\tflush(): string[] {\n\t\tconst remaining = this.buffer;\n\t\tthis.buffer = '';\n\t\tconst payload = extractDataPayload(remaining);\n\t\treturn payload === null ? [] : [payload];\n\t}\n\n\tprivate findBoundary(): { index: number; length: number } | null {\n\t\tconst lf = this.buffer.indexOf('\\n\\n');\n\t\tconst crlf = this.buffer.indexOf('\\r\\n\\r\\n');\n\t\tif (crlf !== -1 && (lf === -1 || crlf < lf)) {\n\t\t\treturn { index: crlf, length: 4 };\n\t\t}\n\t\tif (lf !== -1) {\n\t\t\treturn { index: lf, length: 2 };\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * Pulls the payload out of one SSE frame, joining multi-line `data:` fields the\n * way the SSE spec requires. Returns `null` for comment-only or empty frames.\n */\nconst extractDataPayload = (frame: string): string | null => {\n\tconst dataLines = frame\n\t\t.split(/\\r?\\n/)\n\t\t.filter((line) => line.startsWith('data:'))\n\t\t.map((line) => {\n\t\t\tconst value = line.slice('data:'.length);\n\t\t\t// A single leading space after the colon is part of the framing.\n\t\t\treturn value.startsWith(' ') ? value.slice(1) : value;\n\t\t});\n\n\tif (dataLines.length === 0) {\n\t\treturn null;\n\t}\n\tconst payload = dataLines.join('\\n').trim();\n\treturn payload.length === 0 ? null : payload;\n};\n"],"names":["CopilotSseParser","chunk","payloads","boundary","frame","payload","extractDataPayload","remaining","lf","crlf","dataLines","line","value"],"mappings":"AAQO,MAAMA,EAAiB;AAAA,EACrB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,KAAKC,GAAyB;AAC7B,SAAK,UAAUA;AACf,UAAMC,IAAqB,CAAA;AAI3B,QAAIC,IAAW,KAAK,aAAA;AACpB,WAAOA,KAAU;AAChB,YAAMC,IAAQ,KAAK,OAAO,MAAM,GAAGD,EAAS,KAAK;AACjD,WAAK,SAAS,KAAK,OAAO,MAAMA,EAAS,QAAQA,EAAS,MAAM;AAChE,YAAME,IAAUC,EAAmBF,CAAK;AACxC,MAAIC,MAAY,QACfH,EAAS,KAAKG,CAAO,GAEtBF,IAAW,KAAK,aAAA;AAAA,IACjB;AAEA,WAAOD;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAkB;AACjB,UAAMK,IAAY,KAAK;AACvB,SAAK,SAAS;AACd,UAAMF,IAAUC,EAAmBC,CAAS;AAC5C,WAAOF,MAAY,OAAO,CAAA,IAAK,CAACA,CAAO;AAAA,EACxC;AAAA,EAEQ,eAAyD;AAChE,UAAMG,IAAK,KAAK,OAAO,QAAQ;AAAA;AAAA,CAAM,GAC/BC,IAAO,KAAK,OAAO,QAAQ;AAAA;AAAA,CAAU;AAC3C,WAAIA,MAAS,OAAOD,MAAO,MAAMC,IAAOD,KAChC,EAAE,OAAOC,GAAM,QAAQ,EAAA,IAE3BD,MAAO,KACH,EAAE,OAAOA,GAAI,QAAQ,EAAA,IAEtB;AAAA,EACR;AACD;AAMA,MAAMF,IAAqB,CAACF,MAAiC;AAC5D,QAAMM,IAAYN,EAChB,MAAM,OAAO,EACb,OAAO,CAACO,MAASA,EAAK,WAAW,OAAO,CAAC,EACzC,IAAI,CAACA,MAAS;AACd,UAAMC,IAAQD,EAAK,MAAM,CAAc;AAEvC,WAAOC,EAAM,WAAW,GAAG,IAAIA,EAAM,MAAM,CAAC,IAAIA;AAAA,EACjD,CAAC;AAEF,MAAIF,EAAU,WAAW;AACxB,WAAO;AAER,QAAML,IAAUK,EAAU,KAAK;AAAA,CAAI,EAAE,KAAA;AACrC,SAAOL,EAAQ,WAAW,IAAI,OAAOA;AACtC;"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { CopilotStreamEvent, CopilotStreamHandlers, CopilotToolResult, StreamCopilotChatOptions } from '../model';
|
|
2
|
-
/** Default path of the streaming copilot endpoint (`/bik-ai/copilot-chatbot`). */
|
|
3
|
-
export declare const COPILOT_ENDPOINT_PATH = "/bik-ai/copilot-chatbot";
|
|
4
|
-
/**
|
|
5
|
-
* Reads an event's `content`. `STREAM`/`ERROR` carry a bare string; `TEXT` wraps
|
|
6
|
-
* `{ reply, pod, lastResponseId, toolResults }`.
|
|
7
|
-
*
|
|
8
|
-
* `text` prefers `reply`, falling back to the legacy `message`. `responseId`
|
|
9
|
-
* (from `lastResponseId`) threads the next turn. Anything unrecognised reads as
|
|
10
|
-
* empty text rather than throwing, so a shape the backend adds later cannot
|
|
11
|
-
* break a turn that is otherwise fine.
|
|
12
|
-
*/
|
|
13
|
-
export declare const readCopilotEventContent: (event: CopilotStreamEvent) => {
|
|
14
|
-
text: string;
|
|
15
|
-
responseId?: string | undefined;
|
|
16
|
-
followUps?: string[] | undefined;
|
|
17
|
-
toolResults?: CopilotToolResult[] | undefined;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Opens one streaming copilot turn and drives the handlers until the server
|
|
21
|
-
* closes the stream.
|
|
22
|
-
*
|
|
23
|
-
* The endpoint's `STOP` never reaches the client as a frame — the server breaks
|
|
24
|
-
* out of its generator, which ends the HTTP stream. So "the reader is done" is
|
|
25
|
-
* what completion means here, and `onComplete` fires from there.
|
|
26
|
-
*
|
|
27
|
-
* `TEXT` carries the **whole** message, so it is authoritative: a caller should
|
|
28
|
-
* replace the text accumulated from `STREAM` chunks with it rather than append.
|
|
29
|
-
* When a turn fails halfway the server still sends `TEXT` with the partial
|
|
30
|
-
* answer but **without** `responseId` — that intentionally drops the thread, so
|
|
31
|
-
* the next turn must start fresh.
|
|
32
|
-
*
|
|
33
|
-
* @returns a function that aborts the in-flight stream.
|
|
34
|
-
*/
|
|
35
|
-
export declare const streamCopilotChat: ({ baseUrl, endpointPath, headers, authToken, getAuthToken, fetchImpl, ...request }: StreamCopilotChatOptions, handlers: CopilotStreamHandlers) => (() => void);
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { CopilotSseParser as w } from "./copilotSseParser.js";
|
|
2
|
-
const I = "/bik-ai/copilot-chatbot", v = (t) => ({
|
|
3
|
-
agent: t.agent,
|
|
4
|
-
store_id: t.storeId,
|
|
5
|
-
session_id: t.sessionId,
|
|
6
|
-
route: t.route,
|
|
7
|
-
// The backend field is `user_query` (not `user_prompt`).
|
|
8
|
-
user_query: t.userPrompt,
|
|
9
|
-
// Omitted on the first turn; from the second turn on it is the previous TEXT
|
|
10
|
-
// event's `lastResponseId`, which is how OpenAI keeps the thread's context.
|
|
11
|
-
...t.previousResponseId ? { previous_response_id: t.previousResponseId } : {},
|
|
12
|
-
// Overrides the assistant's server-side system prompt when present.
|
|
13
|
-
...t.systemPrompt ? { system_prompt: t.systemPrompt } : {}
|
|
14
|
-
}), _ = (t) => {
|
|
15
|
-
const { content: e } = t, s = typeof t.responseId == "string" ? t.responseId : void 0;
|
|
16
|
-
if (typeof e == "string")
|
|
17
|
-
return {
|
|
18
|
-
text: e,
|
|
19
|
-
...s ? { responseId: s } : {}
|
|
20
|
-
};
|
|
21
|
-
if (!e || typeof e != "object")
|
|
22
|
-
return {
|
|
23
|
-
text: "",
|
|
24
|
-
...s ? { responseId: s } : {}
|
|
25
|
-
};
|
|
26
|
-
const o = e, i = Array.isArray(o.followUps) ? o.followUps.filter(
|
|
27
|
-
(n) => typeof n == "string" && n.trim().length > 0
|
|
28
|
-
) : void 0, l = Array.isArray(o.toolResults) ? o.toolResults.filter(
|
|
29
|
-
(n) => !!n && typeof n == "object" && typeof n.tool == "string"
|
|
30
|
-
) : void 0, y = typeof o.reply == "string" ? o.reply : typeof o.message == "string" ? o.message : "", r = typeof o.lastResponseId == "string" ? o.lastResponseId : s;
|
|
31
|
-
return {
|
|
32
|
-
text: y,
|
|
33
|
-
...r ? { responseId: r } : {},
|
|
34
|
-
...i && i.length > 0 ? { followUps: i } : {},
|
|
35
|
-
...l && l.length > 0 ? { toolResults: l } : {}
|
|
36
|
-
};
|
|
37
|
-
}, C = (t) => {
|
|
38
|
-
try {
|
|
39
|
-
const e = JSON.parse(t);
|
|
40
|
-
if (typeof e != "object" || e === null)
|
|
41
|
-
return null;
|
|
42
|
-
const s = e;
|
|
43
|
-
return s.type ? s : null;
|
|
44
|
-
} catch {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}, x = ({
|
|
48
|
-
baseUrl: t,
|
|
49
|
-
endpointPath: e = I,
|
|
50
|
-
headers: s,
|
|
51
|
-
authToken: o,
|
|
52
|
-
getAuthToken: i,
|
|
53
|
-
fetchImpl: l,
|
|
54
|
-
...y
|
|
55
|
-
}, r) => {
|
|
56
|
-
const n = new AbortController();
|
|
57
|
-
return (async () => {
|
|
58
|
-
const d = `${t.replace(/\/$/, "")}${e}`, g = i ? await i() : o, f = await (l ?? fetch)(d, {
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers: {
|
|
61
|
-
"Content-Type": "application/json",
|
|
62
|
-
Accept: "text/event-stream",
|
|
63
|
-
...g ? { authorization: g } : {},
|
|
64
|
-
...s
|
|
65
|
-
},
|
|
66
|
-
body: JSON.stringify(v(y)),
|
|
67
|
-
signal: n.signal
|
|
68
|
-
});
|
|
69
|
-
if (!f.ok) {
|
|
70
|
-
const a = await f.text().catch(() => "");
|
|
71
|
-
throw new Error(
|
|
72
|
-
`Copilot request failed with ${f.status}${a ? `: ${a}` : ""}`
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
if (!f.body)
|
|
76
|
-
throw new Error("Copilot response carried no stream body");
|
|
77
|
-
const b = f.body.getReader(), h = new w();
|
|
78
|
-
let u;
|
|
79
|
-
const m = (a) => {
|
|
80
|
-
a.forEach((p) => {
|
|
81
|
-
const c = C(p);
|
|
82
|
-
c && r.onEvent(c);
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
for (; ; ) {
|
|
86
|
-
const { done: a, value: p } = await b.read();
|
|
87
|
-
if (a)
|
|
88
|
-
break;
|
|
89
|
-
if (p === void 0)
|
|
90
|
-
continue;
|
|
91
|
-
let c;
|
|
92
|
-
typeof p == "string" ? c = p : (u = u ?? new TextDecoder(), c = u.decode(p, { stream: !0 })), m(h.push(c));
|
|
93
|
-
}
|
|
94
|
-
m(h.flush());
|
|
95
|
-
})().then(() => r.onComplete?.()).catch((d) => {
|
|
96
|
-
if (n.signal.aborted) {
|
|
97
|
-
r.onAbort?.();
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
r.onError?.(
|
|
101
|
-
d instanceof Error ? d : new Error(String(d))
|
|
102
|
-
);
|
|
103
|
-
}), () => n.abort();
|
|
104
|
-
};
|
|
105
|
-
export {
|
|
106
|
-
I as COPILOT_ENDPOINT_PATH,
|
|
107
|
-
_ as readCopilotEventContent,
|
|
108
|
-
x as streamCopilotChat
|
|
109
|
-
};
|
|
110
|
-
//# sourceMappingURL=copilotStreamClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"copilotStreamClient.js","sources":["../../../../../src/components/bik-copilot/services/copilotStreamClient.ts"],"sourcesContent":["import {\n\tCopilotAnswerPayload,\n\tCopilotStreamEvent,\n\tCopilotStreamHandlers,\n\tCopilotStreamRequest,\n\tCopilotToolResult,\n\tStreamCopilotChatOptions,\n} from '../model';\nimport { CopilotSseParser } from './copilotSseParser';\n\n/** Default path of the streaming copilot endpoint (`/bik-ai/copilot-chatbot`). */\nexport const COPILOT_ENDPOINT_PATH = '/bik-ai/copilot-chatbot';\n\nconst buildRequestBody = (request: CopilotStreamRequest) => ({\n\tagent: request.agent,\n\tstore_id: request.storeId,\n\tsession_id: request.sessionId,\n\troute: request.route,\n\t// The backend field is `user_query` (not `user_prompt`).\n\tuser_query: request.userPrompt,\n\t// Omitted on the first turn; from the second turn on it is the previous TEXT\n\t// event's `lastResponseId`, 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// Overrides the assistant's server-side system prompt when present.\n\t...(request.systemPrompt ? { system_prompt: request.systemPrompt } : {}),\n});\n\n/**\n * Reads an event's `content`. `STREAM`/`ERROR` carry a bare string; `TEXT` wraps\n * `{ reply, pod, lastResponseId, toolResults }`.\n *\n * `text` prefers `reply`, falling back to the legacy `message`. `responseId`\n * (from `lastResponseId`) threads the next turn. Anything unrecognised reads as\n * empty text rather than throwing, so a shape the backend adds later cannot\n * break a turn that is otherwise fine.\n */\nexport const readCopilotEventContent = (\n\tevent: CopilotStreamEvent,\n): {\n\ttext: string;\n\tresponseId?: string;\n\tfollowUps?: string[];\n\ttoolResults?: CopilotToolResult[];\n} => {\n\tconst { content } = event;\n\t// Real backend puts the id inside the TEXT payload as `lastResponseId`; a\n\t// top-level `responseId` is read as a fallback so either shape threads.\n\tconst eventResponseId =\n\t\ttypeof event.responseId === 'string' ? event.responseId : undefined;\n\n\tif (typeof content === 'string') {\n\t\treturn {\n\t\t\ttext: content,\n\t\t\t...(eventResponseId ? { responseId: eventResponseId } : {}),\n\t\t};\n\t}\n\tif (!content || typeof content !== 'object') {\n\t\treturn {\n\t\t\ttext: '',\n\t\t\t...(eventResponseId ? { responseId: eventResponseId } : {}),\n\t\t};\n\t}\n\n\tconst payload = content as CopilotAnswerPayload;\n\n\tconst followUps = Array.isArray(payload.followUps)\n\t\t? payload.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\t// Tool outputs (e.g. the support-portal link) ride on the TEXT payload as\n\t// well as their own TOOL_RESULT event, so the final message keeps them.\n\tconst toolResults = Array.isArray(payload.toolResults)\n\t\t? payload.toolResults.filter(\n\t\t\t\t(toolResult): toolResult is CopilotToolResult =>\n\t\t\t\t\t!!toolResult &&\n\t\t\t\t\ttypeof toolResult === 'object' &&\n\t\t\t\t\ttypeof (toolResult as CopilotToolResult).tool === 'string',\n\t\t )\n\t\t: undefined;\n\n\tconst text =\n\t\ttypeof payload.reply === 'string'\n\t\t\t? payload.reply\n\t\t\t: typeof payload.message === 'string'\n\t\t\t? payload.message\n\t\t\t: '';\n\n\tconst responseId =\n\t\ttypeof payload.lastResponseId === 'string'\n\t\t\t? payload.lastResponseId\n\t\t\t: eventResponseId;\n\n\treturn {\n\t\ttext,\n\t\t...(responseId ? { responseId } : {}),\n\t\t...(followUps && followUps.length > 0 ? { followUps } : {}),\n\t\t...(toolResults && toolResults.length > 0 ? { toolResults } : {}),\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","eventResponseId","payload","followUps","followUp","toolResults","toolResult","text","responseId","parseEvent","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":"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"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { UseCopilotIcebreakersOptions, UseCopilotIcebreakersResult, CopilotAgent } from './model';
|
|
2
|
-
/** The assistant persona the endpoints expect. */
|
|
3
|
-
export declare const DEFAULT_COPILOT_AGENT: CopilotAgent;
|
|
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;
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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 { CopilotAgent } from './model';\nimport { fetchCopilotIcebreakers } from './services/copilotIcebreakersClient';\n\n/** The assistant persona the endpoints expect. */\nexport const DEFAULT_COPILOT_AGENT: CopilotAgent = '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":";;AAUO,MAAMA,IAAsC,uBAOtCC,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;"}
|
|
@@ -1,20 +0,0 @@
|
|
|
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, messagesPath, feedbackPath, user, loadHistory, systemPrompt, sessionId: pinnedSessionId, persist, onError, onResponseComplete, onSessionIdChange, baseUrl, endpointPath, headers, authToken, getAuthToken, fetchImpl, }: UseCopilotStreamChatOptions) => UseCopilotStreamChatResult;
|