@inploi/plugin-chatbot 3.6.2 → 3.6.5

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.
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-7659d6f8.cjs");
3
+ const index = require("./index-ebce8046.cjs");
4
4
  require("@inploi/sdk");
5
+ const getHeadOrThrow = (nodes) => {
6
+ const head = nodes.find((n2) => n2.isHead);
7
+ if (!head)
8
+ throw new Error("No head node found");
9
+ return head;
10
+ };
11
+ const getApplicationSubmissionsPayload = (submissions) => {
12
+ const payload = Object.entries(submissions).reduce((acc, [key, submission]) => {
13
+ acc[key] = submission.value;
14
+ return acc;
15
+ }, {});
16
+ return payload;
17
+ };
18
+ const isSubmissionOfType = (type) => (submission) => {
19
+ if (!submission)
20
+ return false;
21
+ return submission.type === type;
22
+ };
23
+ class AbortedError extends Error {
24
+ constructor() {
25
+ super("Aborted");
26
+ }
27
+ }
5
28
  const followNodes = ({
6
29
  node,
7
30
  nodes,
@@ -88,14 +111,14 @@ const createFlowInterpreter = ({
88
111
  end: () => onFlowEnd == null ? void 0 : onFlowEnd(node)
89
112
  });
90
113
  } catch (e) {
91
- if (e instanceof index.AbortedError)
114
+ if (e instanceof AbortedError)
92
115
  return;
93
116
  throw e;
94
117
  }
95
118
  };
96
119
  return {
97
120
  interpret: async (startFromNodeId) => {
98
- const startNode = flow.find((node) => node.id === startFromNodeId) ?? index.getHeadOrThrow(flow);
121
+ const startNode = flow.find((node) => node.id === startFromNodeId) ?? getHeadOrThrow(flow);
99
122
  return interpretNode(startNode);
100
123
  },
101
124
  abort: () => {
@@ -216,7 +239,7 @@ async function interpretSubmitNode({
216
239
  ats: node.data.ats,
217
240
  integration_id: node.data.integrationId,
218
241
  anonymous_id: analytics.getAnonymousId(),
219
- submissions: index.getApplicationSubmissionsPayload(submissions || {})
242
+ submissions: getApplicationSubmissionsPayload(submissions || {})
220
243
  })
221
244
  }).catch((e) => e);
222
245
  await index.N(response).with({
@@ -460,7 +483,7 @@ async function interpretEndFlowNode({
460
483
  await chat.sendMessage({
461
484
  type: "system",
462
485
  variant: "info",
463
- text: node.data.systemMessage || "Conversation finished"
486
+ text: node.data.systemMessage
464
487
  });
465
488
  end();
466
489
  }
@@ -554,7 +577,7 @@ const ChatInputBoolean = ({
554
577
  onHeightChange();
555
578
  return index.o("form", {
556
579
  noValidate: true,
557
- class: "flex items-center gap-2",
580
+ class: "flex items-center gap-2 p-2.5",
558
581
  onSubmit: (e) => {
559
582
  e.preventDefault();
560
583
  const value = index.N(e).with({
@@ -588,55 +611,45 @@ const InputError = ({
588
611
  error,
589
612
  onAnimationComplete
590
613
  }) => {
591
- return index.o(index.AnimatePresence, {
592
- children: error && index.o(index.m.div, {
593
- initial: {
594
- height: 0,
595
- opacity: 0
596
- },
597
- animate: {
598
- height: "auto",
599
- opacity: 1
600
- },
601
- exit: {
602
- height: 0,
603
- opacity: 0
604
- },
605
- onAnimationComplete,
606
- role: "alert",
607
- class: "text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full p-0.5 px-1 opacity-0",
608
- children: [index.o("svg", {
609
- class: "text-error-10",
610
- width: "16",
611
- height: "16",
612
- viewBox: "0 0 16 16",
613
- fill: "none",
614
- xmlns: "http://www.w3.org/2000/svg",
615
- children: [index.o("circle", {
616
- cx: "8",
617
- cy: "8",
618
- r: "6.3",
619
- stroke: "currentColor",
620
- "stroke-width": "1.4"
621
- }), index.o("rect", {
622
- x: "7",
623
- y: "4",
624
- width: "2",
625
- height: "5",
626
- fill: "currentColor"
627
- }), index.o("rect", {
628
- x: "7",
629
- y: "10",
630
- width: "2",
631
- height: "2",
632
- fill: "currentColor"
633
- })]
634
- }), index.o("p", {
635
- class: "truncate pr-1 text-sm",
636
- children: error.message
614
+ index.y(() => {
615
+ if (error) {
616
+ onAnimationComplete();
617
+ }
618
+ }, [error, onAnimationComplete]);
619
+ return error ? index.o("div", {
620
+ role: "alert",
621
+ class: "text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full px-2 py-2",
622
+ children: [index.o("svg", {
623
+ class: "text-error-10",
624
+ width: "16",
625
+ height: "16",
626
+ viewBox: "0 0 16 16",
627
+ fill: "none",
628
+ xmlns: "http://www.w3.org/2000/svg",
629
+ children: [index.o("circle", {
630
+ cx: "8",
631
+ cy: "8",
632
+ r: "6.3",
633
+ stroke: "currentColor",
634
+ "stroke-width": "1.4"
635
+ }), index.o("rect", {
636
+ x: "7",
637
+ y: "4",
638
+ width: "2",
639
+ height: "5",
640
+ fill: "currentColor"
641
+ }), index.o("rect", {
642
+ x: "7",
643
+ y: "10",
644
+ width: "2",
645
+ height: "2",
646
+ fill: "currentColor"
637
647
  })]
638
- })
639
- });
648
+ }), index.o("p", {
649
+ class: "truncate pr-1 text-sm",
650
+ children: error.message
651
+ })]
652
+ }) : index.o(index.k, {});
640
653
  };
641
654
  const toBase64 = (file) => new Promise((resolve, reject) => {
642
655
  const reader = new FileReader();
@@ -650,7 +663,7 @@ const toBase64 = (file) => new Promise((resolve, reject) => {
650
663
  });
651
664
  const kbToReadableSize = (kb) => index.N(kb).with(index._.number.lte(1e3), () => `${Math.round(kb)}KB`).with(index._.number.lt(1e3 * 10), () => `${(kb / 1e3).toFixed(1)}MB`).otherwise(() => `${Math.round(kb / 1e3)}MB`);
652
665
  const addFileSizesKb = (files) => files.reduce((acc, cur) => acc + cur.sizeKb, 0);
653
- const isFileSubmission = index.isSubmissionOfType("file");
666
+ const isFileSubmission = isSubmissionOfType("file");
654
667
  const FILENAMES_TO_SHOW_QTY = 3;
655
668
  const FileThumbnail = ({
656
669
  file,
@@ -698,7 +711,7 @@ const ChatInputFile = ({
698
711
  const totalSize = addFileSizesKb(files);
699
712
  const focusRef = useFocusOnMount();
700
713
  return index.o("form", {
701
- class: "flex flex-col gap-1",
714
+ class: "flex flex-col gap-1 p-2.5",
702
715
  onSubmit: (e) => {
703
716
  e.preventDefault();
704
717
  setError(void 0);
@@ -2286,6 +2299,9 @@ var a = function(r, e) {
2286
2299
  }
2287
2300
  };
2288
2301
  };
2302
+ const LABEL_HEIGHT = 27;
2303
+ const GAP = 12;
2304
+ const PADDING = 10;
2289
2305
  const submitIfSingleChecked = (form) => {
2290
2306
  const formObj = Object.fromEntries(new FormData(form).entries());
2291
2307
  const isSingleChecked = Object.keys(formObj).length;
@@ -2295,7 +2311,7 @@ const submitIfSingleChecked = (form) => {
2295
2311
  bubbles: true
2296
2312
  }));
2297
2313
  };
2298
- const isMultipleChoiceSubmission = index.isSubmissionOfType("multiple-choice");
2314
+ const isMultipleChoiceSubmission = isSubmissionOfType("multiple-choice");
2299
2315
  const getResolver$1 = (config) => {
2300
2316
  const length = {
2301
2317
  min: config.minSelected ?? 0,
@@ -2328,7 +2344,7 @@ const ChatInputMultipleChoice = ({
2328
2344
  const isSingleChoice = input.config.minSelected === 1 && input.config.maxSelected === 1;
2329
2345
  return index.o("form", {
2330
2346
  noValidate: true,
2331
- class: "flex flex-col gap-1",
2347
+ class: "flex flex-col gap-1 pr-2.5",
2332
2348
  onChange: (e) => {
2333
2349
  if (isSingleChoice) {
2334
2350
  submitIfSingleChecked(e.currentTarget);
@@ -2339,9 +2355,12 @@ const ChatInputMultipleChoice = ({
2339
2355
  onSubmitSuccess(checked);
2340
2356
  }),
2341
2357
  children: [index.o("div", {
2342
- class: "flex items-center gap-2",
2343
- children: [index.o("div", {
2344
- class: index.clsx("flex w-full flex-1 flex-wrap gap-3 p-1", {
2358
+ class: "flex items-center gap-1",
2359
+ children: [index.o("ul", {
2360
+ style: {
2361
+ maxHeight: 6.5 * LABEL_HEIGHT + 5 * GAP + 2 * PADDING
2362
+ },
2363
+ class: index.clsx("gutter-stable flex w-full flex-1 flex-wrap gap-3 overflow-y-auto rounded-xl p-2.5 pr-4", {
2345
2364
  "justify-center": input.config.options.length === 1
2346
2365
  }),
2347
2366
  children: input.config.options.map((option, i2) => {
@@ -2350,7 +2369,8 @@ const ChatInputMultipleChoice = ({
2350
2369
  ref: setRef,
2351
2370
  ...props
2352
2371
  } = register(id);
2353
- return index.o("div", {
2372
+ return index.o("li", {
2373
+ class: "relative",
2354
2374
  children: [index.o("input", {
2355
2375
  autoFocus: i2 === 0,
2356
2376
  ref: (e) => {
@@ -2361,7 +2381,7 @@ const ChatInputMultipleChoice = ({
2361
2381
  },
2362
2382
  id,
2363
2383
  ...props,
2364
- class: "peer sr-only",
2384
+ class: "peer sr-only h-full",
2365
2385
  type: "checkbox"
2366
2386
  }), index.o("label", {
2367
2387
  class: "bg-lowest peer-focus-visible:ring-accent-7 active:outline-neutral-10 ease-expo-out outline-neutral-12/5 text-neutral-11 peer-checked:outline-accent-7 peer-checked:bg-accent-2 peer-checked:text-accent-9 duration-snappy block rounded-2xl px-2.5 py-1 outline outline-2 ring-0 ring-transparent transition-all selection:bg-transparent peer-focus-visible:ring-4 peer-focus-visible:ring-offset-2",
@@ -2371,9 +2391,12 @@ const ChatInputMultipleChoice = ({
2371
2391
  }, option.value);
2372
2392
  })
2373
2393
  }), !isSingleChoice && index.o(SendButton, {})]
2374
- }), index.o(InputError, {
2375
- onAnimationComplete: onHeightChange,
2376
- error: (_b = errors2.checked) == null ? void 0 : _b.root
2394
+ }), index.o("div", {
2395
+ class: "px-1",
2396
+ children: index.o(InputError, {
2397
+ onAnimationComplete: onHeightChange,
2398
+ error: (_b = errors2.checked) == null ? void 0 : _b.root
2399
+ })
2377
2400
  })]
2378
2401
  });
2379
2402
  };
@@ -2408,7 +2431,7 @@ const inputFormatToProps = {
2408
2431
  formNoValidate: true
2409
2432
  }
2410
2433
  };
2411
- const isTextSubmission = index.isSubmissionOfType("text");
2434
+ const isTextSubmission = isSubmissionOfType("text");
2412
2435
  const getResolver = (config) => i(index.object({
2413
2436
  text: inputFormatToSchema[config.format]
2414
2437
  }));
@@ -2446,7 +2469,7 @@ const ChatInputText = ({
2446
2469
  }, []);
2447
2470
  return index.o("form", {
2448
2471
  noValidate: true,
2449
- class: "flex flex-col gap-1",
2472
+ class: "flex flex-col gap-1 p-2.5",
2450
2473
  onSubmit: handleSubmit((submission2) => {
2451
2474
  onSubmitSuccess(submission2.text);
2452
2475
  }),
@@ -2508,7 +2531,7 @@ const ChatInput = ({
2508
2531
  class: "bg-neutral-2/80 absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",
2509
2532
  children: index.o("div", {
2510
2533
  ref: inputWrapperRef,
2511
- class: "border-neutral-12/5 border-t p-2.5",
2534
+ class: "border-neutral-12/5 border-t",
2512
2535
  children: index.N({
2513
2536
  application: index.application,
2514
2537
  input,
@@ -2516,7 +2539,7 @@ const ChatInput = ({
2516
2539
  }).with({
2517
2540
  input: index._.nullish
2518
2541
  }, () => index.o("div", {
2519
- class: "flex items-center gap-2",
2542
+ class: "flex items-center gap-2 p-2.5",
2520
2543
  children: [index.o("input", {
2521
2544
  "aria-hidden": "true",
2522
2545
  id: "chat-input",
@@ -2791,7 +2814,7 @@ const useChatService = () => {
2791
2814
  type: "text"
2792
2815
  }, async (message2) => {
2793
2816
  if (signal == null ? void 0 : signal.aborted)
2794
- throw new index.AbortedError();
2817
+ throw new AbortedError();
2795
2818
  setIsBotTyping(true);
2796
2819
  const typingTime = Math.min(Math.max(20, message2.text.length), 100) * TYPING_SPEED_MS_PER_CHARACTER;
2797
2820
  await new Promise((resolve) => {
@@ -2802,7 +2825,7 @@ const useChatService = () => {
2802
2825
  setIsBotTyping(false);
2803
2826
  }).otherwise(async () => void 0);
2804
2827
  if (signal == null ? void 0 : signal.aborted)
2805
- throw new index.AbortedError();
2828
+ throw new AbortedError();
2806
2829
  index.application.addMessage(message, groupId);
2807
2830
  },
2808
2831
  input: async ({
@@ -2810,12 +2833,12 @@ const useChatService = () => {
2810
2833
  signal
2811
2834
  }) => {
2812
2835
  if (signal == null ? void 0 : signal.aborted)
2813
- throw new index.AbortedError();
2836
+ throw new AbortedError();
2814
2837
  index.application.setInput(input);
2815
2838
  return await new Promise((resolve) => {
2816
2839
  const submitFunction = (submission) => {
2817
2840
  if (signal == null ? void 0 : signal.aborted)
2818
- throw new index.AbortedError();
2841
+ throw new AbortedError();
2819
2842
  index.application.setInput(void 0);
2820
2843
  if (input.key) {
2821
2844
  index.application.setSubmission(input.key, submission);
@@ -2868,14 +2891,27 @@ const JobApplicationContent = ({
2868
2891
  } = index.application.current$.peek();
2869
2892
  if (state !== "loaded")
2870
2893
  throw new Error(index.ERROR_MESSAGES.invalid_state);
2871
- const fromNodeId = currentApplication2.data.currentNodeId;
2894
+ let fromNodeId = currentApplication2.data.currentNodeId;
2872
2895
  scrollToEnd({
2873
2896
  behavior: "instant"
2874
2897
  });
2875
2898
  index.application.setInput(void 0);
2876
2899
  if (currentApplication2.data.isFinished)
2877
2900
  return;
2878
- index.application.removeLastGroupMessagesById(fromNodeId);
2901
+ if (fromNodeId === null) {
2902
+ fromNodeId = getHeadOrThrow(flow.nodes).id;
2903
+ index.application.setCurrentNodeId(fromNodeId);
2904
+ analytics.log({
2905
+ event: "APPLY_START",
2906
+ attributionKey: `job_${job.id}`,
2907
+ properties: {
2908
+ job_id: job.id,
2909
+ flow_id: flow.id
2910
+ }
2911
+ });
2912
+ } else {
2913
+ index.application.removeLastGroupMessagesById(fromNodeId);
2914
+ }
2879
2915
  const {
2880
2916
  interpret: interpret2,
2881
2917
  abort
@@ -2897,20 +2933,22 @@ const JobApplicationContent = ({
2897
2933
  onInterpret: (node, prevNode) => {
2898
2934
  const currentState = index.application.current$.peek().application;
2899
2935
  index.invariant(currentState);
2900
- currentState.data.sequence = currentState.data.sequence + 1;
2901
- analytics.log({
2902
- event: "FLOW_NODE",
2903
- attributionKey: `job_${job.id}`,
2904
- properties: {
2905
- flow_id: flow.id,
2906
- flow_version: flow.version,
2907
- job_id: job.id,
2908
- from_node_id: prevNode ? prevNode.id : null,
2909
- to_node_id: node.id,
2910
- sequence: currentState.data.sequence,
2911
- flow_session_id: currentState.data.flowSessionId
2912
- }
2913
- });
2936
+ if (prevNode) {
2937
+ currentState.data.sequence = currentState.data.sequence + 1;
2938
+ analytics.log({
2939
+ event: "FLOW_NODE",
2940
+ attributionKey: `job_${job.id}`,
2941
+ properties: {
2942
+ flow_id: flow.id,
2943
+ flow_version: flow.version,
2944
+ job_id: job.id,
2945
+ from_node_id: prevNode.id,
2946
+ to_node_id: node.id,
2947
+ sequence: currentState.data.sequence,
2948
+ flow_session_id: currentState.data.flowSessionId
2949
+ }
2950
+ });
2951
+ }
2914
2952
  index.application.setCurrentNodeId(node.id);
2915
2953
  },
2916
2954
  onFlowEnd: async () => {