@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,5 +1,28 @@
1
- import { _, g as getHeadOrThrow, A as AbortedError, N, a as getApplicationSubmissionsPayload, i as invariant, o as o$1, c as clsx, b as _$1, p, d as parse, e as picklist, m, f as AnimatePresence, h as application, j as h, k, l as isSubmissionOfType, C as Cn, n as parseAsync, V as ValiError, q as object, t as transform, r as maxLength, s as minLength, u as record, v as boolean, w as string, x as email, y as url, z as regex, B as y, T, D as inputHeight, F, E as viewState, G as ERROR_MESSAGES } from "./index-873a3e2d.js";
1
+ import { _, N, i as invariant, o as o$1, c as clsx, a as _$1, p, b as parse, d as picklist, y, k, e as application, h, C as Cn, f as parseAsync, V as ValiError, g as object, t as transform, m as maxLength, j as minLength, r as record, l as boolean, s as string, n as email, u as url, q as regex, T, v as inputHeight, w as m, A as AnimatePresence, F, x as viewState, E as ERROR_MESSAGES } from "./index-b130eeef.js";
2
2
  import "@inploi/sdk";
3
+ const getHeadOrThrow = (nodes) => {
4
+ const head = nodes.find((n2) => n2.isHead);
5
+ if (!head)
6
+ throw new Error("No head node found");
7
+ return head;
8
+ };
9
+ const getApplicationSubmissionsPayload = (submissions) => {
10
+ const payload = Object.entries(submissions).reduce((acc, [key, submission]) => {
11
+ acc[key] = submission.value;
12
+ return acc;
13
+ }, {});
14
+ return payload;
15
+ };
16
+ const isSubmissionOfType = (type) => (submission) => {
17
+ if (!submission)
18
+ return false;
19
+ return submission.type === type;
20
+ };
21
+ class AbortedError extends Error {
22
+ constructor() {
23
+ super("Aborted");
24
+ }
25
+ }
3
26
  const followNodes = ({
4
27
  node,
5
28
  nodes,
@@ -458,7 +481,7 @@ async function interpretEndFlowNode({
458
481
  await chat.sendMessage({
459
482
  type: "system",
460
483
  variant: "info",
461
- text: node.data.systemMessage || "Conversation finished"
484
+ text: node.data.systemMessage
462
485
  });
463
486
  end();
464
487
  }
@@ -552,7 +575,7 @@ const ChatInputBoolean = ({
552
575
  onHeightChange();
553
576
  return o$1("form", {
554
577
  noValidate: true,
555
- class: "flex items-center gap-2",
578
+ class: "flex items-center gap-2 p-2.5",
556
579
  onSubmit: (e) => {
557
580
  e.preventDefault();
558
581
  const value = N(e).with({
@@ -586,55 +609,45 @@ const InputError = ({
586
609
  error,
587
610
  onAnimationComplete
588
611
  }) => {
589
- return o$1(AnimatePresence, {
590
- children: error && o$1(m.div, {
591
- initial: {
592
- height: 0,
593
- opacity: 0
594
- },
595
- animate: {
596
- height: "auto",
597
- opacity: 1
598
- },
599
- exit: {
600
- height: 0,
601
- opacity: 0
602
- },
603
- onAnimationComplete,
604
- role: "alert",
605
- class: "text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full p-0.5 px-1 opacity-0",
606
- children: [o$1("svg", {
607
- class: "text-error-10",
608
- width: "16",
609
- height: "16",
610
- viewBox: "0 0 16 16",
611
- fill: "none",
612
- xmlns: "http://www.w3.org/2000/svg",
613
- children: [o$1("circle", {
614
- cx: "8",
615
- cy: "8",
616
- r: "6.3",
617
- stroke: "currentColor",
618
- "stroke-width": "1.4"
619
- }), o$1("rect", {
620
- x: "7",
621
- y: "4",
622
- width: "2",
623
- height: "5",
624
- fill: "currentColor"
625
- }), o$1("rect", {
626
- x: "7",
627
- y: "10",
628
- width: "2",
629
- height: "2",
630
- fill: "currentColor"
631
- })]
632
- }), o$1("p", {
633
- class: "truncate pr-1 text-sm",
634
- children: error.message
612
+ y(() => {
613
+ if (error) {
614
+ onAnimationComplete();
615
+ }
616
+ }, [error, onAnimationComplete]);
617
+ return error ? o$1("div", {
618
+ role: "alert",
619
+ class: "text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full px-2 py-2",
620
+ children: [o$1("svg", {
621
+ class: "text-error-10",
622
+ width: "16",
623
+ height: "16",
624
+ viewBox: "0 0 16 16",
625
+ fill: "none",
626
+ xmlns: "http://www.w3.org/2000/svg",
627
+ children: [o$1("circle", {
628
+ cx: "8",
629
+ cy: "8",
630
+ r: "6.3",
631
+ stroke: "currentColor",
632
+ "stroke-width": "1.4"
633
+ }), o$1("rect", {
634
+ x: "7",
635
+ y: "4",
636
+ width: "2",
637
+ height: "5",
638
+ fill: "currentColor"
639
+ }), o$1("rect", {
640
+ x: "7",
641
+ y: "10",
642
+ width: "2",
643
+ height: "2",
644
+ fill: "currentColor"
635
645
  })]
636
- })
637
- });
646
+ }), o$1("p", {
647
+ class: "truncate pr-1 text-sm",
648
+ children: error.message
649
+ })]
650
+ }) : o$1(k, {});
638
651
  };
639
652
  const toBase64 = (file) => new Promise((resolve, reject) => {
640
653
  const reader = new FileReader();
@@ -696,7 +709,7 @@ const ChatInputFile = ({
696
709
  const totalSize = addFileSizesKb(files);
697
710
  const focusRef = useFocusOnMount();
698
711
  return o$1("form", {
699
- class: "flex flex-col gap-1",
712
+ class: "flex flex-col gap-1 p-2.5",
700
713
  onSubmit: (e) => {
701
714
  e.preventDefault();
702
715
  setError(void 0);
@@ -2284,6 +2297,9 @@ var a = function(r, e) {
2284
2297
  }
2285
2298
  };
2286
2299
  };
2300
+ const LABEL_HEIGHT = 27;
2301
+ const GAP = 12;
2302
+ const PADDING = 10;
2287
2303
  const submitIfSingleChecked = (form) => {
2288
2304
  const formObj = Object.fromEntries(new FormData(form).entries());
2289
2305
  const isSingleChecked = Object.keys(formObj).length;
@@ -2326,7 +2342,7 @@ const ChatInputMultipleChoice = ({
2326
2342
  const isSingleChoice = input.config.minSelected === 1 && input.config.maxSelected === 1;
2327
2343
  return o$1("form", {
2328
2344
  noValidate: true,
2329
- class: "flex flex-col gap-1",
2345
+ class: "flex flex-col gap-1 pr-2.5",
2330
2346
  onChange: (e) => {
2331
2347
  if (isSingleChoice) {
2332
2348
  submitIfSingleChecked(e.currentTarget);
@@ -2337,9 +2353,12 @@ const ChatInputMultipleChoice = ({
2337
2353
  onSubmitSuccess(checked);
2338
2354
  }),
2339
2355
  children: [o$1("div", {
2340
- class: "flex items-center gap-2",
2341
- children: [o$1("div", {
2342
- class: clsx("flex w-full flex-1 flex-wrap gap-3 p-1", {
2356
+ class: "flex items-center gap-1",
2357
+ children: [o$1("ul", {
2358
+ style: {
2359
+ maxHeight: 6.5 * LABEL_HEIGHT + 5 * GAP + 2 * PADDING
2360
+ },
2361
+ class: clsx("gutter-stable flex w-full flex-1 flex-wrap gap-3 overflow-y-auto rounded-xl p-2.5 pr-4", {
2343
2362
  "justify-center": input.config.options.length === 1
2344
2363
  }),
2345
2364
  children: input.config.options.map((option, i2) => {
@@ -2348,7 +2367,8 @@ const ChatInputMultipleChoice = ({
2348
2367
  ref: setRef,
2349
2368
  ...props
2350
2369
  } = register(id);
2351
- return o$1("div", {
2370
+ return o$1("li", {
2371
+ class: "relative",
2352
2372
  children: [o$1("input", {
2353
2373
  autoFocus: i2 === 0,
2354
2374
  ref: (e) => {
@@ -2359,7 +2379,7 @@ const ChatInputMultipleChoice = ({
2359
2379
  },
2360
2380
  id,
2361
2381
  ...props,
2362
- class: "peer sr-only",
2382
+ class: "peer sr-only h-full",
2363
2383
  type: "checkbox"
2364
2384
  }), o$1("label", {
2365
2385
  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",
@@ -2369,9 +2389,12 @@ const ChatInputMultipleChoice = ({
2369
2389
  }, option.value);
2370
2390
  })
2371
2391
  }), !isSingleChoice && o$1(SendButton, {})]
2372
- }), o$1(InputError, {
2373
- onAnimationComplete: onHeightChange,
2374
- error: (_b = errors2.checked) == null ? void 0 : _b.root
2392
+ }), o$1("div", {
2393
+ class: "px-1",
2394
+ children: o$1(InputError, {
2395
+ onAnimationComplete: onHeightChange,
2396
+ error: (_b = errors2.checked) == null ? void 0 : _b.root
2397
+ })
2375
2398
  })]
2376
2399
  });
2377
2400
  };
@@ -2444,7 +2467,7 @@ const ChatInputText = ({
2444
2467
  }, []);
2445
2468
  return o$1("form", {
2446
2469
  noValidate: true,
2447
- class: "flex flex-col gap-1",
2470
+ class: "flex flex-col gap-1 p-2.5",
2448
2471
  onSubmit: handleSubmit((submission2) => {
2449
2472
  onSubmitSuccess(submission2.text);
2450
2473
  }),
@@ -2506,7 +2529,7 @@ const ChatInput = ({
2506
2529
  class: "bg-neutral-2/80 absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",
2507
2530
  children: o$1("div", {
2508
2531
  ref: inputWrapperRef,
2509
- class: "border-neutral-12/5 border-t p-2.5",
2532
+ class: "border-neutral-12/5 border-t",
2510
2533
  children: N({
2511
2534
  application,
2512
2535
  input,
@@ -2514,7 +2537,7 @@ const ChatInput = ({
2514
2537
  }).with({
2515
2538
  input: _.nullish
2516
2539
  }, () => o$1("div", {
2517
- class: "flex items-center gap-2",
2540
+ class: "flex items-center gap-2 p-2.5",
2518
2541
  children: [o$1("input", {
2519
2542
  "aria-hidden": "true",
2520
2543
  id: "chat-input",
@@ -2866,14 +2889,27 @@ const JobApplicationContent = ({
2866
2889
  } = application.current$.peek();
2867
2890
  if (state !== "loaded")
2868
2891
  throw new Error(ERROR_MESSAGES.invalid_state);
2869
- const fromNodeId = currentApplication2.data.currentNodeId;
2892
+ let fromNodeId = currentApplication2.data.currentNodeId;
2870
2893
  scrollToEnd({
2871
2894
  behavior: "instant"
2872
2895
  });
2873
2896
  application.setInput(void 0);
2874
2897
  if (currentApplication2.data.isFinished)
2875
2898
  return;
2876
- application.removeLastGroupMessagesById(fromNodeId);
2899
+ if (fromNodeId === null) {
2900
+ fromNodeId = getHeadOrThrow(flow.nodes).id;
2901
+ application.setCurrentNodeId(fromNodeId);
2902
+ analytics.log({
2903
+ event: "APPLY_START",
2904
+ attributionKey: `job_${job.id}`,
2905
+ properties: {
2906
+ job_id: job.id,
2907
+ flow_id: flow.id
2908
+ }
2909
+ });
2910
+ } else {
2911
+ application.removeLastGroupMessagesById(fromNodeId);
2912
+ }
2877
2913
  const {
2878
2914
  interpret: interpret2,
2879
2915
  abort
@@ -2895,20 +2931,22 @@ const JobApplicationContent = ({
2895
2931
  onInterpret: (node, prevNode) => {
2896
2932
  const currentState = application.current$.peek().application;
2897
2933
  invariant(currentState);
2898
- currentState.data.sequence = currentState.data.sequence + 1;
2899
- analytics.log({
2900
- event: "FLOW_NODE",
2901
- attributionKey: `job_${job.id}`,
2902
- properties: {
2903
- flow_id: flow.id,
2904
- flow_version: flow.version,
2905
- job_id: job.id,
2906
- from_node_id: prevNode ? prevNode.id : null,
2907
- to_node_id: node.id,
2908
- sequence: currentState.data.sequence,
2909
- flow_session_id: currentState.data.flowSessionId
2910
- }
2911
- });
2934
+ if (prevNode) {
2935
+ currentState.data.sequence = currentState.data.sequence + 1;
2936
+ analytics.log({
2937
+ event: "FLOW_NODE",
2938
+ attributionKey: `job_${job.id}`,
2939
+ properties: {
2940
+ flow_id: flow.id,
2941
+ flow_version: flow.version,
2942
+ job_id: job.id,
2943
+ from_node_id: prevNode.id,
2944
+ to_node_id: node.id,
2945
+ sequence: currentState.data.sequence,
2946
+ flow_session_id: currentState.data.flowSessionId
2947
+ }
2948
+ });
2949
+ }
2912
2950
  application.setCurrentNodeId(node.id);
2913
2951
  },
2914
2952
  onFlowEnd: async () => {
@@ -1,5 +1,5 @@
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
5
  exports.chatbotPlugin = index.chatbotPlugin;
@@ -1,5 +1,5 @@
1
- import { H } from "./index-873a3e2d.js";
1
+ import { z } from "./index-b130eeef.js";
2
2
  import "@inploi/sdk";
3
3
  export {
4
- H as chatbotPlugin
4
+ z as chatbotPlugin
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inploi/plugin-chatbot",
3
- "version": "3.6.2",
3
+ "version": "3.6.5",
4
4
  "type": "module",
5
5
  "main": "dist/plugin-chatbot.js",
6
6
  "types": "dist/index.d.ts",
@@ -63,8 +63,8 @@
63
63
  "vite": "^4.4.5",
64
64
  "vite-plugin-dts": "^3.7.0",
65
65
  "vite-tsconfig-paths": "^4.2.1",
66
- "@inploi/core": "1.11.1",
67
- "@inploi/sdk": "1.11.2",
66
+ "@inploi/core": "1.11.3",
67
+ "@inploi/sdk": "1.11.4",
68
68
  "eslint-config-custom": "0.1.0",
69
69
  "tsconfig": "0.1.0"
70
70
  },
@@ -78,7 +78,7 @@
78
78
  "build": "concurrently 'pnpm build:npm' 'pnpm run build:cdn'",
79
79
  "setup-local": "cp -n .env.example .env || true",
80
80
  "check": "eslint src --fix --max-warnings 0 && tsc",
81
- "test:unit": "bun test",
81
+ "test": "bun test src/",
82
82
  "test:int": "playwright test",
83
83
  "test:ui": "playwright test --ui",
84
84
  "preview": "vite preview"