@chatbotkit/react 1.8.0 → 1.8.2

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.
Files changed (32) hide show
  1. package/README.md +7 -6
  2. package/dist/cjs/actions/complete.cjs +37 -23
  3. package/dist/cjs/actions/complete.d.ts +13 -3
  4. package/dist/cjs/components/AutoScroller.cjs +1 -0
  5. package/dist/cjs/components/AutoTextarea.cjs +1 -0
  6. package/dist/cjs/components/ChatInput.cjs +1 -0
  7. package/dist/cjs/components/ChatMessage.cjs +4 -18
  8. package/dist/cjs/components/ChatMessage.d.ts +2 -2
  9. package/dist/cjs/components/ChatMessages.cjs +1 -0
  10. package/dist/cjs/components/ConversationManager.cjs +4 -3
  11. package/dist/cjs/hooks/useConversationManager.cjs +8 -4
  12. package/dist/cjs/hooks/useConversationManager.d.ts +12 -5
  13. package/dist/cjs/hooks/useConversationManagerRemote.cjs +1 -0
  14. package/dist/cjs/hooks/useConversationManagerState.cjs +1 -0
  15. package/dist/cjs/hooks/useConversationManagerStateReducer.cjs +1 -0
  16. package/dist/esm/actions/complete.d.ts +13 -3
  17. package/dist/esm/actions/complete.js +37 -23
  18. package/dist/esm/components/AutoScroller.js +1 -0
  19. package/dist/esm/components/AutoTextarea.js +1 -0
  20. package/dist/esm/components/ChatInput.js +1 -0
  21. package/dist/esm/components/ChatMessage.d.ts +2 -2
  22. package/dist/esm/components/ChatMessage.js +4 -18
  23. package/dist/esm/components/ChatMessages.js +1 -0
  24. package/dist/esm/components/ConversationManager.js +4 -3
  25. package/dist/esm/hooks/useConversationManager.d.ts +12 -5
  26. package/dist/esm/hooks/useConversationManager.js +8 -4
  27. package/dist/esm/hooks/useConversationManagerRemote.js +1 -0
  28. package/dist/esm/hooks/useConversationManagerState.js +1 -0
  29. package/dist/esm/hooks/useConversationManagerStateReducer.js +1 -0
  30. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  31. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  32. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![ChatBotKit](https://img.shields.io/badge/credits-ChatBotKit-blue.svg)](https://chatbotkit.com)
2
+ [![CBK.AI](https://img.shields.io/badge/credits-CBK.AI-blue.svg)](https://cbk.ai)
2
3
  [![Follow on Twitter](https://img.shields.io/twitter/follow/chatbotkit.svg?logo=twitter)](https://twitter.com/chatbotkit)
3
4
  [![NPM](https://img.shields.io/npm/v/@chatbotkit/react.svg)](https://www.npmjs.com/package/@chatbotkit/react)
4
5
 
@@ -10,9 +11,9 @@ Welcome to the ChatBotKit React SDK! This SDK is your go-to React solution for c
10
11
 
11
12
  The ChatBotKit React SDK offers a comprehensive set of features and capabilities, including:
12
13
 
13
- - **[streamComplete](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_react.actions_streamComplete.html#streamcomplete)**: A server-side reaction which allow for function calling and React component streaming.
14
- - **[userConversationManager](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_react.hooks_useConversationManager.html)**: A React Hook for managing conversation flow. Handles all the heavy lifting of sending and receiving messages, as well as thinking and typing indicators.
15
- - **[ConvesationManager](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_react.components_ConversationManager.html)**: A React component that provides a conversation manager interface. Useful for chat interfaces to manage conversation flow.
14
+ - **[streamComplete](https://chatbotkit.github.io/node-sdk/functions/_chatbotkit_react.actions_complete.streamComplete.html)**: A server-side reaction which allow for function calling and React component streaming.
15
+ - **[userConversationManager](https://chatbotkit.github.io/node-sdk/functions/_chatbotkit_react.hooks_useConversationManager.useConversationManager.html)**: A React Hook for managing conversation flow. Handles all the heavy lifting of sending and receiving messages, as well as thinking and typing indicators.
16
+ - **[ConvesationManager](https://chatbotkit.github.io/node-sdk/functions/_chatbotkit_react.components_ConversationManager.ConversationManager.html)**: A React component that provides a conversation manager interface. Useful for chat interfaces to manage conversation flow.
16
17
  - **[AutoTextarea](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_react.components_AutoTextarea.html)**: A React component that automatically resizes the textarea to fit the content. Useful for chat interfaces to allow users to type messages.
17
18
  - **[ChatInput](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_react.components_ChatInput.html)**: A React component that provides a chat input interface. Useful for chat interfaces to allow users to type messages. It automatically handles modifiers such as ctrl, cmd and shift.
18
19
  - **[ChatMessage](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_react.components_ChatMessage.html)**: A React component that provides a chat message interface. Useful for chat interfaces to display messages with rich formatting.
@@ -45,7 +46,7 @@ export default function Page() {
45
46
 
46
47
  import { useContext } from 'react'
47
48
 
48
- import { complete } from '../actions/conversation.js'
49
+ import { complete } from '../actions/conversation.jsx'
49
50
 
50
51
  import { ChatInput, ConversationContext } from '@chatbotkit/react'
51
52
  import ConversationManager from '@chatbotkit/react/components/ConversationManager'
@@ -118,7 +119,7 @@ export default function ChatArea() {
118
119
  )
119
120
  }
120
121
 
121
- // file: ./actions/conversation.js
122
+ // file: ./actions/conversation.jsx
122
123
  'use server'
123
124
 
124
125
  import CalendarEvents from '../components/CalendarEvents.jsx'
@@ -130,7 +131,7 @@ const cbk = new ChatBotKit({
130
131
  secret: process.env.CHATBOTKIT_API_SECRET,
131
132
  })
132
133
 
133
- export async function complete(_, { messages }) {
134
+ export async function complete({ messages }) {
134
135
  return streamComplete({
135
136
  client: cbk.conversation,
136
137
 
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.streamComplete = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
4
  const react_1 = require("react");
6
5
  const it_js_1 = require("../utils/it.cjs");
7
6
  const stream_js_1 = require("../utils/stream.cjs");
@@ -12,14 +11,16 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
12
11
  return;
13
12
  }
14
13
  messages = messages.slice(0);
15
- const functionDefinitions = functions === null || functions === void 0 ? void 0 : functions.map((fn) => {
16
- if (typeof fn === 'function') {
17
- return fn();
18
- }
19
- else {
20
- return fn;
21
- }
22
- });
14
+ const functionDefinitions = functions
15
+ ? await Promise.all(functions.map(async (fn) => {
16
+ if (typeof fn === 'function') {
17
+ return await fn();
18
+ }
19
+ else {
20
+ return fn;
21
+ }
22
+ }))
23
+ : undefined;
23
24
  let it;
24
25
  if (!it) {
25
26
  const lastMessage = messages[messages.length - 1];
@@ -73,7 +74,18 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
73
74
  throw error || new Error('Invalid arguments');
74
75
  }
75
76
  }
76
- const output = await fn.handler(args);
77
+ const abortController = new AbortController();
78
+ const continuationController = new AbortController();
79
+ const output = await fn.handler(args, {
80
+ messages: messages,
81
+ functions: functionDefinitions,
82
+ controllers: {
83
+ continuation: continuationController,
84
+ },
85
+ signals: {
86
+ abort: abortController.signal,
87
+ },
88
+ });
77
89
  let text;
78
90
  let children;
79
91
  let result;
@@ -109,8 +121,8 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
109
121
  type: 'message',
110
122
  data: {
111
123
  type: 'bot',
112
- text: text ? text : '',
113
- children: children ? (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }) : undefined,
124
+ text: text || '',
125
+ children: children || undefined,
114
126
  },
115
127
  };
116
128
  }
@@ -124,8 +136,8 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
124
136
  data: {
125
137
  id: id,
126
138
  type: 'bot',
127
- text: text ? text : '',
128
- children: item,
139
+ text: text || '',
140
+ children: item || undefined,
129
141
  },
130
142
  };
131
143
  }
@@ -135,8 +147,8 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
135
147
  type: 'message',
136
148
  data: {
137
149
  type: 'bot',
138
- text: text ? text : '',
139
- children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: result }),
150
+ text: text || '',
151
+ children: result || undefined,
140
152
  },
141
153
  };
142
154
  }
@@ -158,13 +170,15 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
158
170
  };
159
171
  yield { type: 'message', data: activityMessage };
160
172
  messages.push(activityMessage);
161
- yield* complete({
162
- ...options,
163
- client,
164
- messages,
165
- functions,
166
- maxRecusion: maxRecusion - 1,
167
- });
173
+ if (continuationController.signal.aborted === false) {
174
+ yield* complete({
175
+ ...options,
176
+ client,
177
+ messages,
178
+ functions,
179
+ maxRecusion: maxRecusion - 1,
180
+ });
181
+ }
168
182
  }
169
183
  }
170
184
  }
@@ -17,22 +17,32 @@ export type InputMessage = {
17
17
  };
18
18
  export type RenderFunction = () => AsyncGenerator<ReactNode> | ReactNode | Promise<ReactNode>;
19
19
  export type HandlerArgs = any;
20
+ export type HandlerOptions = {
21
+ messages: InputMessage[];
22
+ functions?: InputFunction[];
23
+ controllers: {
24
+ continuation: AbortController;
25
+ };
26
+ signals: {
27
+ abort: AbortSignal;
28
+ };
29
+ };
20
30
  export type HandlerResult = string | ReactElement | {
21
31
  text?: string;
22
32
  children?: ReactNode;
23
- render: RenderFunction;
33
+ render?: RenderFunction;
24
34
  result?: any;
25
35
  };
26
36
  export type InputFunction = {
27
37
  name: string;
28
38
  description: string;
29
39
  parameters: BasicParametersSchema | ValidatingParametersSchema;
30
- handler?: (args: HandlerArgs) => Promise<HandlerResult>;
40
+ handler?: (args: HandlerArgs, options: HandlerOptions) => Promise<HandlerResult>;
31
41
  };
32
42
  export type Options = Omit<any, 'messages' | 'functions'> & {
33
43
  client: import('@chatbotkit/sdk').ConversationClient;
34
44
  messages: InputMessage[];
35
- functions?: (InputFunction | (() => InputFunction))[];
45
+ functions?: (InputFunction | (() => InputFunction | Promise<InputFunction>))[];
36
46
  maxRecusion?: number;
37
47
  };
38
48
  declare function complete({ client, messages, functions, maxRecusion, ...options }: Options): any;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.AutoScroller = void 0;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.AutoTextarea = void 0;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.ChatInput = void 0;
@@ -1,3 +1,4 @@
1
+ 'use any';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.ChatMessage = void 0;
@@ -7,33 +8,18 @@ const react_1 = require("react");
7
8
  const react_markdown_1 = tslib_1.__importDefault(require("react-markdown"));
8
9
  const defaultComponents = {
9
10
  a: ({ href, children }) => {
10
- const isExternal = /^https?:\/\//.test(href);
11
+ const isExternal = /^https?:\/\//.test(href || '');
11
12
  return ((0, jsx_runtime_1.jsx)("a", { href: href, ...(isExternal ? { target: '_blank', rel: 'noopener' } : {}), children: children }));
12
13
  },
13
- code: ({ inline, className, children }) => {
14
- const language = className ? className.replace(/language-/, '') : null;
15
- if (inline) {
16
- return (0, jsx_runtime_1.jsx)("code", { className: "className", children: children });
17
- }
18
- else {
19
- return ((0, jsx_runtime_1.jsx)("pre", { children: (0, jsx_runtime_1.jsx)("code", { className: className, "data-language": language, children: children }) }));
20
- }
21
- },
22
14
  };
23
15
  function ChatMessage(props) {
24
- const { text, style: customStyle, components: customComponents, children, ...rest } = props || {};
16
+ const { text, remarkPlugins, rehypePlugins, components: customComponents, children, ...rest } = props || {};
25
17
  const components = (0, react_1.useMemo)(() => {
26
18
  return {
27
19
  ...defaultComponents,
28
20
  ...customComponents,
29
21
  };
30
22
  }, [customComponents]);
31
- const style = (0, react_1.useMemo)(() => {
32
- return {
33
- whiteSpace: 'pre-wrap',
34
- ...customStyle,
35
- };
36
- }, [customStyle]);
37
- return ((0, jsx_runtime_1.jsxs)("div", { ...rest, style: style, children: [(0, jsx_runtime_1.jsx)(react_markdown_1.default, { components: components, children: text }), children] }));
23
+ return ((0, jsx_runtime_1.jsxs)("div", { ...rest, children: [(0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: remarkPlugins, rehypePlugins: rehypePlugins, components: components, children: text }), children] }));
38
24
  }
39
25
  exports.ChatMessage = ChatMessage;
@@ -1,3 +1,3 @@
1
1
  export function ChatMessage(props: {
2
- [name: string]: any;
3
- }): import("react/jsx-runtime").JSX.Element;
2
+ text: string;
3
+ } & Pick<import("react-markdown/lib").Options, "remarkPlugins" | "rehypePlugins" | "components"> & import("react").HTMLProps<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.ChatMessages = void 0;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.ConversationManager = exports.ConversationContext = void 0;
@@ -14,9 +15,9 @@ exports.ConversationContext = (0, react_1.createContext)(({
14
15
  setText: () => { },
15
16
  error: null,
16
17
  setError: () => { },
17
- submit: () => { },
18
- trigger: () => { },
19
- request: () => { },
18
+ submit: async () => false,
19
+ trigger: async () => false,
20
+ request: async () => false,
20
21
  }));
21
22
  function ConversationManager({ children, ...options }) {
22
23
  const manager = (0, useConversationManager_js_1.default)(options);
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.useConversationManager = void 0;
@@ -57,11 +58,11 @@ function useConversationManager({ ...conversationManagerRemoteOptions }) {
57
58
  }
58
59
  async function submit(thisText) {
59
60
  if (thinking || typing) {
60
- return;
61
+ return false;
61
62
  }
62
63
  if (!thisText) {
63
64
  if (!text) {
64
- return;
65
+ return false;
65
66
  }
66
67
  thisText = text;
67
68
  setText('');
@@ -72,10 +73,11 @@ function useConversationManager({ ...conversationManagerRemoteOptions }) {
72
73
  };
73
74
  appendMessage(userMessage);
74
75
  await stream([userMessage]);
76
+ return true;
75
77
  }
76
78
  async function trigger(name) {
77
79
  if (thinking || typing) {
78
- return;
80
+ return false;
79
81
  }
80
82
  const activityMessage = {
81
83
  type: 'activity',
@@ -90,10 +92,11 @@ function useConversationManager({ ...conversationManagerRemoteOptions }) {
90
92
  },
91
93
  };
92
94
  await stream([activityMessage]);
95
+ return true;
93
96
  }
94
97
  async function request(name, args) {
95
98
  if (thinking || typing) {
96
- return;
99
+ return false;
97
100
  }
98
101
  const activityMessage = {
99
102
  type: 'activity',
@@ -109,6 +112,7 @@ function useConversationManager({ ...conversationManagerRemoteOptions }) {
109
112
  },
110
113
  };
111
114
  await stream([activityMessage]);
115
+ return true;
112
116
  }
113
117
  return {
114
118
  message,
@@ -1,18 +1,25 @@
1
1
  export function useConversationManager({ ...conversationManagerRemoteOptions }: UseConversationManagerOptions): UseConversationManagerResult;
2
2
  export default useConversationManager;
3
3
  export type Message = any;
4
+ export type SimpleMessage = Message & {
5
+ id: string;
6
+ };
7
+ export type ComplexMessage = Message & {
8
+ id: string;
9
+ children?: import('react').ReactNode;
10
+ };
4
11
  export type UseConversationManagerRemoteOptions = import('./useConversationManagerRemote.cjs').UseConversationManagerRemoteOptions;
5
12
  export type UseConversationManagerOptions = UseConversationManagerRemoteOptions & {};
6
13
  export type UseConversationManagerResult = {
7
- message: any;
8
- messages: Message[];
14
+ message: SimpleMessage | null;
15
+ messages: ComplexMessage[];
9
16
  thinking: boolean;
10
17
  typing: boolean;
11
18
  text: string;
12
19
  setText: (text: string) => void;
13
20
  error: any;
14
21
  setError: (error: any) => void;
15
- submit: () => void;
16
- trigger: (name: string) => void;
17
- request: (name: string, args: any) => void;
22
+ submit: () => Promise<boolean>;
23
+ trigger: (name: string) => Promise<boolean>;
24
+ request: (name: string, args: any) => Promise<boolean>;
18
25
  };
@@ -1,3 +1,4 @@
1
+ 'use any';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.useConversationManagerRemote = void 0;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.useConversationManagerState = void 0;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.useConversationManagerStateReducer = exports.conversationManagerStateInitial = exports.conversationManagerStateReducer = void 0;
@@ -17,22 +17,32 @@ export type InputMessage = {
17
17
  };
18
18
  export type RenderFunction = () => AsyncGenerator<ReactNode> | ReactNode | Promise<ReactNode>;
19
19
  export type HandlerArgs = any;
20
+ export type HandlerOptions = {
21
+ messages: InputMessage[];
22
+ functions?: InputFunction[];
23
+ controllers: {
24
+ continuation: AbortController;
25
+ };
26
+ signals: {
27
+ abort: AbortSignal;
28
+ };
29
+ };
20
30
  export type HandlerResult = string | ReactElement | {
21
31
  text?: string;
22
32
  children?: ReactNode;
23
- render: RenderFunction;
33
+ render?: RenderFunction;
24
34
  result?: any;
25
35
  };
26
36
  export type InputFunction = {
27
37
  name: string;
28
38
  description: string;
29
39
  parameters: BasicParametersSchema | ValidatingParametersSchema;
30
- handler?: ((args: HandlerArgs) => Promise<HandlerResult>) | undefined;
40
+ handler?: ((args: HandlerArgs, options: HandlerOptions) => Promise<HandlerResult>) | undefined;
31
41
  };
32
42
  export type Options = Omit<import('@chatbotkit/sdk/conversation/v1.js').ConversationCompleteRequest, 'messages' | 'functions'> & {
33
43
  client: import('@chatbotkit/sdk').ConversationClient;
34
44
  messages: InputMessage[];
35
- functions?: (InputFunction | (() => InputFunction))[];
45
+ functions?: (InputFunction | (() => InputFunction | Promise<InputFunction>))[];
36
46
  maxRecusion?: number;
37
47
  };
38
48
  declare function complete({ client, messages, functions, maxRecusion, ...options }: Options): any;
@@ -1,4 +1,3 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
1
  import { isValidElement } from 'react';
3
2
  import { isAsyncGenerator } from '../utils/it.js';
4
3
  import { stream } from '../utils/stream.js';
@@ -8,14 +7,16 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
8
7
  return;
9
8
  }
10
9
  messages = messages.slice(0);
11
- const functionDefinitions = functions?.map((fn) => {
12
- if (typeof fn === 'function') {
13
- return fn();
14
- }
15
- else {
16
- return fn;
17
- }
18
- });
10
+ const functionDefinitions = functions
11
+ ? await Promise.all(functions.map(async (fn) => {
12
+ if (typeof fn === 'function') {
13
+ return await fn();
14
+ }
15
+ else {
16
+ return fn;
17
+ }
18
+ }))
19
+ : undefined;
19
20
  let it;
20
21
  if (!it) {
21
22
  const lastMessage = messages[messages.length - 1];
@@ -69,7 +70,18 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
69
70
  throw error || new Error('Invalid arguments');
70
71
  }
71
72
  }
72
- const output = await fn.handler(args);
73
+ const abortController = new AbortController();
74
+ const continuationController = new AbortController();
75
+ const output = await fn.handler(args, {
76
+ messages: messages,
77
+ functions: functionDefinitions,
78
+ controllers: {
79
+ continuation: continuationController,
80
+ },
81
+ signals: {
82
+ abort: abortController.signal,
83
+ },
84
+ });
73
85
  let text;
74
86
  let children;
75
87
  let result;
@@ -105,8 +117,8 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
105
117
  type: 'message',
106
118
  data: {
107
119
  type: 'bot',
108
- text: text ? text : '',
109
- children: children ? _jsx(_Fragment, { children: children }) : undefined,
120
+ text: text || '',
121
+ children: children || undefined,
110
122
  },
111
123
  };
112
124
  }
@@ -120,8 +132,8 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
120
132
  data: {
121
133
  id: id,
122
134
  type: 'bot',
123
- text: text ? text : '',
124
- children: item,
135
+ text: text || '',
136
+ children: item || undefined,
125
137
  },
126
138
  };
127
139
  }
@@ -131,8 +143,8 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
131
143
  type: 'message',
132
144
  data: {
133
145
  type: 'bot',
134
- text: text ? text : '',
135
- children: _jsx(_Fragment, { children: result }),
146
+ text: text || '',
147
+ children: result || undefined,
136
148
  },
137
149
  };
138
150
  }
@@ -154,13 +166,15 @@ async function* complete({ client, messages, functions, maxRecusion = 3, ...opti
154
166
  };
155
167
  yield { type: 'message', data: activityMessage };
156
168
  messages.push(activityMessage);
157
- yield* complete({
158
- ...options,
159
- client,
160
- messages,
161
- functions,
162
- maxRecusion: maxRecusion - 1,
163
- });
169
+ if (continuationController.signal.aborted === false) {
170
+ yield* complete({
171
+ ...options,
172
+ client,
173
+ messages,
174
+ functions,
175
+ maxRecusion: maxRecusion - 1,
176
+ });
177
+ }
164
178
  }
165
179
  }
166
180
  }
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import React, { useEffect, useRef } from 'react';
3
4
  function AutoScrollAnchor() {
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import React, { useEffect, useRef } from 'react';
3
4
  export function AutoTextarea(props) {
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import AutoTextarea from './AutoTextarea.js';
3
4
  export function ChatInput(props) {
@@ -1,3 +1,3 @@
1
1
  export function ChatMessage(props: {
2
- [name: string]: any;
3
- }): import("react/jsx-runtime").JSX.Element;
2
+ text: string;
3
+ } & Pick<import("../../node_modules/react-markdown/lib/index.js").Options, "remarkPlugins" | "rehypePlugins" | "components"> & import("react").HTMLProps<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
@@ -1,34 +1,20 @@
1
+ 'use any';
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { useMemo } from 'react';
3
4
  import Markdown from 'react-markdown';
4
5
  const defaultComponents = {
5
6
  a: ({ href, children }) => {
6
- const isExternal = /^https?:\/\//.test(href);
7
+ const isExternal = /^https?:\/\//.test(href || '');
7
8
  return (_jsx("a", { href: href, ...(isExternal ? { target: '_blank', rel: 'noopener' } : {}), children: children }));
8
9
  },
9
- code: ({ inline, className, children }) => {
10
- const language = className ? className.replace(/language-/, '') : null;
11
- if (inline) {
12
- return _jsx("code", { className: "className", children: children });
13
- }
14
- else {
15
- return (_jsx("pre", { children: _jsx("code", { className: className, "data-language": language, children: children }) }));
16
- }
17
- },
18
10
  };
19
11
  export function ChatMessage(props) {
20
- const { text, style: customStyle, components: customComponents, children, ...rest } = props || {};
12
+ const { text, remarkPlugins, rehypePlugins, components: customComponents, children, ...rest } = props || {};
21
13
  const components = useMemo(() => {
22
14
  return {
23
15
  ...defaultComponents,
24
16
  ...customComponents,
25
17
  };
26
18
  }, [customComponents]);
27
- const style = useMemo(() => {
28
- return {
29
- whiteSpace: 'pre-wrap',
30
- ...customStyle,
31
- };
32
- }, [customStyle]);
33
- return (_jsxs("div", { ...rest, style: style, children: [_jsx(Markdown, { components: components, children: text }), children] }));
19
+ return (_jsxs("div", { ...rest, children: [_jsx(Markdown, { remarkPlugins: remarkPlugins, rehypePlugins: rehypePlugins, components: components, children: text }), children] }));
34
20
  }
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import AutoScroller from './AutoScroller.js';
3
4
  export function ChatMessages(props) {
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import { createContext } from 'react';
3
4
  import useConversationManager from '../hooks/useConversationManager.js';
@@ -10,9 +11,9 @@ export const ConversationContext = createContext(({
10
11
  setText: () => { },
11
12
  error: null,
12
13
  setError: () => { },
13
- submit: () => { },
14
- trigger: () => { },
15
- request: () => { },
14
+ submit: async () => false,
15
+ trigger: async () => false,
16
+ request: async () => false,
16
17
  }));
17
18
  export function ConversationManager({ children, ...options }) {
18
19
  const manager = useConversationManager(options);
@@ -1,18 +1,25 @@
1
1
  export function useConversationManager({ ...conversationManagerRemoteOptions }: UseConversationManagerOptions): UseConversationManagerResult;
2
2
  export default useConversationManager;
3
3
  export type Message = import('@chatbotkit/sdk/conversation/v1').Message;
4
+ export type SimpleMessage = Message & {
5
+ id: string;
6
+ };
7
+ export type ComplexMessage = Message & {
8
+ id: string;
9
+ children?: import('react').ReactNode;
10
+ };
4
11
  export type UseConversationManagerRemoteOptions = import('./useConversationManagerRemote.js').UseConversationManagerRemoteOptions;
5
12
  export type UseConversationManagerOptions = UseConversationManagerRemoteOptions & {};
6
13
  export type UseConversationManagerResult = {
7
- message: Message | null;
8
- messages: Message[];
14
+ message: SimpleMessage | null;
15
+ messages: ComplexMessage[];
9
16
  thinking: boolean;
10
17
  typing: boolean;
11
18
  text: string;
12
19
  setText: (text: string) => void;
13
20
  error: any;
14
21
  setError: (error: any) => void;
15
- submit: () => void;
16
- trigger: (name: string) => void;
17
- request: (name: string, args: any) => void;
22
+ submit: () => Promise<boolean>;
23
+ trigger: (name: string) => Promise<boolean>;
24
+ request: (name: string, args: any) => Promise<boolean>;
18
25
  };