@chatbotkit/react 0.7.0 → 1.1.4

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,67 +1,41 @@
1
- /**
2
- * @typedef {{
3
- * id: string,
4
- * type: string,
5
- * text: string,
6
- * createdAt: number,
7
- * meta?: Record<string,any>
8
- * }} Message
9
- *
10
- * @typedef {(error: any) => any} onErrorFn
11
- * @typedef {(conversationId: string, messages: Message[], data: Record<string,any>) => any} onSendFn
12
- * @typedef {(conversationId: string, messages: Message[], data: Record<string,any>) => any} onReceiveFn
13
- *
14
- * @param {{
15
- * conversationId?: string,
16
- * token?: string,
17
- * messages?: Message[],
18
- * parse?: boolean,
19
- * stream?: boolean,
20
- * verbose?: boolean,
21
- * onError?: onErrorFn?,
22
- * onSend?: onSendFn?,
23
- * onReceive?: onReceiveFn?,
24
- * }}[options]
25
- */
26
- export default function useConversationManager({ conversationId: _conversationId, token: _token, messages: _messages, parse, stream, verbose, onError, onSend, onReceive, }?: {
27
- conversationId?: string | undefined;
1
+ export function useConversationManager(options: {
2
+ [key: string]: any;
3
+ client?: ConversationClient | undefined;
4
+ endpoint?: string | undefined;
28
5
  token?: string | undefined;
29
- messages?: Message[] | undefined;
30
- parse?: boolean | undefined;
31
- stream?: boolean | undefined;
32
- verbose?: boolean | undefined;
33
- onError?: onErrorFn | null | undefined;
34
- onSend?: onSendFn | null | undefined;
35
- onReceive?: onReceiveFn | null | undefined;
36
- } | undefined): {
6
+ conversationId?: string | undefined;
7
+ backstory?: string | undefined;
8
+ model?: string | undefined;
9
+ datasetId?: string | undefined;
10
+ skillsetId?: string | undefined;
11
+ }): {
12
+ token: string | undefined;
13
+ setToken: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
14
+ conversationId: string | undefined;
15
+ setConversationId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
16
+ backstory: string | undefined;
17
+ setBackstory: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
18
+ model: string | undefined;
19
+ setModel: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
20
+ datasetId: string | undefined;
21
+ setDatasetId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
22
+ skillsetId: string | undefined;
23
+ setSkillsetId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
37
24
  text: string;
38
25
  setText: import("react").Dispatch<import("react").SetStateAction<string>>;
39
- token: string;
40
- setToken: import("react").Dispatch<import("react").SetStateAction<string>>;
41
- conversationId: string;
42
- setConversationId: import("react").Dispatch<import("react").SetStateAction<string>>;
43
26
  messages: Message[];
44
27
  setMessages: import("react").Dispatch<import("react").SetStateAction<Message[]>>;
45
- flushUserMessage: () => Promise<void>;
46
- continueConversation: (options?: {
47
- token?: string | undefined;
48
- } | undefined) => Promise<void>;
49
- interact: (options?: {
50
- token?: string | undefined;
51
- conversationId?: string | undefined;
52
- messages?: Message[] | undefined;
53
- } | undefined) => void;
54
- reset: () => void;
55
- loading: boolean;
56
28
  thinking: boolean;
29
+ setThinking: import("react").Dispatch<import("react").SetStateAction<boolean>>;
30
+ writing: boolean;
31
+ setWriting: import("react").Dispatch<import("react").SetStateAction<boolean>>;
32
+ error: any;
33
+ setError: import("react").Dispatch<any>;
34
+ submit: () => Promise<void>;
57
35
  };
36
+ export default useConversationManager;
58
37
  export type Message = {
59
- id: string;
60
- type: string;
38
+ type: 'bot' | 'user';
61
39
  text: string;
62
- createdAt: number;
63
- meta?: Record<string, any>;
64
40
  };
65
- export type onErrorFn = (error: any) => any;
66
- export type onSendFn = (conversationId: string, messages: Message[], data: Record<string, any>) => any;
67
- export type onReceiveFn = (conversationId: string, messages: Message[], data: Record<string, any>) => any;
41
+ import { ConversationClient } from '@chatbotkit/sdk';
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useConversationManager = exports.AutoTextarea = void 0;
7
- var AutoTextarea_js_1 = require("./components/AutoTextarea.cjs");
8
- Object.defineProperty(exports, "AutoTextarea", { enumerable: true, get: function () { return __importDefault(AutoTextarea_js_1).default; } });
9
- var useConversationManager_js_1 = require("./hooks/useConversationManager.cjs");
10
- Object.defineProperty(exports, "useConversationManager", { enumerable: true, get: function () { return __importDefault(useConversationManager_js_1).default; } });
4
+ var AutoTextarea_js_1 = require("./components/AutoTextarea..cjs");
5
+ Object.defineProperty(exports, "AutoTextarea", { enumerable: true, get: function () { return AutoTextarea_js_1.AutoTextarea; } });
6
+ var useConversationManager_js_1 = require("./hooks/useConversationManager..cjs");
7
+ Object.defineProperty(exports, "useConversationManager", { enumerable: true, get: function () { return useConversationManager_js_1.useConversationManager; } });
@@ -1,2 +1,2 @@
1
- export { default as AutoTextarea } from "./components/AutoTextarea.js";
2
- export { default as useConversationManager } from "./hooks/useConversationManager.js";
1
+ export { AutoTextarea } from "./components/AutoTextarea.js";
2
+ export { useConversationManager } from "./hooks/useConversationManager.js";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cloneAndExtend = void 0;
4
+ function cloneAndExtend(object, extension) {
5
+ return Object.assign(Object.assign(Object.create(Object.getPrototypeOf(object)), object), extension);
6
+ }
7
+ exports.cloneAndExtend = cloneAndExtend;
@@ -0,0 +1 @@
1
+ export function cloneAndExtend<T>(object: T, extension: object): T;
@@ -1,30 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replaceWithCoordinates = exports.replaceBetween = exports.getRandomId = void 0;
4
- /**
5
- * @param {string} [prefix]
6
- * @returns {string}
7
- */
8
4
  function getRandomId(prefix) {
9
5
  return `${prefix || ''}${Math.random().toString(32).slice(2)}`;
10
6
  }
11
7
  exports.getRandomId = getRandomId;
12
- /**
13
- * @param {string} input
14
- * @param {number} begin
15
- * @param {number} end
16
- * @param {string} replacement
17
- * @returns {string}
18
- */
19
8
  function replaceBetween(input, begin, end, replacement) {
20
9
  return input.substring(0, begin) + replacement + input.substring(end);
21
10
  }
22
11
  exports.replaceBetween = replaceBetween;
23
- /**
24
- * @param {string} input
25
- * @param {[string, string][]} replacements
26
- * @returns {({begin: number, end: number, input: string, output: string}|string)[]}
27
- */
28
12
  function replaceWithCoordinates(input, replacements) {
29
13
  const output = [];
30
14
  let currentIndex = 0;
@@ -1,21 +1,5 @@
1
- /**
2
- * @param {string} [prefix]
3
- * @returns {string}
4
- */
5
1
  export function getRandomId(prefix?: string | undefined): string;
6
- /**
7
- * @param {string} input
8
- * @param {number} begin
9
- * @param {number} end
10
- * @param {string} replacement
11
- * @returns {string}
12
- */
13
2
  export function replaceBetween(input: string, begin: number, end: number, replacement: string): string;
14
- /**
15
- * @param {string} input
16
- * @param {[string, string][]} replacements
17
- * @returns {({begin: number, end: number, input: string, output: string}|string)[]}
18
- */
19
3
  export function replaceWithCoordinates(input: string, replacements: [string, string][]): (string | {
20
4
  begin: number;
21
5
  end: number;
@@ -1,20 +1,10 @@
1
- export function AutoScrollAnchor(): React.JSX.Element;
2
- /**
3
- * @param {{
4
- * anchor?: 'top'|'bottom',
5
- * childList?: boolean,
6
- * subtree?: boolean,
7
- * block?: 'start'|'end',
8
- * delay?: number,
9
- * [name: string]: any
10
- * }} props
11
- */
12
- export default function AutoScroller({ anchor, childList, subtree, block, delay, disabled, children, ...props }: {
1
+ export function AutoScrollAnchor(): import("react/jsx-runtime").JSX.Element;
2
+ export function AutoScroller(props?: {
13
3
  [name: string]: any;
14
- anchor?: "top" | "bottom" | undefined;
4
+ anchor?: "bottom" | "top" | undefined;
15
5
  childList?: boolean | undefined;
16
6
  subtree?: boolean | undefined;
17
7
  block?: "end" | "start" | undefined;
18
8
  delay?: number | undefined;
19
- }): React.JSX.Element;
20
- import React from 'react';
9
+ } | undefined): import("react/jsx-runtime").JSX.Element;
10
+ export default AutoScroller;
@@ -1,61 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  import React, { useRef, useEffect } from 'react';
2
3
  export function AutoScrollAnchor() {
3
- return React.createElement("div", { className: "auto-scroll-anchor ![height:1px]" });
4
+ return _jsx("div", { className: "auto-scroll-anchor ![height:1px]" });
4
5
  }
5
- /**
6
- * @param {{
7
- * anchor?: 'top'|'bottom',
8
- * childList?: boolean,
9
- * subtree?: boolean,
10
- * block?: 'start'|'end',
11
- * delay?: number,
12
- * [name: string]: any
13
- * }} props
14
- */
15
- export default function AutoScroller({ anchor = 'bottom', childList = true, subtree = false, block = 'end', delay = 3000, disabled, children, ...props }) {
16
- const rootRef = useRef();
6
+ export function AutoScroller(props) {
7
+ const { anchor = 'bottom', childList = true, subtree = false, block = 'end', delay = 3000, disabled, children, ...rest } = props || {};
8
+ const rootRef = (useRef());
17
9
  useEffect(() => {
18
10
  if (disabled) {
19
11
  return;
20
12
  }
21
13
  let visible = false;
22
14
  let pause = false;
23
- let timeout = 0;
15
+ let timeout;
24
16
  const io = new IntersectionObserver((entries) => {
25
17
  if (pause) {
26
18
  return;
27
19
  }
28
20
  visible = entries.some((entry) => entry.isIntersecting);
29
21
  });
30
- // @ts-ignore
31
- io.observe(rootRef.current?.querySelector('.auto-scroll-anchor'));
22
+ const anchor = rootRef.current?.querySelector('.auto-scroll-anchor');
23
+ if (anchor) {
24
+ io.observe(anchor);
25
+ }
32
26
  const mo = new MutationObserver(() => {
33
27
  if (!visible) {
34
28
  return;
35
29
  }
36
30
  pause = true;
37
31
  rootRef.current
38
- // @ts-ignore
39
32
  ?.querySelector('.auto-scroll-anchor')
40
33
  ?.scrollIntoView({ behavior: 'smooth', block });
41
34
  clearTimeout(timeout);
42
- // @ts-ignore
43
35
  timeout = setTimeout(() => {
44
36
  visible = true;
45
37
  pause = false;
46
38
  }, delay);
47
39
  });
48
- // @ts-ignore
49
- mo.observe(rootRef.current, { childList, subtree });
40
+ const root = rootRef.current;
41
+ if (root) {
42
+ mo.observe(root, { childList, subtree });
43
+ }
50
44
  return () => {
51
45
  io.disconnect();
52
46
  mo.disconnect();
53
47
  };
54
48
  }, [disabled]);
55
- return (
56
- // @ts-ignore
57
- React.createElement("div", { ref: rootRef, ...props },
58
- anchor === 'top' ? React.createElement(AutoScrollAnchor, { key: "top" }) : null,
59
- children,
60
- anchor === 'bottom' ? React.createElement(AutoScrollAnchor, { key: "bottom" }) : null));
49
+ return (_jsxs("div", { ref: rootRef, ...rest, children: [anchor === 'top' ? _jsx(AutoScrollAnchor, {}, "top") : null, children, anchor === 'bottom' ? _jsx(AutoScrollAnchor, {}, "bottom") : null] }));
61
50
  }
51
+ export default AutoScroller;
@@ -1,14 +1,7 @@
1
- /**
2
- * @typedef {(event: React.ChangeEvent<HTMLTextAreaElement>) => any} onInputFn
3
- *
4
- * @param {{
5
- * onInput?: onInputFn?,
6
- * [name: string]: any
7
- * }} [props]
8
- */
9
- export default function AutoTextarea({ onInput, ...props }?: {
1
+ export function AutoTextarea(props?: {
10
2
  [name: string]: any;
11
3
  onInput?: onInputFn | null | undefined;
12
- } | undefined): React.JSX.Element;
4
+ } | undefined): import("react/jsx-runtime").JSX.Element;
5
+ export default AutoTextarea;
13
6
  export type onInputFn = (event: React.ChangeEvent<HTMLTextAreaElement>) => any;
14
7
  import React from 'react';
@@ -1,17 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  import React from 'react';
2
- /**
3
- * @typedef {(event: React.ChangeEvent<HTMLTextAreaElement>) => any} onInputFn
4
- *
5
- * @param {{
6
- * onInput?: onInputFn?,
7
- * [name: string]: any
8
- * }} [props]
9
- */
10
- // @ts-ignore
11
- export default function AutoTextarea({ onInput, ...props } = {}) {
12
- /**
13
- * @param {React.ChangeEvent<HTMLTextAreaElement>} event
14
- */
3
+ export function AutoTextarea(props) {
4
+ const { onInput, ...rest } = props || {};
15
5
  function handleOnInput(event) {
16
6
  const adjustment = `calc(${[event.target.style.paddingTop, event.target.style.paddingBottom]
17
7
  .filter((f) => f)
@@ -22,5 +12,6 @@ export default function AutoTextarea({ onInput, ...props } = {}) {
22
12
  onInput(event);
23
13
  }
24
14
  }
25
- return React.createElement("textarea", { ...props, rows: 1, onInput: handleOnInput });
15
+ return _jsx("textarea", { ...rest, rows: 1, onInput: handleOnInput });
26
16
  }
17
+ export default AutoTextarea;
@@ -1,67 +1,41 @@
1
- /**
2
- * @typedef {{
3
- * id: string,
4
- * type: string,
5
- * text: string,
6
- * createdAt: number,
7
- * meta?: Record<string,any>
8
- * }} Message
9
- *
10
- * @typedef {(error: any) => any} onErrorFn
11
- * @typedef {(conversationId: string, messages: Message[], data: Record<string,any>) => any} onSendFn
12
- * @typedef {(conversationId: string, messages: Message[], data: Record<string,any>) => any} onReceiveFn
13
- *
14
- * @param {{
15
- * conversationId?: string,
16
- * token?: string,
17
- * messages?: Message[],
18
- * parse?: boolean,
19
- * stream?: boolean,
20
- * verbose?: boolean,
21
- * onError?: onErrorFn?,
22
- * onSend?: onSendFn?,
23
- * onReceive?: onReceiveFn?,
24
- * }}[options]
25
- */
26
- export default function useConversationManager({ conversationId: _conversationId, token: _token, messages: _messages, parse, stream, verbose, onError, onSend, onReceive, }?: {
27
- conversationId?: string | undefined;
1
+ export function useConversationManager(options: {
2
+ [key: string]: any;
3
+ client?: ConversationClient | undefined;
4
+ endpoint?: string | undefined;
28
5
  token?: string | undefined;
29
- messages?: Message[] | undefined;
30
- parse?: boolean | undefined;
31
- stream?: boolean | undefined;
32
- verbose?: boolean | undefined;
33
- onError?: onErrorFn | null | undefined;
34
- onSend?: onSendFn | null | undefined;
35
- onReceive?: onReceiveFn | null | undefined;
36
- } | undefined): {
6
+ conversationId?: string | undefined;
7
+ backstory?: string | undefined;
8
+ model?: string | undefined;
9
+ datasetId?: string | undefined;
10
+ skillsetId?: string | undefined;
11
+ }): {
12
+ token: string | undefined;
13
+ setToken: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
14
+ conversationId: string | undefined;
15
+ setConversationId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
16
+ backstory: string | undefined;
17
+ setBackstory: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
18
+ model: string | undefined;
19
+ setModel: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
20
+ datasetId: string | undefined;
21
+ setDatasetId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
22
+ skillsetId: string | undefined;
23
+ setSkillsetId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
37
24
  text: string;
38
25
  setText: import("react").Dispatch<import("react").SetStateAction<string>>;
39
- token: string;
40
- setToken: import("react").Dispatch<import("react").SetStateAction<string>>;
41
- conversationId: string;
42
- setConversationId: import("react").Dispatch<import("react").SetStateAction<string>>;
43
26
  messages: Message[];
44
27
  setMessages: import("react").Dispatch<import("react").SetStateAction<Message[]>>;
45
- flushUserMessage: () => Promise<void>;
46
- continueConversation: (options?: {
47
- token?: string | undefined;
48
- } | undefined) => Promise<void>;
49
- interact: (options?: {
50
- token?: string | undefined;
51
- conversationId?: string | undefined;
52
- messages?: Message[] | undefined;
53
- } | undefined) => void;
54
- reset: () => void;
55
- loading: boolean;
56
28
  thinking: boolean;
29
+ setThinking: import("react").Dispatch<import("react").SetStateAction<boolean>>;
30
+ writing: boolean;
31
+ setWriting: import("react").Dispatch<import("react").SetStateAction<boolean>>;
32
+ error: any;
33
+ setError: import("react").Dispatch<any>;
34
+ submit: () => Promise<void>;
57
35
  };
36
+ export default useConversationManager;
58
37
  export type Message = {
59
- id: string;
60
- type: string;
38
+ type: 'bot' | 'user';
61
39
  text: string;
62
- createdAt: number;
63
- meta?: Record<string, any>;
64
40
  };
65
- export type onErrorFn = (error: any) => any;
66
- export type onSendFn = (conversationId: string, messages: Message[], data: Record<string, any>) => any;
67
- export type onReceiveFn = (conversationId: string, messages: Message[], data: Record<string, any>) => any;
41
+ import { ConversationClient } from '@chatbotkit/sdk';