@zero-library/chat-agent 2.1.6 → 2.1.8

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/index.d.mts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { RenderControl, UserInfo } from '@zero-library/common';
2
2
  import { ButtonProps, ThemeConfig } from 'antd';
3
3
  import * as react from 'react';
4
- import { Conversation } from '@ant-design/x';
4
+ import { Conversation, BubbleProps } from '@ant-design/x';
5
+ export * from '@ant-design/x';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
7
 
6
8
  interface InputFile {
7
9
  /**
@@ -316,6 +318,29 @@ interface ChatSenderHandle {
316
318
  cursor?: 'start' | 'end';
317
319
  }) => void;
318
320
  }
321
+ interface FileUpload {
322
+ params?: ObjectType<any>;
323
+ config: FileUploadConfig[];
324
+ }
325
+ interface Props$3 {
326
+ placeholder?: string;
327
+ content?: string;
328
+ fileList?: InputFile[];
329
+ headerOpen?: boolean;
330
+ loading?: boolean;
331
+ onContentChange: (value: string) => void;
332
+ onFileListChange: (files: InputFile[]) => void;
333
+ onHeaderOpenChange: (open: boolean) => void;
334
+ onSend: () => void;
335
+ onCancel?: () => void;
336
+ onFocus?: () => void;
337
+ extraHeader?: React.ReactNode;
338
+ extraFooter?: React.ReactNode;
339
+ extraFooterBelow?: React.ReactNode;
340
+ sendBtnProps?: ButtonProps;
341
+ fileUpload?: FileUpload;
342
+ }
343
+ declare const _default$3: react.ForwardRefExoticComponent<Props$3 & react.RefAttributes<ChatSenderHandle>>;
319
344
 
320
345
  interface ChatConfig {
321
346
  receiverType?: number;
@@ -323,7 +348,7 @@ interface ChatConfig {
323
348
  conversationId?: string;
324
349
  conversationStrategy?: ConversationStrategy;
325
350
  }
326
- interface Props {
351
+ interface Props$2 {
327
352
  theme?: ThemeConfig;
328
353
  config?: ChatConfig;
329
354
  params?: ChatParams;
@@ -333,14 +358,29 @@ interface Props {
333
358
  }
334
359
  interface ChatHandle {
335
360
  sendMessage: (message?: string, files?: InputFile[]) => void;
336
- switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => void;
337
- switchConversation: (id?: Conversation['id']) => void;
361
+ switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => Promise<void>;
362
+ switchConversation: (id?: Conversation['id']) => Promise<void>;
338
363
  createConversation: () => Promise<void>;
339
364
  setReferences: (references?: ReferencesType) => void;
340
365
  setMessage: (message?: string) => void;
341
366
  setFiles: (files?: InputFile[]) => void;
367
+ setParams: (params?: ChatParams) => void;
342
368
  senderFocus: ChatSenderHandle['focus'];
343
369
  }
344
- declare const _default: react.ForwardRefExoticComponent<Props & react.RefAttributes<ChatHandle>>;
370
+ declare const _default$2: react.ForwardRefExoticComponent<Props$2 & react.RefAttributes<ChatHandle>>;
371
+
372
+ interface Props$1 {
373
+ fileUploadConfig?: FileUploadConfig[];
374
+ extraParams?: ObjectType<string | undefined>;
375
+ fileList?: InputFile[];
376
+ onChange: (fileList: InputFile[]) => void;
377
+ }
378
+ declare const _default$1: react.ForwardRefExoticComponent<Props$1 & react.RefAttributes<unknown>>;
379
+
380
+ interface Props {
381
+ message: ConversationMessage;
382
+ placement: BubbleProps['placement'];
383
+ }
384
+ declare const _default: ({ message, placement }: Props) => react_jsx_runtime.JSX.Element;
345
385
 
346
- export { type AgentInfo, type ChatConfig, _default as ChatCopilot, type ChatHandle, type ChatLayout };
386
+ export { type AgentInfo, _default$1 as Attachments, type ChatConfig, _default$2 as ChatCopilot, type ChatHandle, type ChatHooks, type ChatLayout, type ChatParams, _default$3 as ChatSender, type ConversationStrategy, type InputFile, _default as MessageRender, type ReferencesType };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { RenderControl, UserInfo } from '@zero-library/common';
2
2
  import { ButtonProps, ThemeConfig } from 'antd';
3
3
  import * as react from 'react';
4
- import { Conversation } from '@ant-design/x';
4
+ import { Conversation, BubbleProps } from '@ant-design/x';
5
+ export * from '@ant-design/x';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
7
 
6
8
  interface InputFile {
7
9
  /**
@@ -316,6 +318,29 @@ interface ChatSenderHandle {
316
318
  cursor?: 'start' | 'end';
317
319
  }) => void;
318
320
  }
321
+ interface FileUpload {
322
+ params?: ObjectType<any>;
323
+ config: FileUploadConfig[];
324
+ }
325
+ interface Props$3 {
326
+ placeholder?: string;
327
+ content?: string;
328
+ fileList?: InputFile[];
329
+ headerOpen?: boolean;
330
+ loading?: boolean;
331
+ onContentChange: (value: string) => void;
332
+ onFileListChange: (files: InputFile[]) => void;
333
+ onHeaderOpenChange: (open: boolean) => void;
334
+ onSend: () => void;
335
+ onCancel?: () => void;
336
+ onFocus?: () => void;
337
+ extraHeader?: React.ReactNode;
338
+ extraFooter?: React.ReactNode;
339
+ extraFooterBelow?: React.ReactNode;
340
+ sendBtnProps?: ButtonProps;
341
+ fileUpload?: FileUpload;
342
+ }
343
+ declare const _default$3: react.ForwardRefExoticComponent<Props$3 & react.RefAttributes<ChatSenderHandle>>;
319
344
 
320
345
  interface ChatConfig {
321
346
  receiverType?: number;
@@ -323,7 +348,7 @@ interface ChatConfig {
323
348
  conversationId?: string;
324
349
  conversationStrategy?: ConversationStrategy;
325
350
  }
326
- interface Props {
351
+ interface Props$2 {
327
352
  theme?: ThemeConfig;
328
353
  config?: ChatConfig;
329
354
  params?: ChatParams;
@@ -333,14 +358,29 @@ interface Props {
333
358
  }
334
359
  interface ChatHandle {
335
360
  sendMessage: (message?: string, files?: InputFile[]) => void;
336
- switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => void;
337
- switchConversation: (id?: Conversation['id']) => void;
361
+ switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => Promise<void>;
362
+ switchConversation: (id?: Conversation['id']) => Promise<void>;
338
363
  createConversation: () => Promise<void>;
339
364
  setReferences: (references?: ReferencesType) => void;
340
365
  setMessage: (message?: string) => void;
341
366
  setFiles: (files?: InputFile[]) => void;
367
+ setParams: (params?: ChatParams) => void;
342
368
  senderFocus: ChatSenderHandle['focus'];
343
369
  }
344
- declare const _default: react.ForwardRefExoticComponent<Props & react.RefAttributes<ChatHandle>>;
370
+ declare const _default$2: react.ForwardRefExoticComponent<Props$2 & react.RefAttributes<ChatHandle>>;
371
+
372
+ interface Props$1 {
373
+ fileUploadConfig?: FileUploadConfig[];
374
+ extraParams?: ObjectType<string | undefined>;
375
+ fileList?: InputFile[];
376
+ onChange: (fileList: InputFile[]) => void;
377
+ }
378
+ declare const _default$1: react.ForwardRefExoticComponent<Props$1 & react.RefAttributes<unknown>>;
379
+
380
+ interface Props {
381
+ message: ConversationMessage;
382
+ placement: BubbleProps['placement'];
383
+ }
384
+ declare const _default: ({ message, placement }: Props) => react_jsx_runtime.JSX.Element;
345
385
 
346
- export { type AgentInfo, type ChatConfig, _default as ChatCopilot, type ChatHandle, type ChatLayout };
386
+ export { type AgentInfo, _default$1 as Attachments, type ChatConfig, _default$2 as ChatCopilot, type ChatHandle, type ChatHooks, type ChatLayout, type ChatParams, _default$3 as ChatSender, type ConversationStrategy, type InputFile, _default as MessageRender, type ReferencesType };
package/dist/index.esm.js CHANGED
@@ -5,6 +5,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { forwardRef, useRef, useEffect, useImperativeHandle, useMemo, useState } from 'react';
6
6
  import { CloudUploadOutlined, PaperClipOutlined, EnterOutlined, UserSwitchOutlined, CloseOutlined, PlusOutlined, CommentOutlined, OpenAIOutlined, CopyOutlined, LikeOutlined, DislikeOutlined, DeleteOutlined, RedoOutlined, PlayCircleOutlined, CaretRightOutlined } from '@ant-design/icons';
7
7
  import { Attachments, Sender, Suggestion, XProvider, Welcome, Prompts, Bubble, Conversations } from '@ant-design/x';
8
+ export * from '@ant-design/x';
8
9
  import classNames7 from 'classnames';
9
10
  import { useSnapshot, proxy } from 'valtio';
10
11
  import InfiniteScroll from 'react-infinite-scroll-component';
@@ -419,7 +420,7 @@ function createChatStore() {
419
420
  const defaultLayout = receiverType === 3 ? defaultAgentLayout : defaultExpertLayout;
420
421
  config.layout = deepMerge(defaultLayout, layout);
421
422
  };
422
- const setConfigParams = (params = {}) => {
423
+ const setParams = (params = {}) => {
423
424
  config.params = { ...params };
424
425
  };
425
426
  const setHooks = (hooks = {}) => {
@@ -481,6 +482,7 @@ function createChatStore() {
481
482
  }
482
483
  config.hooks?.onAfterSwitchAgent?.(data);
483
484
  } catch (error) {
485
+ console.error(error);
484
486
  throw error;
485
487
  } finally {
486
488
  receiver.loading = false;
@@ -506,10 +508,13 @@ function createChatStore() {
506
508
  const getCharacters = async (agentId) => {
507
509
  try {
508
510
  character.loading = true;
509
- const res = await agentCharacterQuery(agentId);
511
+ const { data } = await agentCharacterQuery(agentId);
510
512
  if (receiver.active.id !== agentId) return;
511
- character.list = res.data;
512
- character.active = res.data.find((item) => item.selected);
513
+ character.list = data;
514
+ const active = data.find((item) => item.selected);
515
+ if (active) {
516
+ character.active = active;
517
+ }
513
518
  } finally {
514
519
  character.loading = false;
515
520
  }
@@ -878,7 +883,7 @@ function createChatStore() {
878
883
  setPreview,
879
884
  setLayout,
880
885
  setHooks,
881
- setConfigParams,
886
+ setParams,
882
887
  setUserInfo,
883
888
  character,
884
889
  getCharacters,
@@ -1854,7 +1859,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
1854
1859
  chatStore.setLayout(layout, config?.receiverType);
1855
1860
  }, [layout, config?.receiverType]);
1856
1861
  useEffect(() => {
1857
- chatStore.setConfigParams(params);
1862
+ chatStore.setParams(params);
1858
1863
  }, [params]);
1859
1864
  useEffect(() => {
1860
1865
  chatStore.setHooks(hooks);
@@ -1871,6 +1876,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
1871
1876
  setReferences: chatStore.setReferences,
1872
1877
  setMessage: chatStore.setContent,
1873
1878
  setFiles: chatStore.setFileList,
1879
+ setParams: chatStore.setParams,
1874
1880
  senderFocus: (options) => {
1875
1881
  senderRef.current?.focus(options);
1876
1882
  }
@@ -1986,6 +1992,6 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
1986
1992
  ] }) }) }) });
1987
1993
  });
1988
1994
 
1989
- export { layouts_default as ChatCopilot };
1995
+ export { Attachments_default as Attachments, layouts_default as ChatCopilot, ChatSender_default as ChatSender, MessageRender_default as MessageRender };
1990
1996
  //# sourceMappingURL=index.esm.js.map
1991
1997
  //# sourceMappingURL=index.esm.js.map