@inploi/plugin-chatbot 3.15.0 → 3.16.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.
package/dist/chatbot.d.ts CHANGED
@@ -27,9 +27,7 @@ export declare const chatbotPlugin: ({ _internal_domManager: dom, theme, }: {
27
27
  mode: 'light' | 'dark';
28
28
  };
29
29
  /** @deprecated For internal usage only */
30
- _internal_domManager?: {
31
- getOrCreateChatbotElement: () => HTMLElement;
32
- } | undefined;
30
+ _internal_domManager?: ChatbotDomManager;
33
31
  }) => ({ apiClient, logger, analytics }: {
34
32
  apiClient: import("@inploi/sdk").ApiClient;
35
33
  logger: import("@inploi/sdk").Logger;
@@ -0,0 +1,127 @@
1
+ import { OpenChatbotParams } from '.';
2
+ import { Flow } from './chatbot.api';
3
+ import { ChatInput } from './components/chat-input/chat-input';
4
+ import { ChatbotFlowProgress } from './progress';
5
+ export declare const getCacheKey: (flow: Pick<StartedFlow, 'flowKeys' | 'id' | 'version'>) => string;
6
+ export type StartedFlow = Flow & {
7
+ flowKeys: string[];
8
+ title: string;
9
+ data: FlowStateData;
10
+ startedAt: Date;
11
+ context: Record<string, unknown>;
12
+ nodeIdToProgress: Record<string, ChatbotFlowProgress>;
13
+ };
14
+ type CurrentFlow = {
15
+ state: 'idle';
16
+ flow?: never;
17
+ error?: never;
18
+ } | {
19
+ state: 'loading';
20
+ flow?: never;
21
+ error?: never;
22
+ } | {
23
+ state: 'loaded';
24
+ flow: StartedFlow;
25
+ error?: never;
26
+ } | {
27
+ state: 'error';
28
+ flow?: never;
29
+ error: string;
30
+ };
31
+ export declare const store: {
32
+ current$: import("@preact/signals").Signal<CurrentFlow>;
33
+ viewState$: import("@preact/signals").Signal<"maximised" | "minimised" | "closed">;
34
+ inputHeight$: import("@preact/signals").Signal<number>;
35
+ startFlow: ({ flow, context, flowKeys, title }: OpenChatbotParams) => Promise<void>;
36
+ cancelCurrentFlow: () => void;
37
+ markAsFinished: () => void;
38
+ setCurrentNodeId: (currentNodeId: string) => void;
39
+ restart: () => void;
40
+ addMessage: (message: ChatMessage, groupId?: string) => void;
41
+ /** Removes messages from nodeId, all the messages that have the groupId passed, until it reaches one that doesn't */
42
+ removeMessagesSentByNodeIds: (nodeIds: string[]) => void;
43
+ setSubmission: (fieldKey: string, submission: FlowSubmission | null) => void;
44
+ setInput: (input: ChatInput | undefined) => void;
45
+ };
46
+ export type MessageAuthor = 'bot' | 'user';
47
+ type SystemMessage = {
48
+ type: 'system';
49
+ text: string;
50
+ variant: 'info' | 'warning' | 'error' | 'success';
51
+ };
52
+ type TextMessage = {
53
+ author: MessageAuthor;
54
+ type: 'text';
55
+ text: string;
56
+ };
57
+ type LinkMessage = {
58
+ type: 'link';
59
+ href: string;
60
+ text: string;
61
+ };
62
+ type ImageMessage = {
63
+ author: MessageAuthor;
64
+ type: 'image';
65
+ url: string;
66
+ width: number;
67
+ height: number;
68
+ };
69
+ type FileMessage = {
70
+ author: MessageAuthor;
71
+ type: 'file';
72
+ fileName: string;
73
+ fileSizeKb: number;
74
+ };
75
+ export type ChatMessage = TextMessage | ImageMessage | SystemMessage | FileMessage | LinkMessage;
76
+ export type FileToUpload = {
77
+ name: string;
78
+ data: string;
79
+ sizeKb: number;
80
+ };
81
+ export type FlowSubmissionAddress = {
82
+ value: Record<string, string | undefined>;
83
+ type: 'address';
84
+ };
85
+ export type FlowSubmissionFile = {
86
+ value: FileToUpload[];
87
+ type: 'file';
88
+ };
89
+ export type FlowSubmissionString = {
90
+ value: string;
91
+ type: 'string';
92
+ };
93
+ export type FlowSubmissionBoolean = {
94
+ value: boolean;
95
+ type: 'boolean';
96
+ };
97
+ export type FlowSubmissionNumber = {
98
+ value: number;
99
+ type: 'number';
100
+ };
101
+ export type FlowSubmissionEnum = {
102
+ value: string[];
103
+ type: 'enum';
104
+ };
105
+ export type FlowSubmissionIntegration = {
106
+ value: unknown;
107
+ type: 'integration';
108
+ };
109
+ export type FlowSubmission = FlowSubmissionString | FlowSubmissionBoolean | FlowSubmissionNumber | FlowSubmissionEnum | FlowSubmissionAddress | FlowSubmissionFile | FlowSubmissionIntegration;
110
+ export type KeyToSubmissionMap = {
111
+ [key: string]: FlowSubmission;
112
+ };
113
+ /** Dynamic part of a flow */
114
+ export type FlowStateData = {
115
+ /** History of messages left in the chat */
116
+ messages: (ChatMessage & {
117
+ groupId?: string;
118
+ })[];
119
+ submissions: KeyToSubmissionMap;
120
+ nodeHistory: string[];
121
+ /** Needs to be separate because a node can have many inputs */
122
+ currentInput: ChatInput | null;
123
+ isFinished: boolean;
124
+ sequence: number;
125
+ flowSessionId: string;
126
+ };
127
+ export {};
@@ -165,18 +165,20 @@ export declare const getHeadOrThrow: (nodes: FlowNode[]) => {
165
165
  isHead?: boolean | undefined;
166
166
  nextId?: string | undefined;
167
167
  };
168
- export declare const getFlowSubmissionsPayload: (submissions: KeyToSubmissionMap) => Record<string, string | string[] | import("./components/chat-input/chat-input.file").FileToUpload[] | Record<string, string | undefined> | null>;
169
- export declare const isSubmissionOfType: <T extends "boolean" | "text" | "multiple-choice" | "file" | "submit" | "address">(type: T) => (submission?: FlowSubmission) => submission is Extract<Pick<import("./components/chat-input/chat-input.text").TextPayload, "type" | "value">, {
168
+ export declare const getFlowSubmissionsPayload: (submissions: KeyToSubmissionMap) => Record<string, unknown>;
169
+ export declare const isSubmissionOfType: <T extends "string" | "number" | "boolean" | "enum" | "address" | "file" | "integration">(type: T) => (submission?: FlowSubmission) => submission is Extract<import("./chatbot.state").FlowSubmissionString, {
170
170
  type: T;
171
- }> | Extract<Pick<import("./components/chat-input/chat-input.multiple-choice").MultipleChoicePayload, "type" | "value">, {
171
+ }> | Extract<import("./chatbot.state").FlowSubmissionBoolean, {
172
172
  type: T;
173
- }> | Extract<Pick<import("./components/chat-input/chat-input.boolean").BooleanChoicePayload, "type" | "value">, {
173
+ }> | Extract<import("./chatbot.state").FlowSubmissionNumber, {
174
174
  type: T;
175
- }> | Extract<Pick<import("./components/chat-input/chat-input.file").FilePayload, "type" | "value">, {
175
+ }> | Extract<import("./chatbot.state").FlowSubmissionEnum, {
176
176
  type: T;
177
- }> | Extract<Pick<import("./components/chat-input/chat-input.submit").SubmitPayload, "type" | "value">, {
177
+ }> | Extract<import("./chatbot.state").FlowSubmissionAddress, {
178
178
  type: T;
179
- }> | Extract<Pick<import("./components/chat-input/chat-input.address").AddressInputPayload, "type" | "value">, {
179
+ }> | Extract<import("./chatbot.state").FlowSubmissionFile, {
180
+ type: T;
181
+ }> | Extract<import("./chatbot.state").FlowSubmissionIntegration, {
180
182
  type: T;
181
183
  }>;
182
184
  export declare function gzip(string: string): string | Promise<string>;
@@ -184,3 +186,4 @@ export declare class AbortedError extends Error {
184
186
  constructor();
185
187
  }
186
188
  export declare function debounce<TFn extends (...params: any[]) => void>(func: TFn, timeout?: number): TFn;
189
+ export declare const isString: (value: unknown) => value is string;
@@ -0,0 +1,3 @@
1
+ import { IfBlockNode } from '@inploi/core/flows';
2
+ import { KeyToSubmissionMap } from './chatbot.state';
3
+ export declare const isIfBlockConditionMet: (ifBlock: IfBlockNode, submissions?: KeyToSubmissionMap) => boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -4280,6 +4280,7 @@ function debounce(func, timeout = 300) {
4280
4280
  }, timeout);
4281
4281
  };
4282
4282
  }
4283
+ const isString = (value) => typeof value === "string";
4283
4284
  const db = typeof window === "undefined" ? void 0 : openDB("inploi-chatbot", 2, {
4284
4285
  upgrade(db2) {
4285
4286
  try {
@@ -4733,7 +4734,7 @@ const StatusBar = ({
4733
4734
  })
4734
4735
  });
4735
4736
  };
4736
- const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-daedf7bd.cjs")).then((module2) => module2.ChatbotBody));
4737
+ const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-9bce9c3f.cjs")).then((module2) => module2.ChatbotBody));
4737
4738
  const chatbotContentClass = cva("selection:bg-accent-4 selection:text-accent-12 fixed bottom-2 left-2 right-2 isolate mx-auto max-h-full max-w-[450px] focus:outline-none", {
4738
4739
  variants: {
4739
4740
  view: {
@@ -5205,6 +5206,7 @@ exports.getFlowSubmissionsPayload = getFlowSubmissionsPayload;
5205
5206
  exports.getHeadOrThrow = getHeadOrThrow;
5206
5207
  exports.h = h$1;
5207
5208
  exports.invariant = invariant;
5209
+ exports.isString = isString;
5208
5210
  exports.isSubmissionOfType = isSubmissionOfType;
5209
5211
  exports.k = k$3;
5210
5212
  exports.kbToReadableSize = kbToReadableSize;
@@ -4279,6 +4279,7 @@ function debounce(func, timeout = 300) {
4279
4279
  }, timeout);
4280
4280
  };
4281
4281
  }
4282
+ const isString = (value) => typeof value === "string";
4282
4283
  const db = typeof window === "undefined" ? void 0 : openDB("inploi-chatbot", 2, {
4283
4284
  upgrade(db2) {
4284
4285
  try {
@@ -4732,7 +4733,7 @@ const StatusBar = ({
4732
4733
  })
4733
4734
  });
4734
4735
  };
4735
- const ChatbotBody = M(() => import("./chatbot-body-0131fc86.js").then((module) => module.ChatbotBody));
4736
+ const ChatbotBody = M(() => import("./chatbot-body-59fab6f6.js").then((module) => module.ChatbotBody));
4736
4737
  const chatbotContentClass = cva("selection:bg-accent-4 selection:text-accent-12 fixed bottom-2 left-2 right-2 isolate mx-auto max-h-full max-w-[450px] focus:outline-none", {
4737
4738
  variants: {
4738
4739
  view: {
@@ -5187,40 +5188,41 @@ const chatbotPlugin = ({
5187
5188
  });
5188
5189
  export {
5189
5190
  AbortedError as A,
5190
- url as B,
5191
+ email as B,
5191
5192
  Cn as C,
5192
- regex as D,
5193
- cva as E,
5193
+ url as D,
5194
+ regex as E,
5194
5195
  F$1 as F,
5195
- ERROR_MESSAGES as G,
5196
- chatbotPlugin as H,
5196
+ cva as G,
5197
+ ERROR_MESSAGES as H,
5198
+ chatbotPlugin as I,
5197
5199
  N,
5198
5200
  ValiError as V,
5199
5201
  _$3 as _,
5200
- getFlowSubmissionsPayload as a,
5201
- _$4 as b,
5202
- clsx as c,
5203
- a as d,
5204
- debounce as e,
5205
- k$3 as f,
5202
+ invariant as a,
5203
+ getFlowSubmissionsPayload as b,
5204
+ _$4 as c,
5205
+ clsx as d,
5206
+ a as e,
5207
+ debounce as f,
5206
5208
  getHeadOrThrow as g,
5207
5209
  h$1 as h,
5208
- invariant as i,
5209
- parse$1 as j,
5210
+ isString as i,
5211
+ k$3 as j,
5210
5212
  kbToReadableSize as k,
5211
- picklist as l,
5212
- isSubmissionOfType as m,
5213
- parseAsync as n,
5213
+ parse$1 as l,
5214
+ picklist as m,
5215
+ isSubmissionOfType as n,
5214
5216
  o,
5215
5217
  p$3 as p,
5216
- object as q,
5217
- maxLength as r,
5218
+ parseAsync as q,
5219
+ object as r,
5218
5220
  store as s,
5219
5221
  transform as t,
5220
- minLength as u,
5221
- record as v,
5222
- boolean as w,
5223
- string as x,
5222
+ maxLength as u,
5223
+ minLength as v,
5224
+ record as w,
5225
+ boolean as x,
5224
5226
  y$2 as y,
5225
- email as z
5227
+ string as z
5226
5228
  };
@@ -1,11 +1,11 @@
1
1
  import { FlowNode } from '@inploi/core/flows';
2
2
  import { AnalyticsService, ApiClient, Logger } from '@inploi/sdk';
3
- import { ChatInput } from './components/chat-input/chat-input';
3
+ import { ChatbotInput } from './components/chat-input/chat-input';
4
4
  import { ChatMessage, FlowSubmission, KeyToSubmissionMap } from './chatbot.state';
5
5
  export declare const followNodes: ({ node, nodes, stopWhen, }: {
6
6
  node: FlowNode;
7
7
  nodes: FlowNode[];
8
- stopWhen?: ((node: FlowNode) => boolean) | undefined;
8
+ stopWhen?: (node: FlowNode) => boolean;
9
9
  }) => FlowNode | undefined;
10
10
  export type ChatServiceSendParams = {
11
11
  signal?: AbortSignal;
@@ -14,14 +14,15 @@ export type ChatServiceSendParams = {
14
14
  };
15
15
  export type ChatService = {
16
16
  send: (params: ChatServiceSendParams) => Promise<void>;
17
- input: <TType extends ChatInput['type']>(params: {
18
- input: Extract<ChatInput, {
17
+ input: <TType extends ChatbotInput['type']>(params: {
18
+ input: Pick<ChatbotInput & {
19
19
  type: TType;
20
- }>;
20
+ }, 'type' | 'config' | 'key'>;
21
21
  signal?: AbortSignal;
22
- }) => Promise<Extract<FlowSubmission, {
22
+ }) => Promise<(ChatbotInput & {
23
23
  type: TType;
24
- }>>;
24
+ })['submission']>;
25
+ addToSubmissions: (key: string, value: FlowSubmission) => void;
25
26
  };
26
27
  type ChatbotInterpreterParams<TContext extends Record<string, unknown>> = {
27
28
  apiClient: ApiClient;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-51b0335a.cjs");
3
+ const index = require("./index-154bf9a3.cjs");
4
4
  require("@inploi/sdk");
5
5
  exports.chatbotPlugin = index.chatbotPlugin;
@@ -1,5 +1,5 @@
1
- import { H } from "./index-b1d81d1c.js";
1
+ import { I } from "./index-dfe3ef24.js";
2
2
  import "@inploi/sdk";
3
3
  export {
4
- H as chatbotPlugin
4
+ I as chatbotPlugin
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inploi/plugin-chatbot",
3
- "version": "3.15.0",
3
+ "version": "3.16.1",
4
4
  "type": "module",
5
5
  "main": "dist/plugin-chatbot.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,6 +16,7 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
+ "lodash": "^4.17.21",
19
20
  "react-use-measure": "^2.1.1"
20
21
  },
21
22
  "peerDependencies": {
@@ -26,14 +27,15 @@
26
27
  "@hookform/resolvers": "^3.3.2",
27
28
  "@preact/preset-vite": "^2.5.0",
28
29
  "@preact/signals": "^1.2.2",
29
- "@radix-ui/react-dialog": "^1.0.5",
30
- "@radix-ui/react-focus-guards": "^1.0.1",
31
- "@radix-ui/react-focus-scope": "^1.0.4",
32
- "@radix-ui/react-slot": "^1.0.2",
30
+ "@radix-ui/react-dialog": "1.0.5",
31
+ "@radix-ui/react-focus-guards": "1.0.1",
32
+ "@radix-ui/react-focus-scope": "1.0.4",
33
+ "@radix-ui/react-slot": "1.0.2",
33
34
  "@total-typescript/ts-reset": "^0.5.1",
34
35
  "@types/bun": "^1.0.8",
35
36
  "@types/culori": "^2.0.4",
36
37
  "@types/google.maps": "^3.55.4",
38
+ "@types/lodash": "^4.17.7",
37
39
  "@types/node": "^20.10.0",
38
40
  "@types/react-transition-group": "^4.4.9",
39
41
  "autoprefixer": "^10.4.16",
@@ -60,7 +62,6 @@
60
62
  "tailwindcss-touch": "^1.0.1",
61
63
  "ts-pattern": "^5.0.6",
62
64
  "ts-toolbelt": "^9.6.0",
63
- "typescript": "^5.3.0",
64
65
  "valibot": "^0.21.0",
65
66
  "vite": "^4.4.5",
66
67
  "vite-plugin-dts": "^3.7.0",