@chatbotkit/react 0.8.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,65 +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
- * stream?: boolean,
19
- * verbose?: boolean,
20
- * onError?: onErrorFn?,
21
- * onSend?: onSendFn?,
22
- * onReceive?: onReceiveFn?,
23
- * }}[options]
24
- */
25
- export default function useConversationManager({ conversationId: _conversationId, token: _token, messages: _messages, stream, verbose, onError, onSend, onReceive, }?: {
26
- conversationId?: string | undefined;
1
+ export function useConversationManager(options: {
2
+ [key: string]: any;
3
+ client?: ConversationClient | undefined;
4
+ endpoint?: string | undefined;
27
5
  token?: string | undefined;
28
- messages?: Message[] | undefined;
29
- stream?: boolean | undefined;
30
- verbose?: boolean | undefined;
31
- onError?: onErrorFn | null | undefined;
32
- onSend?: onSendFn | null | undefined;
33
- onReceive?: onReceiveFn | null | undefined;
34
- } | 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>>;
35
24
  text: string;
36
25
  setText: import("react").Dispatch<import("react").SetStateAction<string>>;
37
- token: string;
38
- setToken: import("react").Dispatch<import("react").SetStateAction<string>>;
39
- conversationId: string;
40
- setConversationId: import("react").Dispatch<import("react").SetStateAction<string>>;
41
26
  messages: Message[];
42
27
  setMessages: import("react").Dispatch<import("react").SetStateAction<Message[]>>;
43
- flushUserMessage: () => Promise<void>;
44
- continueConversation: (options?: {
45
- token?: string | undefined;
46
- } | undefined) => Promise<void>;
47
- interact: (options?: {
48
- token?: string | undefined;
49
- conversationId?: string | undefined;
50
- messages?: Message[] | undefined;
51
- } | undefined) => void;
52
- reset: () => void;
53
- loading: boolean;
54
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>;
55
35
  };
36
+ export default useConversationManager;
56
37
  export type Message = {
57
- id: string;
58
- type: string;
38
+ type: 'bot' | 'user';
59
39
  text: string;
60
- createdAt: number;
61
- meta?: Record<string, any>;
62
40
  };
63
- export type onErrorFn = (error: any) => any;
64
- export type onSendFn = (conversationId: string, messages: Message[], data: Record<string, any>) => any;
65
- 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,62 +1,51 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React, { useRef, useEffect } from 'react';
3
3
  export function AutoScrollAnchor() {
4
- return React.createElement("div", { className: "auto-scroll-anchor ![height:1px]" });
4
+ return _jsx("div", { className: "auto-scroll-anchor ![height:1px]" });
5
5
  }
6
- /**
7
- * @param {{
8
- * anchor?: 'top'|'bottom',
9
- * childList?: boolean,
10
- * subtree?: boolean,
11
- * block?: 'start'|'end',
12
- * delay?: number,
13
- * [name: string]: any
14
- * }} props
15
- */
16
- export default function AutoScroller({ anchor = 'bottom', childList = true, subtree = false, block = 'end', delay = 3000, disabled, children, ...props }) {
17
- 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());
18
9
  useEffect(() => {
19
10
  if (disabled) {
20
11
  return;
21
12
  }
22
13
  let visible = false;
23
14
  let pause = false;
24
- let timeout = 0;
15
+ let timeout;
25
16
  const io = new IntersectionObserver((entries) => {
26
17
  if (pause) {
27
18
  return;
28
19
  }
29
20
  visible = entries.some((entry) => entry.isIntersecting);
30
21
  });
31
- // @ts-ignore
32
- 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
+ }
33
26
  const mo = new MutationObserver(() => {
34
27
  if (!visible) {
35
28
  return;
36
29
  }
37
30
  pause = true;
38
31
  rootRef.current
39
- // @ts-ignore
40
32
  ?.querySelector('.auto-scroll-anchor')
41
33
  ?.scrollIntoView({ behavior: 'smooth', block });
42
34
  clearTimeout(timeout);
43
- // @ts-ignore
44
35
  timeout = setTimeout(() => {
45
36
  visible = true;
46
37
  pause = false;
47
38
  }, delay);
48
39
  });
49
- // @ts-ignore
50
- mo.observe(rootRef.current, { childList, subtree });
40
+ const root = rootRef.current;
41
+ if (root) {
42
+ mo.observe(root, { childList, subtree });
43
+ }
51
44
  return () => {
52
45
  io.disconnect();
53
46
  mo.disconnect();
54
47
  };
55
48
  }, [disabled]);
56
- return (
57
- // @ts-ignore
58
- React.createElement("div", { ref: rootRef, ...props },
59
- anchor === 'top' ? React.createElement(AutoScrollAnchor, { key: "top" }) : null,
60
- children,
61
- 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] }));
62
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,18 +1,7 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- /**
4
- * @typedef {(event: React.ChangeEvent<HTMLTextAreaElement>) => any} onInputFn
5
- *
6
- * @param {{
7
- * onInput?: onInputFn?,
8
- * [name: string]: any
9
- * }} [props]
10
- */
11
- // @ts-ignore
12
- export default function AutoTextarea({ onInput, ...props } = {}) {
13
- /**
14
- * @param {React.ChangeEvent<HTMLTextAreaElement>} event
15
- */
3
+ export function AutoTextarea(props) {
4
+ const { onInput, ...rest } = props || {};
16
5
  function handleOnInput(event) {
17
6
  const adjustment = `calc(${[event.target.style.paddingTop, event.target.style.paddingBottom]
18
7
  .filter((f) => f)
@@ -23,5 +12,6 @@ export default function AutoTextarea({ onInput, ...props } = {}) {
23
12
  onInput(event);
24
13
  }
25
14
  }
26
- return React.createElement("textarea", { ...props, rows: 1, onInput: handleOnInput });
15
+ return _jsx("textarea", { ...rest, rows: 1, onInput: handleOnInput });
27
16
  }
17
+ export default AutoTextarea;
@@ -1,65 +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
- * stream?: boolean,
19
- * verbose?: boolean,
20
- * onError?: onErrorFn?,
21
- * onSend?: onSendFn?,
22
- * onReceive?: onReceiveFn?,
23
- * }}[options]
24
- */
25
- export default function useConversationManager({ conversationId: _conversationId, token: _token, messages: _messages, stream, verbose, onError, onSend, onReceive, }?: {
26
- conversationId?: string | undefined;
1
+ export function useConversationManager(options: {
2
+ [key: string]: any;
3
+ client?: ConversationClient | undefined;
4
+ endpoint?: string | undefined;
27
5
  token?: string | undefined;
28
- messages?: Message[] | undefined;
29
- stream?: boolean | undefined;
30
- verbose?: boolean | undefined;
31
- onError?: onErrorFn | null | undefined;
32
- onSend?: onSendFn | null | undefined;
33
- onReceive?: onReceiveFn | null | undefined;
34
- } | 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>>;
35
24
  text: string;
36
25
  setText: import("react").Dispatch<import("react").SetStateAction<string>>;
37
- token: string;
38
- setToken: import("react").Dispatch<import("react").SetStateAction<string>>;
39
- conversationId: string;
40
- setConversationId: import("react").Dispatch<import("react").SetStateAction<string>>;
41
26
  messages: Message[];
42
27
  setMessages: import("react").Dispatch<import("react").SetStateAction<Message[]>>;
43
- flushUserMessage: () => Promise<void>;
44
- continueConversation: (options?: {
45
- token?: string | undefined;
46
- } | undefined) => Promise<void>;
47
- interact: (options?: {
48
- token?: string | undefined;
49
- conversationId?: string | undefined;
50
- messages?: Message[] | undefined;
51
- } | undefined) => void;
52
- reset: () => void;
53
- loading: boolean;
54
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>;
55
35
  };
36
+ export default useConversationManager;
56
37
  export type Message = {
57
- id: string;
58
- type: string;
38
+ type: 'bot' | 'user';
59
39
  text: string;
60
- createdAt: number;
61
- meta?: Record<string, any>;
62
40
  };
63
- export type onErrorFn = (error: any) => any;
64
- export type onSendFn = (conversationId: string, messages: Message[], data: Record<string, any>) => any;
65
- export type onReceiveFn = (conversationId: string, messages: Message[], data: Record<string, any>) => any;
41
+ import { ConversationClient } from '@chatbotkit/sdk';