@inploi/plugin-chatbot 3.15.0 → 3.16.0

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>;
@@ -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 {};
@@ -4732,7 +4732,7 @@ const StatusBar = ({
4732
4732
  })
4733
4733
  });
4734
4734
  };
4735
- const ChatbotBody = M(() => import("./chatbot-body-0131fc86.js").then((module) => module.ChatbotBody));
4735
+ const ChatbotBody = M(() => import("./chatbot-body-1f7580cd.js").then((module) => module.ChatbotBody));
4736
4736
  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
4737
  variants: {
4738
4738
  view: {
@@ -4733,7 +4733,7 @@ const StatusBar = ({
4733
4733
  })
4734
4734
  });
4735
4735
  };
4736
- const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-daedf7bd.cjs")).then((module2) => module2.ChatbotBody));
4736
+ const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-5774cb2a.cjs")).then((module2) => module2.ChatbotBody));
4737
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", {
4738
4738
  variants: {
4739
4739
  view: {
@@ -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-a8a873bc.cjs");
4
4
  require("@inploi/sdk");
5
5
  exports.chatbotPlugin = index.chatbotPlugin;
@@ -1,4 +1,4 @@
1
- import { H } from "./index-b1d81d1c.js";
1
+ import { H } from "./index-063bd7e8.js";
2
2
  import "@inploi/sdk";
3
3
  export {
4
4
  H as chatbotPlugin
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.0",
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",